Skip to content

Commit cd8382e

Browse files
committed
8340477: Remove JDK1.1 compatible behavior for "EST", "MST", and "HST" time zones
Reviewed-by: iris, jlu, joehw
1 parent 7083ae4 commit cd8382e

File tree

5 files changed

+9
-284
lines changed

5 files changed

+9
-284
lines changed

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

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2024, 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
@@ -593,15 +593,6 @@ private ZoneId toZoneId0() {
593593
// delegate to default TZ which is effectively immutable
594594
return defaultZone.toZoneId();
595595
}
596-
// derive it ourselves
597-
if (ZoneInfoFile.useOldMapping() && id.length() == 3) {
598-
if ("EST".equals(id))
599-
return ZoneId.of("America/New_York");
600-
if ("MST".equals(id))
601-
return ZoneId.of("America/Denver");
602-
if ("HST".equals(id))
603-
return ZoneId.of("America/Honolulu");
604-
}
605596
return ZoneId.of(id, ZoneId.SHORT_IDS);
606597
}
607598

src/java.base/share/classes/sun/util/calendar/ZoneInfoFile.java

+6-67
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,20 @@
3636
import java.security.AccessController;
3737
import java.security.PrivilegedAction;
3838
import java.time.LocalDateTime;
39+
import java.time.ZoneId;
3940
import java.time.ZoneOffset;
4041
import java.util.ArrayList;
4142
import java.util.Arrays;
4243
import java.util.Calendar;
4344
import java.util.Collections;
4445
import java.util.HashMap;
4546
import java.util.List;
46-
import java.util.Locale;
4747
import java.util.Map;
4848
import java.util.SimpleTimeZone;
4949
import java.util.concurrent.ConcurrentHashMap;
5050
import java.util.zip.CRC32;
5151

5252
import jdk.internal.util.StaticProperty;
53-
import sun.security.action.GetPropertyAction;
5453

5554
/**
5655
* Loads TZDB time-zone rules for j.u.TimeZone
@@ -65,19 +64,12 @@ public final class ZoneInfoFile {
6564
* @return a set of time zone IDs.
6665
*/
6766
public static String[] getZoneIds() {
68-
int len = regions.length + oldMappings.length;
69-
if (!USE_OLDMAPPING) {
70-
len += 3; // EST/HST/MST not in tzdb.dat
71-
}
67+
var shortIDs = ZoneId.SHORT_IDS.keySet();
68+
int len = regions.length + shortIDs.size();
7269
String[] ids = Arrays.copyOf(regions, len);
7370
int i = regions.length;
74-
if (!USE_OLDMAPPING) {
75-
ids[i++] = "EST";
76-
ids[i++] = "HST";
77-
ids[i++] = "MST";
78-
}
79-
for (int j = 0; j < oldMappings.length; j++) {
80-
ids[i++] = oldMappings[j][0];
71+
for (var id : shortIDs) {
72+
ids[i++] = id;
8173
}
8274
return ids;
8375
}
@@ -216,42 +208,7 @@ private ZoneInfoFile() {
216208
private static String[] regions;
217209
private static int[] indices;
218210

219-
// Flag for supporting JDK backward compatible IDs, such as "EST".
220-
private static final boolean USE_OLDMAPPING;
221-
222-
private static final String[][] oldMappings = new String[][] {
223-
{ "ACT", "Australia/Darwin" },
224-
{ "AET", "Australia/Sydney" },
225-
{ "AGT", "America/Argentina/Buenos_Aires" },
226-
{ "ART", "Africa/Cairo" },
227-
{ "AST", "America/Anchorage" },
228-
{ "BET", "America/Sao_Paulo" },
229-
{ "BST", "Asia/Dhaka" },
230-
{ "CAT", "Africa/Harare" },
231-
{ "CNT", "America/St_Johns" },
232-
{ "CST", "America/Chicago" },
233-
{ "CTT", "Asia/Shanghai" },
234-
{ "EAT", "Africa/Addis_Ababa" },
235-
{ "ECT", "Europe/Paris" },
236-
{ "IET", "America/Indiana/Indianapolis" },
237-
{ "IST", "Asia/Kolkata" },
238-
{ "JST", "Asia/Tokyo" },
239-
{ "MIT", "Pacific/Apia" },
240-
{ "NET", "Asia/Yerevan" },
241-
{ "NST", "Pacific/Auckland" },
242-
{ "PLT", "Asia/Karachi" },
243-
{ "PNT", "America/Phoenix" },
244-
{ "PRT", "America/Puerto_Rico" },
245-
{ "PST", "America/Los_Angeles" },
246-
{ "SST", "Pacific/Guadalcanal" },
247-
{ "VST", "Asia/Ho_Chi_Minh" },
248-
};
249-
250211
static {
251-
String oldmapping = GetPropertyAction
252-
.privilegedGetProperty("sun.timezone.ids.oldmapping", "false")
253-
.toLowerCase(Locale.ROOT);
254-
USE_OLDMAPPING = (oldmapping.equals("yes") || oldmapping.equals("true"));
255212
loadTZDB();
256213
}
257214

@@ -274,24 +231,6 @@ public Void run() {
274231
});
275232
}
276233

