<i18n dev> RFR: 8282819: Deprecate Locale class constructors

Naoto Sato naoto at openjdk.java.net
Fri Mar 25 01:59:51 UTC 2022


On Fri, 25 Mar 2022 00:18:54 GMT, Stuart Marks <smarks at openjdk.org> wrote:

>> Proposing to deprecate the constructors in the `java.util.Locale` class. There is already a factory method and a builder to return singletons, so there is no need to have constructors anymore unless one purposefully wants to create `ill-formed` Locale objects, which is discouraged. We cannot terminally deprecate those constructors for the compatibility to serialized objects created with older JDKs. Please see the draft CSR for more detail.
>
> src/java.base/share/classes/sun/util/locale/provider/LocaleServiceProviderPool.java line 375:
> 
>> 373:                         (locale.getLanguage().isEmpty() ? "und" : locale.getLanguage()) +
>> 374:                         (locale.getCountry().isEmpty() ? "" : "-" + locale.getCountry()) +
>> 375:                         (locale.getVariant().isEmpty() ? "" : "-x-lvariant-" + locale.getVariant()));
> 
> It seems like this snippet (and ones very similar to it) are repeated several times throughout the JDK code as replacements for the two- and three-arg constructors. This seems like a fair increase in complexity, and the use of "und" and "-x-lvariant-" are quite non-obvious. Would we recommend that third party code that uses the Locale constructors replace them with this snippet? Is there something better that we can provide?

True. One solution could be to expose `Locale.getInstance()`, which is currently a package-private static method, for this purpose. Though that means promoting `ill-formed` locale objects which defy some part of the deprecation cause.

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

PR: https://git.openjdk.java.net/jdk/pull/7947


More information about the i18n-dev mailing list