diff options
author | Elliott Hughes <enh@google.com> | 2009-10-14 15:40:27 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2009-10-14 16:39:16 -0700 |
commit | 34ecef9d60764ad57e1c7684a1ecd77e2e8326a1 (patch) | |
tree | 5866ac8709994928c5064ce20baf52dda76ccff8 /icu/src/main/java | |
parent | 36efe4ab6422c34c98e196eee7022fecf52c7534 (diff) | |
download | libcore-34ecef9d60764ad57e1c7684a1ecd77e2e8326a1.zip libcore-34ecef9d60764ad57e1c7684a1ecd77e2e8326a1.tar.gz libcore-34ecef9d60764ad57e1c7684a1ecd77e2e8326a1.tar.bz2 |
Fix icu4jni Resources ("Locale") to not expose its internals.
We shouldn't expose internal arrays without copying.
Bug: 2102273
Diffstat (limited to 'icu/src/main/java')
-rw-r--r-- | icu/src/main/java/com/ibm/icu4jni/util/Resources.java | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/icu/src/main/java/com/ibm/icu4jni/util/Resources.java b/icu/src/main/java/com/ibm/icu4jni/util/Resources.java index 0460fde..086f8d4 100644 --- a/icu/src/main/java/com/ibm/icu4jni/util/Resources.java +++ b/icu/src/main/java/com/ibm/icu4jni/util/Resources.java @@ -114,7 +114,7 @@ public class Resources { isoLanguages = getISOLanguagesNative(); } - return isoLanguages; + return isoLanguages.clone(); } /** @@ -128,7 +128,7 @@ public class Resources { isoCountries = getISOCountriesNative(); } - return isoCountries; + return isoCountries.clone(); } /** @@ -142,7 +142,7 @@ public class Resources { availableLocales = getAvailableLocalesNative(); } - return availableLocales; + return availableLocales.clone(); } /** @@ -157,7 +157,7 @@ public class Resources { availableTimezones = TimeZone.getAvailableIDs(); } - return availableTimezones; + return availableTimezones.clone(); } /** @@ -264,17 +264,25 @@ public class Resources { if (locale == null) { locale = defaultLocale; } - + // If locale == default and the default locale hasn't changed since // DefaultTimeZones loaded, return the cached names. // TODO: We should force a reboot if the default locale changes. if (defaultLocale.equals(locale) && DefaultTimeZones.locale.equals(defaultLocale)) { - return DefaultTimeZones.names; + return clone2dStringArray(DefaultTimeZones.names); } return createTimeZoneNamesFor(locale); } + private static String[][] clone2dStringArray(String[][] array) { + String[][] result = new String[array.length][]; + for (int i = 0; i < array.length; ++i) { + result[i] = array[i].clone(); + } + return result; + } + // --- Specialized ResourceBundle subclasses ------------------------------ /** |