277-
private static void addOldMapping() {
278-
for (String[] alias : oldMappings) {
279-
aliases.put(alias[0], alias[1]);
280-
}
281-
if (USE_OLDMAPPING) {
282-
aliases.put("EST", "America/New_York");
283-
aliases.put("MST", "America/Denver");
284-
} else {
285-
aliases.put("EST", "America/Panama");
286-
aliases.put("MST", "America/Phoenix");
287-
}
288-
aliases.put("HST", "Pacific/Honolulu");
289-
}
290-
291-
public static boolean useOldMapping() {
292-
return USE_OLDMAPPING;
293-
}
294-
295234
/**
296235
* Loads the rules from a DateInputStream
297236
*
@@ -350,7 +289,7 @@ private static void load(DataInputStream dis) throws IOException {
350289
}
351290
}
352291
// old us time-zone names
353-
addOldMapping();
292+
aliases.putAll(ZoneId.SHORT_IDS);
354293
}
355294

356295
/////////////////////////Ser/////////////////////////////////

test/jdk/java/util/TimeZone/OldIDMappingTest.java

-120
This file was deleted.

test/jdk/java/util/TimeZone/TzIDOldMapping.java

-64
This file was deleted.

test/jdk/sun/util/calendar/zi/ZoneInfoOld.java

+2-23
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,6 @@ public class ZoneInfoOld extends TimeZone {
8585
private static final long ABBR_MASK = 0xf00L;
8686
private static final int TRANSITION_NSHIFT = 12;
8787

88-
// Flag for supporting JDK backward compatible IDs, such as "EST".
89-
static final boolean USE_OLDMAPPING;
90-
static {
91-
String oldmapping = System.getProperty("sun.timezone.ids.oldmapping", "false").toLowerCase(Locale.ROOT);
92-
USE_OLDMAPPING = (oldmapping.equals("yes") || oldmapping.equals("true"));
93-
}
94-
9588
// IDs having conflicting data between Olson and JDK 1.1
9689
static final Map<String, String> conflictingIDs = Map.of(
9790
"EST", "America/Panama",
@@ -653,18 +646,6 @@ public static String[] getAvailableIDs(int rawOffset) {
653646
public static TimeZone getTimeZone(String ID) {
654647
String givenID = null;
655648

656-
/*
657-
* If old JDK compatibility is specified, get the old alias
658-
* name.
659-
*/
660-
if (USE_OLDMAPPING) {
661-
String compatibleID = TzIDOldMapping.MAP.get(ID);
662-
if (compatibleID != null) {
663-
givenID = ID;
664-
ID = compatibleID;
665-
}
666-
}
667-
668649
ZoneInfoOld zi = ZoneInfoFile.getZoneInfoOld(ID);
669650
if (zi == null) {
670651
// if we can't create an object for the ID, try aliases.
@@ -842,10 +823,8 @@ public synchronized static Map<String, String> getAliasTable() {
842823
if (aliases == null) {
843824
aliases = ZoneInfoFile.getZoneAliases();
844825
if (aliases != null) {
845-
if (!USE_OLDMAPPING) {
846-
// Replace old mappings from `jdk11_backward`
847-
aliases.putAll(conflictingIDs);
848-
}
826+
// Replace old mappings from `jdk11_backward`
827+
aliases.putAll(conflictingIDs);
849828
aliasTable = new SoftReference<Map<String, String>>(aliases);
850829
}
851830
}

0 commit comments

Comments
 (0)