]> granicus.if.org Git - icu/commitdiff
ICU-20350 Fix DecimalFormatSymbols.setPatternForCurrencySpacing affecting the value...
authorVictor Chang <vichang@google.com>
Fri, 25 Jan 2019 14:26:41 +0000 (14:26 +0000)
committerShane F. Carr <shane@unicode.org>
Fri, 25 Jan 2019 21:04:49 +0000 (13:04 -0800)
icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormatSymbols.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/IntlTestDecimalFormatSymbols.java

index a01ac9af182c954c52ba12f7390d7f1674a19892..8ad220ffa35465ce5ded2bfe9d51d0fc7d751a16 100644 (file)
@@ -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;
         }
     }
index 1042d3f82989bec3ed9b50becdd8a6a096599de1..012946f086c0fed2e8c4b2502bf69075e1306df1 100644 (file)
@@ -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));
+        }
+    }
 }