summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Egnor <egnor@google.com>2009-11-20 16:10:56 -0800
committerDan Egnor <egnor@google.com>2009-11-20 16:10:56 -0800
commitff30d8c3c306d660a58a9bad60e7256d372bc6e8 (patch)
tree350f0aa894c8ec1551ad3ff544a7c2408f96c474
parenteabe220afc096d5abd9d084afdac8f0aa631f26c (diff)
downloadlibcore-ff30d8c3c306d660a58a9bad60e7256d372bc6e8.zip
libcore-ff30d8c3c306d660a58a9bad60e7256d372bc6e8.tar.gz
libcore-ff30d8c3c306d660a58a9bad60e7256d372bc6e8.tar.bz2
Fix bugs created by caching NumberFormat & DecimalFormatSymbols objects
-rw-r--r--luni/src/main/java/java/util/Formatter.java26
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/util/LocaleCache.java14
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();
}
}