8321206: Make Locale related system properties StaticProperty

Reviewed-by: rriggs
This commit is contained in:
Naoto Sato 2023-12-08 18:47:40 +00:00
parent 6c13a3032f
commit 0c178beb69
3 changed files with 62 additions and 20 deletions

View file

@ -50,6 +50,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.spi.LocaleNameProvider;
import java.util.stream.Stream;
import jdk.internal.util.StaticProperty;
import jdk.internal.vm.annotation.Stable;
import sun.security.action.GetPropertyAction;
@ -1053,11 +1054,10 @@ public final class Locale implements Cloneable, Serializable {
private static Locale initDefault() {
String language, region, script, country, variant;
Properties props = GetPropertyAction.privilegedGetProperties();
language = props.getProperty("user.language", "en");
language = StaticProperty.USER_LANGUAGE;
// for compatibility, check for old user.region property
region = props.getProperty("user.region");
if (region != null) {
region = StaticProperty.USER_REGION;
if (!region.isEmpty()) {
// region can be of form country, country_variant, or _variant
int i = region.indexOf('_');
if (i >= 0) {
@ -1069,30 +1069,24 @@ public final class Locale implements Cloneable, Serializable {
}
script = "";
} else {
script = props.getProperty("user.script", "");
country = props.getProperty("user.country", "");
variant = props.getProperty("user.variant", "");
script = StaticProperty.USER_SCRIPT;
country = StaticProperty.USER_COUNTRY;
variant = StaticProperty.USER_VARIANT;
}
return getInstance(language, script, country, variant,
getDefaultExtensions(props.getProperty("user.extensions", ""))
getDefaultExtensions(StaticProperty.USER_EXTENSIONS)
.orElse(null));
}
private static Locale initDefault(Locale.Category category) {
Properties props = GetPropertyAction.privilegedGetProperties();
Locale locale = Locale.defaultLocale;
return getInstance(
props.getProperty(category.languageKey,
locale.getLanguage()),
props.getProperty(category.scriptKey,
locale.getScript()),
props.getProperty(category.countryKey,
locale.getCountry()),
props.getProperty(category.variantKey,
locale.getVariant()),
getDefaultExtensions(props.getProperty(category.extensionsKey, ""))
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()));
}