RFR: 8287340: Refactor old code using StringTokenizer in locale related code [v2]
Naoto Sato
naoto at openjdk.java.net
Wed Jun 1 16:39:33 UTC 2022
On Wed, 1 Jun 2022 04:10:03 GMT, ExE Boss <duke at openjdk.java.net> wrote:
>> Naoto Sato has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Removed unnecessary clone() call
>
> 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
Thanks for your comments. In fact, `clone()` in `JRELocaleProviderAdapter` is not necessary, as it will be subsumed into `Locale.getAvailableLocales()` and other `getAvailableLocales()` methods in locale sensitives services (such as `DateFormat`) where they are defensively cloned. Removed this `clone()` invocation.
-------------
PR: https://git.openjdk.java.net/jdk/pull/8960
More information about the core-libs-dev
mailing list