On Wed, 15 Oct 2025 20:37:16 GMT, Justin Lu <[email protected]> wrote:
>> This PR corrects _test/jdk/java/util/Locale/LocaleEnhanceTest.java_, which
>> has two test cases under `testBuilderSetLanguageTag()` which accidentally
>> pass. One checks that Locale.setLanguageTag(String) throws ILE for duplicate
>> extensions and the other for duplicate U-extension keys. The test cases are
>> updated to actually test the provided code. When the test cases are fixed,
>> they now fail.
>>
>> Fixing the behavior to match the expectation of those test cases is
>> consistent with the specification.
>>
>> From `Locale.forLanguageTag(String)`,
>>
>>>
>>> * <p>If the specified language tag contains any ill-formed subtags,
>>> * the first such subtag and all following subtags are ignored. Compare
>>> * to {@link Locale.Builder#setLanguageTag(String)} which throws an
>>> exception
>>> * in this case.
>>
>> and the RFC specification
>>
>>> Each singleton subtag MUST appear at most one time in each tag
>>> (other than as a private use subtag). That is, singleton subtags
>>> MUST NOT be repeated. For example, the tag "en-a-bbb-a-ccc" is
>>> invalid because the subtag 'a' appears twice.
>>
>> Since duplicate extensions (and Unicode keys/attributes) are invalid,
>> throwing `IllformedLocaleException` in (the strict) `Locale.Builder` and
>> ignoring in (the lenient) `Locale.forLanguageTag` for such tags would be
>> appropriate. This PR updates the implementation as such.
>
> Justin Lu has updated the pull request incrementally with one additional
> commit since the last revision:
>
> Spacing fix in LocaleEnhanceTest.java
>
> Co-authored-by: Andrey Turbanov <[email protected]>
As discussed, while it would be nice to enforce these duplicate cases, we do
not guarantee validity of BCP47 tags. (Primarily, checking against the
registry.) Duplicates falls under "valid", not "well-formed" and
`Locale.Builder` should not have partial conformance of validity. Rather, the
faulty test case should be updated to reflect the existing duplicate behavior.
Additional tests to affirm existing behavior are added for duplicate U
extension attributes as well.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/27775#issuecomment-3412979930