<i18n dev> RFR: 8321206: Make Locale related system properties static properties

Roger Riggs rriggs at openjdk.org
Wed Dec 6 15:31:37 UTC 2023


On Tue, 5 Dec 2023 23:04:55 GMT, Naoto Sato <naoto at openjdk.org> wrote:

> Currently, Locale-related system properties, such as `user.language` or `user.country`, are initialized when the `Locale` class is loaded. Making them static properties is safer than relying on the class initialization timing, which could potentially be changed depending on the implementation.

src/java.base/share/classes/java/util/Locale.java line 1061:

> 1059:         if (sm != null) {
> 1060:             sm.checkPropertiesAccess();
> 1061:         }

This SM check is no longer needed; the use of privilegedGetProperties made access unconditional.
The static properties are always accessible to the locale implementation.

src/java.base/share/classes/jdk/internal/util/StaticProperty.java line 113:

> 111:         USER_EXTENSIONS_DISPLAY = getProperty(props, "user.extensions.display", USER_EXTENSIONS);
> 112:         USER_EXTENSIONS_FORMAT = getProperty(props, "user.extensions.format", USER_EXTENSIONS);
> 113:         USER_REGION = getProperty(props, "user.region", "");

Computing the defaults for these properties should be in the Locale class, close to the initialization of the default locale. Splitting the responsibility across files makes it harder to follow what happens where/when.

src/java.base/share/classes/jdk/internal/util/StaticProperty.java line 415:

> 413:     public static String userRegion() {
> 414:         return USER_REGION;
> 415:     }

Using methods to retrieve these makes is more complicated.
The bleeding of the enum values outside of Locale is undesirable.
Since the property values are final strings, I suggest just making the fields public and keep the mapping local to the Locale class.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/16986#discussion_r1417495473
PR Review Comment: https://git.openjdk.org/jdk/pull/16986#discussion_r1417510556
PR Review Comment: https://git.openjdk.org/jdk/pull/16986#discussion_r1417485546


More information about the i18n-dev mailing list