LocaleId constructor crashes when passed a Locale including script information

Issue #505 resolved
Chase Tingley created an issue

Giuseppe discovered this. This works fine:

        LocaleId srLatin = LocaleId.fromBCP47("sr-Latn-RS");
        LocaleId srCyrl = new LocaleId(new Locale("sr-Cyrl-RS"));
        assertEquals("sr-latn-rs", srLatin.toString());
        assertEquals("sr-cyrl-rs", srCyrl.toString());

These crash:

        srLatin = new LocaleId(Locale.forLanguageTag("sr-Latn-RS"));
        srCyrl = new LocaleId(Locale.forLanguageTag("sr-Cyrl-RS"));
        assertEquals("sr-latn-rs", srLatin.toString());
        assertEquals("sr-cyrl-rs", srCyrl.toString());

In the failing cases, the constructor crashes because normalize() is trying to parse out the strings like sr_RS_#Latn, and doesn't know what to do with the #.

Comments (4)

  1. YvesS

    This seems to be a Java 6 to 7 issue. We have a JAVALOCMAP map that converts Java toString() special cases to BCP47-valid strings. And sr_RS_#Latn is not listed there.

    It seems there is a new Locale.toLanguageTag() that returns the proper BCP47 string. So we can probably eliminate JAVALOCMAP altogether and maybe even skip the validation. But we should double check the entries in JAVALOCMAP first.

  2. Mihai Nita

    Added the crash case as unit test. It works now, after the "LocaleId on top of ICU" refactoring. The only difference is the casing (toString() returns lang-Script-REGION, so "sr-Latn-RS", not "sr-latn-rs")

    So this looks like it is fixed (or it will be in the next release :-)

  3. Log in to comment