On Thu, 30 Apr 2026 20:31:10 GMT, Naoto Sato <[email protected]> wrote:

>> Fixing the race condition during the initialization of the skeleton map. The 
>> root cause was that the map could be accessed while it was still being 
>> initialized, leading to an NPE. Although the NPE could be avoided by 
>> returning a default value, the map initialization itself should be made 
>> thread safe.
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Naoto Sato has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Removed unnecessary throws

src/java.base/share/classes/sun/util/locale/provider/LocaleResources.java line 
683:

> 681:         // hack: "allowed" contains reversed order for hour/period, e.g, 
> "hB" which should be "Bh" as a skeleton
> 682:         if (cp.length() == 2) {
> 683:             cp = "" + cp.charAt(1) + cp.charAt(0);

The new code here is accidentally safer than the old code that truncates the 
most significant bytes of the chars.

src/java.base/share/classes/sun/util/locale/provider/LocaleResources.java line 
700:

> 698:                 regionToSkeletonMap.getOrDefault(locale.getCountry(),
> 699:                     
> regionToSkeletonMap.getOrDefault(locale.getLanguage() + "-001",
> 700:                         regionToSkeletonMap.getOrDefault("001", "h")))) :

Original code and the current code are performing 4 lookups even when one of 
the earlier lookup would produce a valid return value. Feels a bit painful :(

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

PR Review Comment: https://git.openjdk.org/jdk/pull/31006#discussion_r3171298355
PR Review Comment: https://git.openjdk.org/jdk/pull/31006#discussion_r3171291519

Reply via email to