Skip to content

Commit 3e7acfa

Browse files
committed
8349873: StackOverflowError after JDK-8342550 if -Duser.timezone= is set to a deprecated zone id
Reviewed-by: joehw, jlu, iris
1 parent d8fcd43 commit 3e7acfa

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import sun.util.calendar.ZoneInfo;
4848
import sun.util.calendar.ZoneInfoFile;
4949
import sun.util.locale.provider.TimeZoneNameUtility;
50-
import sun.util.logging.PlatformLogger;
5150

5251
/**
5352
* {@code TimeZone} represents a time zone offset, and also figures out daylight
@@ -599,9 +598,9 @@ private ZoneId toZoneId0() {
599598

600599
private static TimeZone getTimeZone(String ID, boolean fallback) {
601600
if (ZoneId.SHORT_IDS.containsKey(ID)) {
602-
PlatformLogger.getLogger(TimeZone.class.getName())
603-
.warning("Use of the three-letter time zone ID \"%s\" is deprecated and it will be removed in a future release"
604-
.formatted(ID));
601+
System.err.printf(
602+
"WARNING: Use of the three-letter time zone ID \"%s\" is deprecated and it will be removed in a future release%n",
603+
ID);
605604
}
606605
TimeZone tz = ZoneInfo.getTimeZone(ID);
607606
if (tz == null) {

test/jdk/java/util/TimeZone/ThreeLetterZoneID.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,37 @@
2323

2424
/*
2525
* @test
26-
* @bug 8342550
26+
* @bug 8342550 8349873
2727
* @summary Three-letter time zone IDs should output a deprecated warning
2828
* message.
2929
* @library /test/lib
3030
* @build jdk.test.lib.process.ProcessTools
31-
* @run main ThreeLetterZoneID
31+
* @run junit ThreeLetterZoneID
3232
*/
3333
import java.util.TimeZone;
3434
import jdk.test.lib.process.ProcessTools;
3535

36+
import org.junit.jupiter.api.Test;
37+
3638
public class ThreeLetterZoneID {
37-
public static void main(String... args) throws Exception {
39+
private static final String WARNING =
40+
"WARNING: Use of the three-letter time zone ID \"PST\" is deprecated and it will be removed in a future release";
41+
42+
public static void main(String... args) {
3843
if (args.length > 0) {
3944
TimeZone.getTimeZone("PST");
4045
} else {
41-
checkWarningMessage();
46+
TimeZone.getDefault();
4247
}
4348
}
4449

45-
public static void checkWarningMessage() throws Exception {
46-
ProcessTools.executeTestJava("ThreeLetterZoneID", "dummy")
47-
.shouldContain("Use of the three-letter time zone ID \"PST\" is deprecated and it will be removed in a future release");
50+
@Test
51+
public void testExplicitGetTimeZone() throws Exception {
52+
ProcessTools.executeTestJava("ThreeLetterZoneID", "dummy").stderrShouldMatch(WARNING);
53+
}
54+
55+
@Test
56+
public void testSysProp() throws Exception {
57+
ProcessTools.executeTestJava("-Duser.timezone=PST", "ThreeLetterZoneID").stderrShouldMatch(WARNING);
4858
}
4959
}

0 commit comments

Comments
 (0)