diff --git a/src/java.base/share/classes/java/util/Locale.java b/src/java.base/share/classes/java/util/Locale.java
index 47a11e72624aa..02f556489e641 100644
--- a/src/java.base/share/classes/java/util/Locale.java
+++ b/src/java.base/share/classes/java/util/Locale.java
@@ -1052,16 +1052,11 @@ private static synchronized Locale getFormatLocale() {
return loc;
}
- @SuppressWarnings("removal")
private static Locale initDefault() {
String language, region, script, country, variant;
- var sm = System.getSecurityManager();
- if (sm != null) {
- sm.checkPropertiesAccess();
- }
- language = StaticProperty.userLanguage(0);
+ language = StaticProperty.USER_LANGUAGE;
// for compatibility, check for old user.region property
- region = StaticProperty.userRegion();
+ region = StaticProperty.USER_REGION;
if (!region.isEmpty()) {
// region can be of form country, country_variant, or _variant
int i = region.indexOf('_');
@@ -1074,29 +1069,24 @@ private static Locale initDefault() {
}
script = "";
} else {
- script = StaticProperty.userScript(0);
- country = StaticProperty.userCountry(0);
- variant = StaticProperty.userVariant(0);
+ script = StaticProperty.USER_SCRIPT;
+ country = StaticProperty.USER_COUNTRY;
+ variant = StaticProperty.USER_VARIANT;
}
return getInstance(language, script, country, variant,
- getDefaultExtensions(StaticProperty.userExtensions(0))
+ getDefaultExtensions(StaticProperty.USER_EXTENSIONS)
.orElse(null));
}
- @SuppressWarnings("removal")
private static Locale initDefault(Locale.Category category) {
Locale locale = Locale.defaultLocale;
- var sm = System.getSecurityManager();
- if (sm != null) {
- sm.checkPropertiesAccess();
- }
return getInstance(
- StaticProperty.userLanguage(category.ordinal() + 1),
- StaticProperty.userScript(category.ordinal() + 1),
- StaticProperty.userCountry(category.ordinal() + 1),
- StaticProperty.userVariant(category.ordinal() + 1),
- getDefaultExtensions(StaticProperty.userExtensions(category.ordinal() + 1))
+ category == Category.DISPLAY ? StaticProperty.USER_LANGUAGE_DISPLAY : StaticProperty.USER_LANGUAGE_FORMAT,
+ category == Category.DISPLAY ? StaticProperty.USER_SCRIPT_DISPLAY : StaticProperty.USER_SCRIPT_FORMAT,
+ category == Category.DISPLAY ? StaticProperty.USER_COUNTRY_DISPLAY : StaticProperty.USER_COUNTRY_FORMAT,
+ category == Category.DISPLAY ? StaticProperty.USER_VARIANT_DISPLAY : StaticProperty.USER_VARIANT_FORMAT,
+ getDefaultExtensions(category == Category.DISPLAY ? StaticProperty.USER_EXTENSIONS_DISPLAY : StaticProperty.USER_EXTENSIONS_FORMAT)
.orElse(locale.getLocaleExtensions()));
}
diff --git a/src/java.base/share/classes/jdk/internal/util/StaticProperty.java b/src/java.base/share/classes/jdk/internal/util/StaticProperty.java
index 5683fe02c4983..da06bf07a65a4 100644
--- a/src/java.base/share/classes/jdk/internal/util/StaticProperty.java
+++ b/src/java.base/share/classes/jdk/internal/util/StaticProperty.java
@@ -57,22 +57,22 @@ public final class StaticProperty {
private static final String OS_NAME;
private static final String OS_ARCH;
private static final String OS_VERSION;
- private static final String USER_LANGUAGE;
- private static final String USER_LANGUAGE_DISPLAY;
- private static final String USER_LANGUAGE_FORMAT;
- private static final String USER_SCRIPT;
- private static final String USER_SCRIPT_DISPLAY;
- private static final String USER_SCRIPT_FORMAT;
- private static final String USER_COUNTRY;
- private static final String USER_COUNTRY_DISPLAY;
- private static final String USER_COUNTRY_FORMAT;
- private static final String USER_VARIANT;
- private static final String USER_VARIANT_DISPLAY;
- private static final String USER_VARIANT_FORMAT;
- private static final String USER_EXTENSIONS;
- private static final String USER_EXTENSIONS_DISPLAY;
- private static final String USER_EXTENSIONS_FORMAT;
- private static final String USER_REGION;
+ public static final String USER_LANGUAGE;
+ public static final String USER_LANGUAGE_DISPLAY;
+ public static final String USER_LANGUAGE_FORMAT;
+ public static final String USER_SCRIPT;
+ public static final String USER_SCRIPT_DISPLAY;
+ public static final String USER_SCRIPT_FORMAT;
+ public static final String USER_COUNTRY;
+ public static final String USER_COUNTRY_DISPLAY;
+ public static final String USER_COUNTRY_FORMAT;
+ public static final String USER_VARIANT;
+ public static final String USER_VARIANT_DISPLAY;
+ public static final String USER_VARIANT_FORMAT;
+ public static final String USER_EXTENSIONS;
+ public static final String USER_EXTENSIONS_DISPLAY;
+ public static final String USER_EXTENSIONS_FORMAT;
+ public static final String USER_REGION;
private StaticProperty() {}
@@ -308,109 +308,4 @@ public static String osArch() {
public static String osVersion() {
return OS_VERSION;
}
-
- /**
- * {@return the {@code user.language} system property}
- * {@link SecurityManager#checkPropertyAccess} is NOT checked
- * in this method. The caller of this method should take care to ensure
- * that the returned property is not made accessible to untrusted code.
- *
- * @param category locale category. 0 for the base property,
- * {@code Locale.Category.ordinal() + 1} for the category
- * specific property
- */
- public static String userLanguage(int category) {
- return switch (category) {
- case 0 -> USER_LANGUAGE;
- case 1 -> USER_LANGUAGE_DISPLAY;
- case 2 -> USER_LANGUAGE_FORMAT;
- default -> throw new InternalError();
- };
- }
-
- /**
- * {@return the {@code user.script} system property}
- * {@link SecurityManager#checkPropertyAccess} is NOT checked
- * in this method. The caller of this method should take care to ensure
- * that the returned property is not made accessible to untrusted code.
- *
- * @param category locale category. 0 for the base property,
- * {@code Locale.Category.ordinal() + 1} for the category
- * specific property
- */
- public static String userScript(int category) {
- return switch (category) {
- case 0 -> USER_SCRIPT;
- case 1 -> USER_SCRIPT_DISPLAY;
- case 2 -> USER_SCRIPT_FORMAT;
- default -> throw new InternalError();
- };
- }
-
- /**
- * {@return the {@code user.country} system property}
- * {@link SecurityManager#checkPropertyAccess} is NOT checked
- * in this method. The caller of this method should take care to ensure
- * that the returned property is not made accessible to untrusted code.
- *
- * @param category locale category. 0 for the base property,
- * {@code Locale.Category.ordinal() + 1} for the category
- * specific property
- */
- public static String userCountry(int category) {
- return switch (category) {
- case 0 -> USER_COUNTRY;
- case 1 -> USER_COUNTRY_DISPLAY;
- case 2 -> USER_COUNTRY_FORMAT;
- default -> throw new InternalError();
- };
- }
-
- /**
- * {@return the {@code user.variant} system property}
- * {@link SecurityManager#checkPropertyAccess} is NOT checked
- * in this method. The caller of this method should take care to ensure
- * that the returned property is not made accessible to untrusted code.
- *
- * @param category locale category. 0 for the base property,
- * {@code Locale.Category.ordinal() + 1} for the category
- * specific property
- */
- public static String userVariant(int category) {
- return switch (category) {
- case 0 -> USER_VARIANT;
- case 1 -> USER_VARIANT_DISPLAY;
- case 2 -> USER_VARIANT_FORMAT;
- default -> throw new InternalError();
- };
- }
-
- /**
- * {@return the {@code user.extensions} system property}
- * {@link SecurityManager#checkPropertyAccess} is NOT checked
- * in this method. The caller of this method should take care to ensure
- * that the returned property is not made accessible to untrusted code.
- *
- * @param category locale category. 0 for the base property,
- * {@code Locale.Category.ordinal() + 1} for the category
- * specific property
- */
- public static String userExtensions(int category) {
- return switch (category) {
- case 0 -> USER_EXTENSIONS;
- case 1 -> USER_EXTENSIONS_DISPLAY;
- case 2 -> USER_EXTENSIONS_FORMAT;
- default -> throw new InternalError();
- };
- }
-
- /**
- * {@return the {@code user.region} system property}
- * {@link SecurityManager#checkPropertyAccess} is NOT checked
- * in this method. The caller of this method should take care to ensure
- * that the returned property is not made accessible to untrusted code.
- */
- public static String userRegion() {
- return USER_REGION;
- }
}