diff --git a/src/java.base/share/classes/java/util/TimeZone.java b/src/java.base/share/classes/java/util/TimeZone.java index f0b122418c9ff..7c7e24814c368 100644 --- a/src/java.base/share/classes/java/util/TimeZone.java +++ b/src/java.base/share/classes/java/util/TimeZone.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2025, 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 @@ -46,6 +46,7 @@ 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 @@ -596,6 +597,11 @@ private ZoneId toZoneId0() { } 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)); + } TimeZone tz = ZoneInfo.getTimeZone(ID); if (tz == null) { tz = parseCustomTimeZone(ID); diff --git a/src/java.base/share/classes/sun/util/cldr/CLDRTimeZoneNameProviderImpl.java b/src/java.base/share/classes/sun/util/cldr/CLDRTimeZoneNameProviderImpl.java index 47dacd21aae1f..d2f94fa39d94b 100644 --- a/src/java.base/share/classes/sun/util/cldr/CLDRTimeZoneNameProviderImpl.java +++ b/src/java.base/share/classes/sun/util/cldr/CLDRTimeZoneNameProviderImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, 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 @@ -36,6 +36,8 @@ import java.util.ResourceBundle; import java.util.Set; import java.util.TimeZone; + +import sun.util.calendar.ZoneInfo; import sun.util.calendar.ZoneInfoFile; import sun.util.locale.provider.LocaleProviderAdapter; import sun.util.locale.provider.LocaleResources; @@ -131,7 +133,7 @@ protected String[][] getZoneStrings(Locale locale) { // Derive fallback time zone name according to LDML's logic private void deriveFallbackNames(String[] names, Locale locale) { - boolean noDST = TimeZone.getTimeZone(names[0]).toZoneId().getRules().isFixedOffset(); + boolean noDST = ZoneInfo.getTimeZone(names[0]).toZoneId().getRules().isFixedOffset(); for (int i = INDEX_STD_LONG; i <= INDEX_GEN_SHORT; i++) { deriveFallbackName(names, i, locale, noDST); diff --git a/test/jdk/java/util/TimeZone/ThreeLetterZoneID.java b/test/jdk/java/util/TimeZone/ThreeLetterZoneID.java new file mode 100644 index 0000000000000..5df3ebe5bf0f1 --- /dev/null +++ b/test/jdk/java/util/TimeZone/ThreeLetterZoneID.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025, 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 8342550 + * @summary Three-letter time zone IDs should output a deprecated warning + * message. + * @library /test/lib + * @build jdk.test.lib.process.ProcessTools + * @run main ThreeLetterZoneID + */ +import java.util.TimeZone; +import jdk.test.lib.process.ProcessTools; + +public class ThreeLetterZoneID { + public static void main(String... args) throws Exception { + if (args.length > 0) { + TimeZone.getTimeZone("PST"); + } else { + checkWarningMessage(); + } + } + + 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"); + } +}