Re: RFR: 8282819: Deprecate Locale class constructors [v2]
On Fri, 25 Mar 2022 01:56:33 GMT, Naoto Sato wrote: >> 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. Introduced a new `Locale.of(String...)` method. - PR: https://git.openjdk.java.net/jdk/pull/7947
Re: RFR: 8282819: Deprecate Locale class constructors [v2]
> 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. Naoto Sato has updated the pull request incrementally with one additional commit since the last revision: Added a new factory method, removed pure refactoring from Locale API changes. - Changes: - all: https://git.openjdk.java.net/jdk/pull/7947/files - new: https://git.openjdk.java.net/jdk/pull/7947/files/9ff69cbe..e874ff7e Webrevs: - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=7947&range=01 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=7947&range=00-01 Stats: 887 lines in 193 files changed: 37 ins; 67 del; 783 mod Patch: https://git.openjdk.java.net/jdk/pull/7947.diff Fetch: git fetch https://git.openjdk.java.net/jdk pull/7947/head:pull/7947 PR: https://git.openjdk.java.net/jdk/pull/7947