RFR: 8196869: Optimize Locale creation

Claes Redestad claes.redestad at oracle.com
Wed Feb 7 10:26:56 UTC 2018

Hi Paul,

On 2018-02-06 20:55, Paul Sandoz wrote:
> Quick observation:
>   261         private BaseLocale getBaseLocale() {
>   262             return (holder == null) ? holderRef.get() : holder;
>   263         }
> This method can return null if the soft ref has been cleared.
> But you don’t check in equals:
>   270             if (obj instanceof Key && this.hash == ((Key)obj).hash) {
>   271                 BaseLocale other = ((Key) obj).getBaseLocale();
>   272                 BaseLocale locale = this.getBaseLocale();
>   273                 if (LocaleUtils.caseIgnoreMatch(other.getLanguage(), locale.getLanguage())

good eye!

It seems this wasn't caught by the existing regression tests since none 
of them
recreate Locales in that are likely to have been reclaimed, but still 
likely to still
be in the CHM (it's a race of sorts since they'll be removed when the 
processing happen).

I added a regression test with the smallest and quickest reproducer I 
could come up
with that provokes a NPE if we don't check null along with the fix to 


For the normalize(Key) case we can deduce that a !normalized Key will 
always have
a strongly referenced BaseLocale and thus not need to deal with 
returning null. I clarified this in the code and added an assert (that 
would be triggered
by the added test if it wasn't true).



More information about the core-libs-dev mailing list