<i18n dev> RFR: 8330802: Desugar switch in Locale::createLocale

Chen Liang liach at openjdk.org
Mon Apr 22 13:51:29 UTC 2024


On Mon, 22 Apr 2024 13:38:58 GMT, Claes Redestad <redestad at openjdk.org> wrote:

>> src/java.base/share/classes/java/util/Locale.java line 1003:
>> 
>>> 1001:             return new Locale(lk.base, lk.exts);
>>> 1002:         } else {
>>> 1003:             throw new InternalError("should not happen");
>> 
>> The default branch was required in the switch. Can we simply drop this branch and have a ClassCastException to LocalKey instead?
>
> You mean like so:
> 
> 
>     private static Locale createLocale(Object key) {
>         if (key instanceof BaseLocale base) {
>             return new Locale(base, null);
>         }
>         LocaleKey lk = (LocaleKey)key;
>         return new Locale(lk.base, lk.exts);
>     }
>  ```
>  ?
>  
>  I think this should be alright. The type of the "impossibly" thrown exception would differ.

Yes, just like how jli handles the Class/MethodType union type arguments.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/18882#discussion_r1574791014


More information about the i18n-dev mailing list