ICU-20350 Fix DecimalFormatSymbols.setPatternForCurrencySpacing affecting the value across instances

This commit is contained in:
Victor Chang 2019-01-25 14:26:41 +00:00 committed by Shane F. Carr
parent 5c8960e59e
commit a424372b7b
2 changed files with 23 additions and 0 deletions

View 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;
}
}

View 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));
}
}
}