LocaleId constructor crashes when passed a Locale including script information
Issue #505
resolved
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)
-
-
reporter I think you're right, Java 7 seems to be BCP47-compliant. https://docs.oracle.com/javase/tutorial/i18n/locale/extensions.html
-
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 :-)
-
reporter - changed status to resolved
Sweet, thanks Mihai. Fixed in M32. (See commit bf44aa05e3)
- Log in to comment
This seems to be a Java 6 to 7 issue. We have a
JAVALOCMAP
map that converts JavatoString()
special cases to BCP47-valid strings. Andsr_RS_#Latn
is not listed there.It seems there is a new
Locale.toLanguageTag()
that returns the proper BCP47 string. So we can probably eliminateJAVALOCMAP
altogether and maybe even skip the validation. But we should double check the entries inJAVALOCMAP
first.