RFR: 8283698: Refactor Locale constructors used in src/test

Naoto Sato naoto at openjdk.java.net
Thu Apr 7 01:19:35 UTC 2022


On Thu, 7 Apr 2022 00:09:58 GMT, Joe Wang <joehw at openjdk.org> wrote:

>> This is a follow-on task after deprecating the Locale constructors (https://bugs.openjdk.java.net/browse/JDK-8282819). Most of the changes are simple replacements to Locale constructors with `Locale.of()` or Locale constants, such as `Locale.US`.
>
> test/jdk/java/text/Format/DateFormat/DateFormatRoundTripTest.java line 81:
> 
>> 79: 
>> 80:     /**
>> 81:      * Parse a name like "fr_FR" into Locale.of("fr", "FR", "");
> 
> Locale.France?

The test code parses the input string (eg. "fr_FR") into 3 elements, `name`, `country`, and `variant`, then create a `Locale` using those 3 elements. Changing it to `Locale.FRANCE` does not seem right here.

> test/jdk/java/text/Format/NumberFormat/CurrencyFormat.java line 63:
> 
>> 61:             Locale.of("it", "IT", "EURO"),
>> 62:             Locale.forLanguageTag("de-AT"),
>> 63:             Locale.forLanguageTag("fr-CH"),
> 
> Use the new factory? Ok not to change as these are tests and there are too many of them. It's not deprecated anyways.

`Locale.forLanguageTag()` is a preferred way to create a `Locale`, as it validates the input language tag, while `Locale.of()` doesn't as well as Locale constructors.

> test/jdk/java/text/Format/common/Bug6215962.java line 58:
> 
>> 56:         check(mf1, mf2, false);
>> 57: 
>> 58:         mf1 = new MessageFormat("{0}", Locale.of("ja", "JP"));
> 
> Locale.JAPAN?

The test intends to compare the generated `MessageFormat` objects (`mf2` & `mf1`) from using a constant `Locale.JAPAN` and the factory method. So I believe leaving it as `Locale.of()` makes sense.

-------------

PR: https://git.openjdk.java.net/jdk/pull/8130



More information about the security-dev mailing list