From a424372b7bde354571a1ddc410a38fef65879583 Mon Sep 17 00:00:00 2001 From: Victor Chang Date: Fri, 25 Jan 2019 14:26:41 +0000 Subject: [PATCH] ICU-20350 Fix DecimalFormatSymbols.setPatternForCurrencySpacing affecting the value across instances --- .../ibm/icu/text/DecimalFormatSymbols.java | 2 ++ .../format/IntlTestDecimalFormatSymbols.java | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormatSymbols.java b/icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormatSymbols.java index a01ac9af182..8ad220ffa35 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormatSymbols.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormatSymbols.java @@ -1156,8 +1156,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/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/IntlTestDecimalFormatSymbols.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/IntlTestDecimalFormatSymbols.java index 1042d3f8298..012946f086c 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/IntlTestDecimalFormatSymbols.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/IntlTestDecimalFormatSymbols.java @@ -400,4 +400,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)); + } + } } -- 2.40.0