Skip to content

Commit b2daf9d

Browse files
committed
8355522: Remove the java.locale.useOldISOCodes system property
Reviewed-by: jlu, joehw
1 parent b99be50 commit b2daf9d

File tree

6 files changed

+38
-104
lines changed

6 files changed

+38
-104
lines changed

src/java.base/share/classes/java/util/Locale.java

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -535,34 +535,13 @@
535535
*
536536
* <h3><a id="legacy_language_codes">Legacy language codes</a></h3>
537537
*
538-
* <p>Locale's constructors have always converted three language codes to
539-
* their earlier, obsoleted forms: {@code he} maps to {@code iw},
540-
* {@code yi} maps to {@code ji}, and {@code id} maps to
541-
* {@code in}. Since Java SE 17, this is no longer the case. Each
542-
* language maps to its new form; {@code iw} maps to {@code he}, {@code ji}
543-
* maps to {@code yi}, and {@code in} maps to {@code id}.
544-
*
545-
* <p>For backwards compatible behavior, the system property
546-
* {@systemProperty java.locale.useOldISOCodes} reverts the behavior
547-
* back to that of before Java SE 17. If the system property is set to
548-
* {@code true}, those three current language codes are mapped to their
549-
* backward compatible forms. The property is only read at Java runtime
550-
* startup and subsequent calls to {@code System.setProperty()} will
551-
* have no effect. <b>As of Java SE 25, the use of the
552-
* {@code java.locale.useOldISOCodes} system property is deprecated.
553-
* This backwards compatible behavior will be removed in a future release
554-
* of the JDK.</b>
555-
*
556-
* <p>The APIs added in Java SE 7 map between the old and new language codes,
557-
* maintaining the mapped codes internal to Locale (so that
558-
* {@code getLanguage} and {@code toString} reflect the mapped
559-
* code, which depends on the {@code java.locale.useOldISOCodes} system
560-
* property), but using the new codes in the BCP 47 language tag APIs (so
561-
* that {@code toLanguageTag} reflects the new one). This
562-
* preserves the equivalence between Locales no matter which code or
563-
* API is used to construct them. Java's default resource bundle
564-
* lookup mechanism also implements this mapping, so that resources
565-
* can be named using either convention, see {@link ResourceBundle.Control}.
538+
* <p>For compatibility, a {@code Locale} created with one of the
539+
* three obsolete language codes, {@code iw}, {@code ji}, or {@code in},
540+
* will map the language to its modern equivalent, {@code he}, {@code yi},
541+
* or {@code id}, respectively.
542+
* <p>The default resource bundle lookup mechanism also implements
543+
* this mapping, so that resources can be named using either convention,
544+
* see {@link ResourceBundle.Control}.
566545
*
567546
* @spec https://www.rfc-editor.org/info/rfc4647
568547
* RFC 4647: Matching of Language Tags
@@ -2527,8 +2506,7 @@ private Object readResolve() throws java.io.ObjectStreamException {
25272506

25282507
private static String convertOldISOCodes(String language) {
25292508
// we accept both the old and the new ISO codes for the languages whose ISO
2530-
// codes have changed, but we always store the NEW code, unless the property
2531-
// java.locale.useOldISOCodes is set to "true"
2509+
// codes have changed, but we always store the NEW code
25322510
return BaseLocale.convertOldISOCodes(LocaleUtils.toLowerString(language).intern());
25332511
}
25342512

src/java.base/share/classes/jdk/internal/util/StaticProperty.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public final class StaticProperty {
5353
private static final String STDOUT_ENCODING;
5454
private static final String SUN_JNU_ENCODING;
5555
private static final String JAVA_PROPERTIES_DATE;
56-
private static final String JAVA_LOCALE_USE_OLD_ISO_CODES;
5756
private static final String OS_NAME;
5857
private static final String OS_ARCH;
5958
private static final String OS_VERSION;
@@ -94,7 +93,6 @@ private StaticProperty() {}
9493
STDOUT_ENCODING = getProperty(props, "stdout.encoding");
9594
SUN_JNU_ENCODING = getProperty(props, "sun.jnu.encoding");
9695
JAVA_PROPERTIES_DATE = getProperty(props, "java.properties.date", null);
97-
JAVA_LOCALE_USE_OLD_ISO_CODES = getProperty(props, "java.locale.useOldISOCodes", "");
9896
OS_NAME = getProperty(props, "os.name");
9997
OS_ARCH = getProperty(props, "os.arch");
10098
OS_VERSION = getProperty(props, "os.version");
@@ -258,13 +256,6 @@ public static String javaPropertiesDate() {
258256
return JAVA_PROPERTIES_DATE;
259257
}
260258

261-
/**
262-
* {@return the {@code java.locale.useOldISOCodes} system property}
263-
*/
264-
public static String javaLocaleUseOldISOCodes() {
265-
return JAVA_LOCALE_USE_OLD_ISO_CODES;
266-
}
267-
268259
/**
269260
* {@return the {@code os.name} system property}
270261
*/

src/java.base/share/classes/sun/util/locale/BaseLocale.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
import jdk.internal.misc.CDS;
3636
import jdk.internal.util.ReferencedKeySet;
37-
import jdk.internal.util.StaticProperty;
3837
import jdk.internal.vm.annotation.Stable;
3938

4039
import java.util.StringJoiner;
@@ -110,16 +109,14 @@ public ReferencedKeySet<BaseLocale> get() {
110109
private @Stable int hash;
111110

112111
/**
113-
* Boolean for the old ISO language code compatibility.
114-
* The system property "java.locale.useOldISOCodes" is not security sensitive,
115-
* so no need to ensure privileged access here.
112+
* Emit the warning message if the system property "java.locale.useOldISOCodes" is
113+
* specified.
116114
*/
117-
private static final boolean OLD_ISO_CODES = StaticProperty.javaLocaleUseOldISOCodes()
118-
.equalsIgnoreCase("true");
119115
static {
120-
if (OLD_ISO_CODES) {
121-
System.err.println("WARNING: The use of the system property \"java.locale.useOldISOCodes\"" +
122-
" is deprecated. It will be removed in a future release of the JDK.");
116+
if (System.getProperty("java.locale.useOldISOCodes") != null) {
117+
System.err.println("WARNING: The system property" +
118+
" \"java.locale.useOldISOCodes\" is no longer supported." +
119+
" Any specified value will be ignored.");
123120
}
124121
}
125122

@@ -166,7 +163,8 @@ public static BaseLocale getInstance(String language, String script,
166163
}
167164
}
168165

169-
// JDK uses deprecated ISO639.1 language codes for he, yi and id
166+
// Normalize deprecated ISO 639-1 language codes for Hebrew, Yiddish,
167+
// and Indonesian to their current standard forms.
170168
if (!language.isEmpty()) {
171169
language = convertOldISOCodes(language);
172170
}
@@ -183,9 +181,9 @@ public static BaseLocale getInstance(String language, String script,
183181

184182
public static String convertOldISOCodes(String language) {
185183
return switch (language) {
186-
case "he", "iw" -> OLD_ISO_CODES ? "iw" : "he";
187-
case "id", "in" -> OLD_ISO_CODES ? "in" : "id";
188-
case "yi", "ji" -> OLD_ISO_CODES ? "ji" : "yi";
184+
case "iw" -> "he";
185+
case "in" -> "id";
186+
case "ji" -> "yi";
189187
default -> language;
190188
};
191189
}

src/java.base/share/classes/sun/util/locale/provider/LocaleResources.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
import java.util.regex.Pattern;
6363
import java.util.stream.Stream;
6464

65-
import jdk.internal.util.StaticProperty;
6665
import sun.util.resources.LocaleData;
6766
import sun.util.resources.OpenListResourceBundle;
6867
import sun.util.resources.TimeZoneNamesBundle;
@@ -288,16 +287,6 @@ public String getCurrencyName(String key) {
288287
}
289288

290289
public String getLocaleName(String key) {
291-
// Get names for old ISO codes with new ISO code resources
292-
if (StaticProperty.javaLocaleUseOldISOCodes().equalsIgnoreCase("true")) {
293-
key = switch (key) {
294-
case "iw" -> "he";
295-
case "in" -> "id";
296-
case "ji" -> "yi";
297-
default -> key;
298-
};
299-
}
300-
301290
Object localeName = null;
302291
String cacheKey = LOCALE_NAMES + key;
303292

test/jdk/java/util/Locale/LocaleTest.java

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,7 @@
2626
* 4118587 4118595 4122371 4126371 4126880 4135316 4135752 4139504 4139940 4143951
2727
* 4147315 4147317 4147552 4335196 4778440 4940539 5010672 6475525 6544471 6627549
2828
* 6786276 7066203 7085757 8008577 8030696 8170840 8174269 8255086 8263202 8287868
29-
* 8337603
29+
* 8337603 8355522
3030
* @summary test Locales
3131
* @modules jdk.localedata
3232
* @run junit LocaleTest
@@ -703,40 +703,21 @@ public void TestUninstalledISO3Names() {
703703
@Test
704704
public void TestChangedISO639Codes() {
705705
Locale hebrewOld = Locale.of("iw", "IL");
706-
Locale hebrewNew = Locale.of("he", "IL");
707706
Locale yiddishOld = Locale.of("ji", "IL");
708-
Locale yiddishNew = Locale.of("yi", "IL");
709707
Locale indonesianOld = Locale.of("in");
710-
Locale indonesianNew = Locale.of("id");
711708

712-
if ("true".equalsIgnoreCase(System.getProperty("java.locale.useOldISOCodes"))) {
713-
if (!hebrewNew.getLanguage().equals("iw")) {
714-
fail("Got back wrong language code for new Hebrew: expected \"iw\", got \""
715-
+ hebrewNew.getLanguage() + "\"");
716-
}
717-
if (!yiddishNew.getLanguage().equals("ji")) {
718-
fail("Got back wrong language code for new Yiddish: expected \"ji\", got \""
719-
+ yiddishNew.getLanguage() + "\"");
720-
}
721-
if (!indonesianNew.getLanguage().equals("in")) {
722-
fail("Got back wrong language code for new Indonesian: expected \"in\", got \""
723-
+ indonesianNew.getLanguage() + "\"");
724-
}
725-
} else {
726-
if (!hebrewOld.getLanguage().equals("he")) {
727-
fail("Got back wrong language code for old Hebrew: expected \"he\", got \""
728-
+ hebrewNew.getLanguage() + "\"");
729-
}
730-
if (!yiddishOld.getLanguage().equals("yi")) {
731-
fail("Got back wrong language code for old Yiddish: expected \"yi\", got \""
732-
+ yiddishNew.getLanguage() + "\"");
733-
}
734-
if (!indonesianOld.getLanguage().equals("id")) {
735-
fail("Got back wrong language code for old Indonesian: expected \"id\", got \""
736-
+ indonesianNew.getLanguage() + "\"");
737-
}
709+
if (!hebrewOld.getLanguage().equals("he")) {
710+
fail("Got back wrong language code for old Hebrew: expected \"he\", got \""
711+
+ hebrewOld.getLanguage() + "\"");
712+
}
713+
if (!yiddishOld.getLanguage().equals("yi")) {
714+
fail("Got back wrong language code for old Yiddish: expected \"yi\", got \""
715+
+ yiddishOld.getLanguage() + "\"");
716+
}
717+
if (!indonesianOld.getLanguage().equals("id")) {
718+
fail("Got back wrong language code for old Indonesian: expected \"id\", got \""
719+
+ indonesianOld.getLanguage() + "\"");
738720
}
739-
740721
}
741722

742723
/**

test/jdk/java/util/Locale/UseOldISOCodesTest.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/*
2525
* @test
26-
* @bug 8295232 8353118
26+
* @bug 8295232 8353118 8355522
2727
* @summary Tests for the "java.locale.useOldISOCodes" system property
2828
* @library /test/lib
2929
* @run junit UseOldISOCodesTest
@@ -34,7 +34,7 @@
3434

3535
import org.junit.jupiter.api.Test;
3636

37-
import static org.junit.jupiter.api.Assertions.assertEquals;
37+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
3838

3939
public class UseOldISOCodesTest {
4040

@@ -44,20 +44,17 @@ public void testUseOldISOCodes() throws Exception {
4444
.outputTo(System.out)
4545
.errorTo(System.err);
4646
oa.shouldHaveExitValue(0);
47-
oa.stderrShouldMatch("WARNING: The use of the system property \"java.locale.useOldISOCodes\" is deprecated. It will be removed in a future release of the JDK.");
47+
oa.stderrShouldMatch("WARNING: The system property \"java.locale.useOldISOCodes\" is no longer supported. Any specified value will be ignored.");
4848
}
4949

5050
static class Runner {
5151
private static final String obsoleteCode = "iw";
5252
private static final String newCode = "he";
5353

5454
public static void main(String[] args) {
55-
// Ensure java.locale.useOldISOCodes is only interpreted at runtime startup
56-
// Should have no effect
57-
System.setProperty("java.locale.useOldISOCodes", "false");
58-
Locale locale = Locale.of(newCode);
59-
assertEquals(obsoleteCode, locale.getLanguage(),
60-
"newCode 'he' was not mapped to 'iw' with useOldISOCodes=true");
55+
// Ensure java.locale.useOldISOCodes should have no effect
56+
assertNotEquals(obsoleteCode, Locale.of(newCode).getLanguage(),
57+
"newCode 'he' was mapped to 'iw' with useOldISOCodes=true");
6158
}
6259
}
6360
}

0 commit comments

Comments
 (0)