mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8295232: "java.locale.useOldISOCodes" property is read lazily
Reviewed-by: lancea, bpb, iris, rriggs, coffeys
This commit is contained in:
parent
3b3438752c
commit
4224d45132
3 changed files with 70 additions and 3 deletions
|
@ -55,6 +55,7 @@ public final class StaticProperty {
|
||||||
private static final String JAVA_PROPERTIES_DATE;
|
private static final String JAVA_PROPERTIES_DATE;
|
||||||
private static final String SUN_JNU_ENCODING;
|
private static final String SUN_JNU_ENCODING;
|
||||||
private static final Charset jnuCharset;
|
private static final Charset jnuCharset;
|
||||||
|
private static final String JAVA_LOCALE_USE_OLD_ISO_CODES;
|
||||||
|
|
||||||
private StaticProperty() {}
|
private StaticProperty() {}
|
||||||
|
|
||||||
|
@ -74,6 +75,7 @@ public final class StaticProperty {
|
||||||
JAVA_PROPERTIES_DATE = getProperty(props, "java.properties.date", null);
|
JAVA_PROPERTIES_DATE = getProperty(props, "java.properties.date", null);
|
||||||
SUN_JNU_ENCODING = getProperty(props, "sun.jnu.encoding");
|
SUN_JNU_ENCODING = getProperty(props, "sun.jnu.encoding");
|
||||||
jnuCharset = Charset.forName(SUN_JNU_ENCODING, Charset.defaultCharset());
|
jnuCharset = Charset.forName(SUN_JNU_ENCODING, Charset.defaultCharset());
|
||||||
|
JAVA_LOCALE_USE_OLD_ISO_CODES = getProperty(props, "java.locale.useOldISOCodes", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getProperty(Properties props, String key) {
|
private static String getProperty(Properties props, String key) {
|
||||||
|
@ -243,4 +245,15 @@ public final class StaticProperty {
|
||||||
public static Charset jnuCharset() {
|
public static Charset jnuCharset() {
|
||||||
return jnuCharset;
|
return jnuCharset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@return the {@code java.locale.useOldISOCodes} system property}
|
||||||
|
*
|
||||||
|
* <strong>{@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.</strong>
|
||||||
|
*/
|
||||||
|
public static String javaLocaleUseOldISOCodes() {
|
||||||
|
return JAVA_LOCALE_USE_OLD_ISO_CODES;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,8 +33,8 @@
|
||||||
package sun.util.locale;
|
package sun.util.locale;
|
||||||
|
|
||||||
import jdk.internal.misc.CDS;
|
import jdk.internal.misc.CDS;
|
||||||
|
import jdk.internal.util.StaticProperty;
|
||||||
import jdk.internal.vm.annotation.Stable;
|
import jdk.internal.vm.annotation.Stable;
|
||||||
import sun.security.action.GetPropertyAction;
|
|
||||||
|
|
||||||
import java.lang.ref.SoftReference;
|
import java.lang.ref.SoftReference;
|
||||||
import java.util.StringJoiner;
|
import java.util.StringJoiner;
|
||||||
|
@ -101,9 +101,10 @@ public final class BaseLocale {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Boolean for the old ISO language code compatibility.
|
* Boolean for the old ISO language code compatibility.
|
||||||
|
* The system property "java.locale.useOldISOCodes" is not security sensitive,
|
||||||
|
* so no need to ensure privileged access here.
|
||||||
*/
|
*/
|
||||||
private static final boolean OLD_ISO_CODES = GetPropertyAction.privilegedGetProperties()
|
private static final boolean OLD_ISO_CODES = StaticProperty.javaLocaleUseOldISOCodes()
|
||||||
.getProperty("java.locale.useOldISOCodes", "false")
|
|
||||||
.equalsIgnoreCase("true");
|
.equalsIgnoreCase("true");
|
||||||
|
|
||||||
// This method must be called with normalize = false only when creating the
|
// This method must be called with normalize = false only when creating the
|
||||||
|
|
53
test/jdk/java/util/Locale/UseOldISOCodesTest.java
Normal file
53
test/jdk/java/util/Locale/UseOldISOCodesTest.java
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @bug 8295232
|
||||||
|
* @summary Ensures java.locale.useOldISOCodes is statically initialized
|
||||||
|
* @library /test/lib
|
||||||
|
* @run main UseOldISOCodesTest
|
||||||
|
*/
|
||||||
|
import java.util.Locale;
|
||||||
|
import jdk.test.lib.process.ProcessTools;
|
||||||
|
|
||||||
|
public class UseOldISOCodesTest {
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
ProcessTools.executeTestJvm("-Djava.locale.useOldISOCodes=true", "UseOldISOCodesTest$Runner")
|
||||||
|
.outputTo(System.out)
|
||||||
|
.errorTo(System.err)
|
||||||
|
.shouldHaveExitValue(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static class Runner {
|
||||||
|
private static final String obsoleteCode = "iw";
|
||||||
|
private static final String newCode = "he";
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.setProperty("java.locale.useOldISOCodes", "false");
|
||||||
|
Locale locale = Locale.of(newCode);
|
||||||
|
if(!obsoleteCode.equals(locale.getLanguage())){
|
||||||
|
throw new RuntimeException("Expected that newcode mapped to old ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue