diff --git a/src/java.base/share/classes/java/util/TimeZone.java b/src/java.base/share/classes/java/util/TimeZone.java index 52d06a858b0..2071ae79b20 100644 --- a/src/java.base/share/classes/java/util/TimeZone.java +++ b/src/java.base/share/classes/java/util/TimeZone.java @@ -47,7 +47,6 @@ import jdk.internal.util.StaticProperty; import sun.util.calendar.ZoneInfo; import sun.util.calendar.ZoneInfoFile; import sun.util.locale.provider.TimeZoneNameUtility; -import sun.util.logging.PlatformLogger; /** * {@code TimeZone} represents a time zone offset, and also figures out daylight @@ -599,9 +598,9 @@ public abstract class TimeZone implements Serializable, Cloneable { private static TimeZone getTimeZone(String ID, boolean fallback) { if (ZoneId.SHORT_IDS.containsKey(ID)) { - PlatformLogger.getLogger(TimeZone.class.getName()) - .warning("Use of the three-letter time zone ID \"%s\" is deprecated and it will be removed in a future release" - .formatted(ID)); + System.err.printf( + "WARNING: Use of the three-letter time zone ID \"%s\" is deprecated and it will be removed in a future release%n", + ID); } TimeZone tz = ZoneInfo.getTimeZone(ID); if (tz == null) { diff --git a/test/jdk/java/util/TimeZone/ThreeLetterZoneID.java b/test/jdk/java/util/TimeZone/ThreeLetterZoneID.java index 5df3ebe5bf0..02b4d89ce2b 100644 --- a/test/jdk/java/util/TimeZone/ThreeLetterZoneID.java +++ b/test/jdk/java/util/TimeZone/ThreeLetterZoneID.java @@ -23,27 +23,37 @@ /* * @test - * @bug 8342550 + * @bug 8342550 8349873 * @summary Three-letter time zone IDs should output a deprecated warning * message. * @library /test/lib * @build jdk.test.lib.process.ProcessTools - * @run main ThreeLetterZoneID + * @run junit ThreeLetterZoneID */ import java.util.TimeZone; import jdk.test.lib.process.ProcessTools; +import org.junit.jupiter.api.Test; + public class ThreeLetterZoneID { - public static void main(String... args) throws Exception { + private static final String WARNING = + "WARNING: Use of the three-letter time zone ID \"PST\" is deprecated and it will be removed in a future release"; + + public static void main(String... args) { if (args.length > 0) { TimeZone.getTimeZone("PST"); } else { - checkWarningMessage(); + TimeZone.getDefault(); } } - public static void checkWarningMessage() throws Exception { - ProcessTools.executeTestJava("ThreeLetterZoneID", "dummy") - .shouldContain("Use of the three-letter time zone ID \"PST\" is deprecated and it will be removed in a future release"); + @Test + public void testExplicitGetTimeZone() throws Exception { + ProcessTools.executeTestJava("ThreeLetterZoneID", "dummy").stderrShouldMatch(WARNING); + } + + @Test + public void testSysProp() throws Exception { + ProcessTools.executeTestJava("-Duser.timezone=PST", "ThreeLetterZoneID").stderrShouldMatch(WARNING); } }