RFR: 8368328: CompactNumberFormat.clone does not produce independent instances [v3]
Justin Lu
jlu at openjdk.org
Wed Sep 24 23:21:01 UTC 2025
On Wed, 24 Sep 2025 22:51:04 GMT, Naoto Sato <naoto at openjdk.org> wrote:
>> test/jdk/java/text/Format/CompactNumberFormat/TestClone.java line 77:
>>
>>> 75: private static Stream<Arguments> referenceFields() throws ClassNotFoundException {
>>> 76: return Stream.of(
>>> 77: Arguments.of("decimalFormat", DecimalFormat.class),
>>
>> We should also include `Arguments.of("symbols", DecimalFormatSymbols.class)` as an entry.
>
> I was only testing mutable ones (as `symbols` is a constant), but as a regression test for `clone()` impl, adding all cloned fields would be desired.
Well CNF treats `symbols` as a constant, but technically user can still mutate it. Regardless, good to see it guaranteed to be a unique reference in the test since we do make a clone on it.
jshell> var dfs = new DecimalFormatSymbols()
dfs ==> java.text.DecimalFormatSymbols at a7ad10d9
jshell> var cnf = new CompactNumberFormat("", dfs, new String[]{})
cnf ==> java.text.CompactNumberFormat at cd2b4d69
jshell> cnf.parse("NaN")
$4 ==> NaN
jshell> dfs.setNaN("FOO")
jshell> cnf.parse("FOO")
$6 ==> NaN
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27475#discussion_r2377274648
More information about the core-libs-dev
mailing list