RFR: 8287340: Refactor old code using StringTokenizer in locale related code
ExE Boss
duke at openjdk.java.net
Wed Jun 1 04:16:35 UTC 2022
On Tue, 31 May 2022 17:46:18 GMT, Naoto Sato <naoto at openjdk.org> wrote:
> Refactoring some old code in locale providers. The test case data have also been modified due to:
> - There's a bug in `LocaleProviderAdapter.toLocaleArray()` where it did not handle the case for `no-NO-NY`.
> - `Locale.toLanguageTag()` won't handle legacy Java locales, e.g., `ja_JP_JP` and falls back, so comparing locales using language tags does not work for those locales. Changed to compare with `Locale.toString()` instead.
src/java.base/share/classes/sun/util/cldr/CLDRLocaleProviderAdapter.java line 181:
> 179: .toArray(Locale[]::new);
> 180: }
> 181: return AVAILABLE_LOCALES;
This should probably clone the cached array:
Suggestion:
return AVAILABLE_LOCALES.clone();
Matching what `JRELocaleProviderAdapter` does[^1], since there’s no guarantee that the result of `getAvailableLocales()` won’t be mutated.
[^1]: https://github.com/openjdk/jdk/blob/6b1169e266b9d21864f886ef574dd64116fa2cb0/src/java.base/share/classes/sun/util/locale/provider/JRELocaleProviderAdapter.java#L430-L439
-------------
PR: https://git.openjdk.java.net/jdk/pull/8960
More information about the core-libs-dev
mailing list