diff options
author | Dan Egnor <egnor@google.com> | 2009-11-20 16:20:17 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2009-11-20 16:20:17 -0800 |
commit | 4b65522326d34470f4e31a8a859ef3df48ed00ea (patch) | |
tree | 8416c9fb03853898a0eba7614ee30a43f78efdec | |
parent | 9efecdb55af339a2566012910c002e0b2b5a7a3b (diff) | |
parent | ff30d8c3c306d660a58a9bad60e7256d372bc6e8 (diff) | |
download | libcore-4b65522326d34470f4e31a8a859ef3df48ed00ea.zip libcore-4b65522326d34470f4e31a8a859ef3df48ed00ea.tar.gz libcore-4b65522326d34470f4e31a8a859ef3df48ed00ea.tar.bz2 |
am 0dfef7bc: Fix bugs created by caching NumberFormat & DecimalFormatSymbols objects
Merge commit '0dfef7bc223f18a1372b4c44c822b9cdc5d5f741' into eclair-mr2-plus-aosp
* commit '0dfef7bc223f18a1372b4c44c822b9cdc5d5f741':
Fix bugs created by caching NumberFormat & DecimalFormatSymbols objects
-rw-r--r-- | luni/src/main/java/java/util/Formatter.java | 26 | ||||
-rw-r--r-- | luni/src/main/java/org/apache/harmony/luni/util/LocaleCache.java | 14 |
2 files changed, 19 insertions, 21 deletions
diff --git a/luni/src/main/java/java/util/Formatter.java b/luni/src/main/java/java/util/Formatter.java index 9198886..dcd6c85 100644 --- a/luni/src/main/java/java/util/Formatter.java +++ b/luni/src/main/java/java/util/Formatter.java @@ -1164,9 +1164,11 @@ public final class Formatter implements Closeable, Flushable { private static String lineSeparator; - private NumberFormat numberFormat; - - private DecimalFormatSymbols decimalFormatSymbols; + // BEGIN android-changed + // These objects are mutated during use, so can't be cached safely. + // private NumberFormat numberFormat; + // private DecimalFormatSymbols decimalFormatSymbols; + // END android-changed private DateTimeUtil dateTimeUtil; @@ -1176,21 +1178,15 @@ public final class Formatter implements Closeable, Flushable { } private NumberFormat getNumberFormat() { - if (null == numberFormat) { - // BEGIN android-changed - numberFormat = LocaleCache.getNumberFormat(locale); - // END android-changed - } - return numberFormat; + // BEGIN android-changed + return LocaleCache.getNumberFormat(locale); + // END android-changed } private DecimalFormatSymbols getDecimalFormatSymbols() { - if (null == decimalFormatSymbols) { - // BEGIN android-changed - decimalFormatSymbols = LocaleCache.getDecimalFormatSymbols(locale); - // END android-changed - } - return decimalFormatSymbols; + // BEGIN android-changed + return LocaleCache.getDecimalFormatSymbols(locale); + // END android-changed } /* diff --git a/luni/src/main/java/org/apache/harmony/luni/util/LocaleCache.java b/luni/src/main/java/org/apache/harmony/luni/util/LocaleCache.java index c591faf..5318e38 100644 --- a/luni/src/main/java/org/apache/harmony/luni/util/LocaleCache.java +++ b/luni/src/main/java/org/apache/harmony/luni/util/LocaleCache.java @@ -55,27 +55,29 @@ public class LocaleCache { } /** - * Returns a NumberFormat object initialized with the specified - * Locale, re-using a previously returned object if possible. + * Returns a NumberFormat object for the specified Locale. */ public static NumberFormat getNumberFormat(Locale locale) { LocaleCache lc = getLocaleCache(locale); if (lc.numberFormat == null) { lc.numberFormat = NumberFormat.getInstance(locale); } - return lc.numberFormat; + + // NumberFormat is mutable, so return a new clone each time. + return (NumberFormat) lc.numberFormat.clone(); } /** - * Returns a DecimalFormatSymbols object initialized with the specified - * Locale, re-using a previously returned object if possible. + * Returns a DecimalFormatSymbols object for the specified Locale. */ public static DecimalFormatSymbols getDecimalFormatSymbols(Locale locale) { LocaleCache lc = getLocaleCache(locale); if (lc.decimalFormatSymbols == null) { lc.decimalFormatSymbols = new DecimalFormatSymbols(locale); } - return lc.decimalFormatSymbols; + + // DecimalFormatSymbols is mutable, so return a new clone each time. + return (DecimalFormatSymbols) lc.decimalFormatSymbols.clone(); } } |