Skip to content

Commit 564066d

Browse files
committed
8353118: Deprecate the use of java.locale.useOldISOCodes system property
Reviewed-by: iris, jlu
1 parent a1ab1d8 commit 564066d

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,8 @@
418418
* <p>The filtering operation returns all matching language tags. It is defined
419419
* in RFC 4647 as follows:
420420
* "In filtering, each language range represents the least specific language
421-
* tag (that is, the language tag with fewest number of subtags) that is an
422-
* acceptable match. All of the language tags in the matching set of tags will
421+
* tag (that is, the language tag with the fewest number of subtags) that is an
422+
* acceptable match. All the language tags in the matching set of tags will
423423
* have an equal or greater number of subtags than the language range. Every
424424
* non-wildcard subtag in the language range will appear in every one of the
425425
* matching language tags."
@@ -541,9 +541,12 @@
541541
* {@code true}, those three current language codes are mapped to their
542542
* backward compatible forms. The property is only read at Java runtime
543543
* startup and subsequent calls to {@code System.setProperty()} will
544-
* have no effect.
544+
* have no effect. <b>As of Java SE 25, the use of the
545+
* {@code java.locale.useOldISOCodes} system property is deprecated.
546+
* This backwards compatible behavior will be removed in a future release
547+
* of the JDK.</b>
545548
*
546-
* <p>The APIs added in 1.7 map between the old and new language codes,
549+
* <p>The APIs added in Java SE 7 map between the old and new language codes,
547550
* maintaining the mapped codes internal to Locale (so that
548551
* {@code getLanguage} and {@code toString} reflect the mapped
549552
* code, which depends on the {@code java.locale.useOldISOCodes} system

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ public final class BaseLocale {
106106
*/
107107
private static final boolean OLD_ISO_CODES = StaticProperty.javaLocaleUseOldISOCodes()
108108
.equalsIgnoreCase("true");
109+
static {
110+
if (OLD_ISO_CODES) {
111+
System.err.println("WARNING: The use of the system property \"java.locale.useOldISOCodes\"" +
112+
" is deprecated. It will be removed in a future release of the JDK.");
113+
}
114+
}
109115

110116
private BaseLocale(String language, String script, String region, String variant) {
111117
this.language = language;

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 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
@@ -23,8 +23,8 @@
2323

2424
/*
2525
* @test
26-
* @bug 8295232
27-
* @summary Ensures java.locale.useOldISOCodes is statically initialized
26+
* @bug 8295232 8353118
27+
* @summary Tests for the "java.locale.useOldISOCodes" system property
2828
* @library /test/lib
2929
* @run junit UseOldISOCodesTest
3030
*/
@@ -38,20 +38,21 @@
3838

3939
public class UseOldISOCodesTest {
4040

41-
// Ensure java.locale.useOldISOCodes is only interpreted at runtime startup
4241
@Test
43-
public void staticInitializationTest() throws Exception {
44-
ProcessTools.executeTestJava("-Djava.locale.useOldISOCodes=true", "UseOldISOCodesTest$Runner")
42+
public void testUseOldISOCodes() throws Exception {
43+
var oa = ProcessTools.executeTestJava("-Djava.locale.useOldISOCodes=true", "UseOldISOCodesTest$Runner")
4544
.outputTo(System.out)
46-
.errorTo(System.err)
47-
.shouldHaveExitValue(0);
45+
.errorTo(System.err);
46+
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.");
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
5556
// Should have no effect
5657
System.setProperty("java.locale.useOldISOCodes", "false");
5758
Locale locale = Locale.of(newCode);

0 commit comments

Comments
 (0)