summaryrefslogtreecommitdiffstats
path: root/android_icu4j
diff options
context:
space:
mode:
authorNikita Iashcenko <nikitai@google.com>2019-01-25 14:26:41 +0000
committerVictor Chang <vichang@google.com>2019-01-30 15:13:23 +0000
commit41918f128cdb56902f5ef3b91895a3566955c3eb (patch)
tree4834f2015b8159a406c281e2b48f9231e270bae0 /android_icu4j
parentae09d6a69ba5148fd860cfed9dcce2518359d97f (diff)
downloadandroid_external_icu-41918f128cdb56902f5ef3b91895a3566955c3eb.tar.gz
android_external_icu-41918f128cdb56902f5ef3b91895a3566955c3eb.tar.bz2
android_external_icu-41918f128cdb56902f5ef3b91895a3566955c3eb.zip
Cherry-pick: ICU-20350 Fix DecimalFormatSymbols.setPatternForCurrencySpacing affecting the value across instances
According to the upstream bug https://unicode-org.atlassian.net/browse/ICU-20350?focusedCommentId=63142#comment-63142, it's a regression in ICU 58. Bug: 116850744 Test: CtsIcuTestCases Change-Id: Ida6b42dad692b7d31df94c788d43a6d41d728982
Diffstat (limited to 'android_icu4j')
-rw-r--r--android_icu4j/src/main/java/android/icu/text/DecimalFormatSymbols.java2
-rw-r--r--android_icu4j/src/main/tests/android/icu/dev/test/format/IntlTestDecimalFormatSymbols.java21
2 files changed, 23 insertions, 0 deletions
diff --git a/android_icu4j/src/main/java/android/icu/text/DecimalFormatSymbols.java b/android_icu4j/src/main/java/android/icu/text/DecimalFormatSymbols.java
index e6c6a2425..c86515cae 100644
--- a/android_icu4j/src/main/java/android/icu/text/DecimalFormatSymbols.java
+++ b/android_icu4j/src/main/java/android/icu/text/DecimalFormatSymbols.java
@@ -1068,8 +1068,10 @@ public class DecimalFormatSymbols implements Cloneable, Serializable {
throw new IllegalArgumentException("unknown currency spacing: " + itemType);
}
if (beforeCurrency) {
+ currencySpcBeforeSym = currencySpcBeforeSym.clone();
currencySpcBeforeSym[itemType] = pattern;
} else {
+ currencySpcAfterSym = currencySpcAfterSym.clone();
currencySpcAfterSym[itemType] = pattern;
}
}
diff --git a/android_icu4j/src/main/tests/android/icu/dev/test/format/IntlTestDecimalFormatSymbols.java b/android_icu4j/src/main/tests/android/icu/dev/test/format/IntlTestDecimalFormatSymbols.java
index 19f249472..1752250b3 100644
--- a/android_icu4j/src/main/tests/android/icu/dev/test/format/IntlTestDecimalFormatSymbols.java
+++ b/android_icu4j/src/main/tests/android/icu/dev/test/format/IntlTestDecimalFormatSymbols.java
@@ -403,4 +403,25 @@ public class IntlTestDecimalFormatSymbols extends TestFmwk
assertEquals("JDK Locale and ICU Locale should produce the same object", dfs, dfs2);
}
}
+
+ @Test
+ public void testSetPatternForCurrencySpacing_notSharedByInstances() {
+ for (int type = DecimalFormatSymbols.CURRENCY_SPC_CURRENCY_MATCH; type <= DecimalFormatSymbols.CURRENCY_SPC_INSERT; type++) {
+ DecimalFormatSymbols dfs1 = DecimalFormatSymbols.getInstance(Locale.US);
+ DecimalFormatSymbols dfs2 = DecimalFormatSymbols.getInstance(Locale.US);
+ final String pattern = "foobar";
+ // before
+ dfs1.setPatternForCurrencySpacing(type, false, pattern);
+ assertEquals("setPatternForCurrencySpacing() must set the pattern", pattern,
+ dfs1.getPatternForCurrencySpacing(type, false));
+ assertNotEquals("DFS instances must not share same pattern", pattern,
+ dfs2.getPatternForCurrencySpacing(type, false));
+ // after
+ dfs1.setPatternForCurrencySpacing(type, true, pattern);
+ assertEquals("setPatternForCurrencySpacing() must set the pattern", pattern,
+ dfs1.getPatternForCurrencySpacing(type, true));
+ assertNotEquals("DFS instances must not share same pattern", pattern,
+ dfs2.getPatternForCurrencySpacing(type, true));
+ }
+ }
}