diff --git a/src/java.base/share/classes/java/util/Locale.java b/src/java.base/share/classes/java/util/Locale.java index a55ddee648e46..452b621ea05b4 100644 --- a/src/java.base/share/classes/java/util/Locale.java +++ b/src/java.base/share/classes/java/util/Locale.java @@ -204,15 +204,18 @@ * key="x"/value="java-1-7" * * - * BCP 47 deviation: Although BCP 47 requires field values to be registered - * in the IANA Language Subtag Registry, the {@code Locale} class - * does not validate this requirement. For example, the variant code "foobar" - * is well-formed since it is composed of 5 to 8 alphanumerics, but is not defined - * the IANA Language Subtag Registry. The {@link Builder} - * only checks if an individual field satisfies the syntactic - * requirement (is well-formed), but does not validate the value - * itself. Conversely, {@link #of(String, String, String) Locale::of} and its - * overloads do not make any syntactic checks on the input. + * BCP 47 deviation: BCP47 defines the following two levels of + * conformance, + * "valid" and "well-formed". A valid tag requires that it is well-formed, its + * subtag values are registered in the IANA Language Subtag Registry, and it does not + * contain duplicate variant or extension singleton subtags. The {@code Locale} + * class does not enforce that subtags are registered in the Subtag Registry. + * {@link Builder} only checks if an individual field satisfies the syntactic + * requirement (is well-formed). When passed duplicate variants, {@code Builder} + * accepts and includes them. When passed duplicate extension singletons, {@code + * Builder} accepts but ignores the duplicate key and its associated value. + * Conversely, {@link #of(String, String, String) Locale::of} and its + * overloads do not check if the input is well-formed at all. * *
The Unicode locale extension specifies optional behavior in * locale-sensitive services. Although the LDML specification defines @@ -561,6 +568,8 @@ * RFC 4647: Matching of Language Tags * @spec https://www.rfc-editor.org/info/rfc5646 * RFC 5646: Tags for Identifying Languages + * @spec https://www.rfc-editor.org/info/rfc6067 + * RFC 6067: BCP 47 Extension U * @spec https://www.unicode.org/reports/tr35 * Unicode Locale Data Markup Language (LDML) * @see Builder @@ -1743,6 +1752,12 @@ public static String caseFoldLanguageTag(String languageTag) { * to {@link Locale.Builder#setLanguageTag(String)} which throws an exception * in this case. * + *
Duplicate variants are accepted and included by the builder. + * However, duplicate extension singleton keys and their associated type + * are accepted but ignored. The same behavior applies to duplicate locale + * keys and attributes within a U extension. Note that subsequent subtags after + * the occurrence of a duplicate are not ignored. + * *
The following conversions are performed:
Duplicate variants are accepted and included by the builder. + * However, duplicate extension singleton keys and their associated type + * are accepted but ignored. The same behavior applies to duplicate locale + * keys and attributes within a U extension. Note that subsequent subtags after + * the occurrence of a duplicate are not ignored. + * *
See {@link Locale##langtag_conversions converions} for a full list * of conversions that are performed on {@code languageTag}. * @@ -2808,7 +2829,8 @@ public Builder setRegion(String region) { * Sets the variant. If variant is null or the empty string, the * variant in this {@code Builder} is removed. Otherwise, it * must consist of one or more {@linkplain Locale##def_variant well-formed} - * subtags, or an exception is thrown. + * subtags, or an exception is thrown. Duplicate variants are + * accepted and included by the builder. * *
Note: This method checks if {@code variant} * satisfies the IETF BCP 47 variant subtag's syntax requirements, @@ -2841,7 +2863,8 @@ public Builder setVariant(String variant) { *
Note: The key {@link #UNICODE_LOCALE_EXTENSION * UNICODE_LOCALE_EXTENSION} ('u') is used for the Unicode locale extension. * Setting a value for this key replaces any existing Unicode locale key/type - * pairs with those defined in the extension. + * pairs with those defined in the extension. Duplicate locale attributes + * as well as locale keys and their associated type are accepted but ignored. * *
Note: The key {@link #PRIVATE_USE_EXTENSION * PRIVATE_USE_EXTENSION} ('x') is used for the private use code. To be