8340477: Remove JDK1.1 compatible behavior for "EST", "MST", and "HST" time zones
Reviewed-by: iris, jlu, joehw
This commit is contained in:
parent
97c9212842
commit
71583222eb
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2024, 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
|
||||
@ -593,15 +593,6 @@ public abstract class TimeZone implements Serializable, Cloneable {
|
||||
// delegate to default TZ which is effectively immutable
|
||||
return defaultZone.toZoneId();
|
||||
}
|
||||
// derive it ourselves
|
||||
if (ZoneInfoFile.useOldMapping() && id.length() == 3) {
|
||||
if ("EST".equals(id))
|
||||
return ZoneId.of("America/New_York");
|
||||
if ("MST".equals(id))
|
||||
return ZoneId.of("America/Denver");
|
||||
if ("HST".equals(id))
|
||||
return ZoneId.of("America/Honolulu");
|
||||
}
|
||||
return ZoneId.of(id, ZoneId.SHORT_IDS);
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,7 @@ import java.io.StreamCorruptedException;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -43,14 +44,12 @@ import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.SimpleTimeZone;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.zip.CRC32;
|
||||
|
||||
import jdk.internal.util.StaticProperty;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
|
||||
/**
|
||||
* Loads TZDB time-zone rules for j.u.TimeZone
|
||||
@ -65,19 +64,12 @@ public final class ZoneInfoFile {
|
||||
* @return a set of time zone IDs.
|
||||
*/
|
||||
public static String[] getZoneIds() {
|
||||
int len = regions.length + oldMappings.length;
|
||||
if (!USE_OLDMAPPING) {
|
||||
len += 3; // EST/HST/MST not in tzdb.dat
|
||||
}
|
||||
var shortIDs = ZoneId.SHORT_IDS.keySet();
|
||||
int len = regions.length + shortIDs.size();
|
||||
String[] ids = Arrays.copyOf(regions, len);
|
||||
int i = regions.length;
|
||||
if (!USE_OLDMAPPING) {
|
||||
ids[i++] = "EST";
|
||||
ids[i++] = "HST";
|
||||
ids[i++] = "MST";
|
||||
}
|
||||
for (int j = 0; j < oldMappings.length; j++) {
|
||||
ids[i++] = oldMappings[j][0];
|
||||
for (var id : shortIDs) {
|
||||
ids[i++] = id;
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
@ -216,42 +208,7 @@ public final class ZoneInfoFile {
|
||||
private static String[] regions;
|
||||
private static int[] indices;
|
||||
|
||||
// Flag for supporting JDK backward compatible IDs, such as "EST".
|
||||
private static final boolean USE_OLDMAPPING;
|
||||
|
||||
private static final String[][] oldMappings = new String[][] {
|
||||
{ "ACT", "Australia/Darwin" },
|
||||
{ "AET", "Australia/Sydney" },
|
||||
{ "AGT", "America/Argentina/Buenos_Aires" },
|
||||
{ "ART", "Africa/Cairo" },
|
||||
{ "AST", "America/Anchorage" },
|
||||
{ "BET", "America/Sao_Paulo" },
|
||||
{ "BST", "Asia/Dhaka" },
|
||||
{ "CAT", "Africa/Harare" },
|
||||
{ "CNT", "America/St_Johns" },
|
||||
{ "CST", "America/Chicago" },
|
||||
{ "CTT", "Asia/Shanghai" },
|
||||
{ "EAT", "Africa/Addis_Ababa" },
|
||||
{ "ECT", "Europe/Paris" },
|
||||
{ "IET", "America/Indiana/Indianapolis" },
|
||||
{ "IST", "Asia/Kolkata" },
|
||||
{ "JST", "Asia/Tokyo" },
|
||||
{ "MIT", "Pacific/Apia" },
|
||||
{ "NET", "Asia/Yerevan" },
|
||||
{ "NST", "Pacific/Auckland" },
|
||||
{ "PLT", "Asia/Karachi" },
|
||||
{ "PNT", "America/Phoenix" },
|
||||
{ "PRT", "America/Puerto_Rico" },
|
||||
{ "PST", "America/Los_Angeles" },
|
||||
{ "SST", "Pacific/Guadalcanal" },
|
||||
{ "VST", "Asia/Ho_Chi_Minh" },
|
||||
};
|
||||
|
||||
static {
|
||||
String oldmapping = GetPropertyAction
|
||||
.privilegedGetProperty("sun.timezone.ids.oldmapping", "false")
|
||||
.toLowerCase(Locale.ROOT);
|
||||
USE_OLDMAPPING = (oldmapping.equals("yes") || oldmapping.equals("true"));
|
||||
loadTZDB();
|
||||
}
|
||||
|
||||
@ -274,24 +231,6 @@ public final class ZoneInfoFile {
|
||||
});
|
||||
}
|
||||
|
||||
private static void addOldMapping() {
|
||||
for (String[] alias : oldMappings) {
|
||||
aliases.put(alias[0], alias[1]);
|
||||
}
|
||||
if (USE_OLDMAPPING) {
|
||||
aliases.put("EST", "America/New_York");
|
||||
aliases.put("MST", "America/Denver");
|
||||
} else {
|
||||
aliases.put("EST", "America/Panama");
|
||||
aliases.put("MST", "America/Phoenix");
|
||||
}
|
||||
aliases.put("HST", "Pacific/Honolulu");
|
||||
}
|
||||
|
||||
public static boolean useOldMapping() {
|
||||
return USE_OLDMAPPING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the rules from a DateInputStream
|
||||
*
|
||||
@ -350,7 +289,7 @@ public final class ZoneInfoFile {
|
||||
}
|
||||
}
|
||||
// old us time-zone names
|
||||
addOldMapping();
|
||||
aliases.putAll(ZoneId.SHORT_IDS);
|
||||
}
|
||||
|
||||
/////////////////////////Ser/////////////////////////////////
|
||||
|
@ -1,120 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2024, 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 6466476
|
||||
* @summary Compatibility test for the old JDK ID mapping and Olson IDs
|
||||
* @comment Expecting the new (Olson compatible) mapping (default)
|
||||
* @run main/othervm -Dsun.timezone.ids.oldmapping=null OldIDMappingTest -new
|
||||
* @run main/othervm -Dsun.timezone.ids.oldmapping="" OldIDMappingTest -new
|
||||
* @run main/othervm -Dsun.timezone.ids.oldmapping=no OldIDMappingTest -new
|
||||
* @run main/othervm -Dsun.timezone.ids.oldmapping=No OldIDMappingTest -new
|
||||
* @run main/othervm -Dsun.timezone.ids.oldmapping=NO OldIDMappingTest -new
|
||||
* @run main/othervm -Dsun.timezone.ids.oldmapping=false OldIDMappingTest -new
|
||||
* @run main/othervm -Dsun.timezone.ids.oldmapping=False OldIDMappingTest -new
|
||||
* @run main/othervm -Dsun.timezone.ids.oldmapping=FALSE OldIDMappingTest -new
|
||||
* @run main/othervm -Dsun.timezone.ids.oldmapping=Hello OldIDMappingTest -new
|
||||
* @comment Expecting the old mapping
|
||||
* @run main/othervm -Dsun.timezone.ids.oldmapping=true OldIDMappingTest -old
|
||||
* @run main/othervm -Dsun.timezone.ids.oldmapping=True OldIDMappingTest -old
|
||||
* @run main/othervm -Dsun.timezone.ids.oldmapping=TRUE OldIDMappingTest -old
|
||||
* @run main/othervm -Dsun.timezone.ids.oldmapping=yes OldIDMappingTest -old
|
||||
* @run main/othervm -Dsun.timezone.ids.oldmapping=Yes OldIDMappingTest -old
|
||||
* @run main/othervm -Dsun.timezone.ids.oldmapping=YES OldIDMappingTest -old
|
||||
*/
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class OldIDMappingTest {
|
||||
private static final String MAPPING_PROPERTY_NAME = "sun.timezone.ids.oldmapping";
|
||||
private static final Map<String, String> newmap = new HashMap<String, String>();
|
||||
static {
|
||||
// Add known new mappings
|
||||
newmap.put("EST", "EST");
|
||||
newmap.put("MST", "MST");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
boolean useOldMapping = true;
|
||||
String arg = args[0];
|
||||
if (arg.equals("-new")) {
|
||||
useOldMapping = false;
|
||||
} else if (arg.equals("-old")) {
|
||||
useOldMapping = true;
|
||||
} else {
|
||||
throw new RuntimeException("-old or -new must be specified; got " + arg);
|
||||
}
|
||||
|
||||
Map<String, String> oldmap = TzIDOldMapping.MAP;
|
||||
String prop = System.getProperty(MAPPING_PROPERTY_NAME);
|
||||
System.out.println(MAPPING_PROPERTY_NAME + "=" + prop);
|
||||
|
||||
// Try the test multiple times with modifying TimeZones to
|
||||
// make sure TimeZone instances for the old mapping are
|
||||
// properly copied (defensive copy).
|
||||
for (int count = 0; count < 3; count++) {
|
||||
for (String id : oldmap.keySet()) {
|
||||
TimeZone tzAlias = TimeZone.getTimeZone(id);
|
||||
TimeZone tz = TimeZone.getTimeZone(oldmap.get(id));
|
||||
if (useOldMapping) {
|
||||
if (!tzAlias.hasSameRules(tz)) {
|
||||
throw new RuntimeException("OLDMAP: " + MAPPING_PROPERTY_NAME
|
||||
+ "=" + prop + ": " + id
|
||||
+ " isn't an alias of " + oldmap.get(id));
|
||||
}
|
||||
if (count == 0) {
|
||||
System.out.println(" " + id + " => " + oldmap.get(id));
|
||||
}
|
||||
tzAlias.setRawOffset(tzAlias.getRawOffset() * count);
|
||||
} else {
|
||||
if (!newmap.containsKey(id)) {
|
||||
// ignore ids not contained in the new map
|
||||
if (count == 0) {
|
||||
System.out.println(" " + id + " => " + oldmap.get(id));
|
||||
}
|
||||
tzAlias.setRawOffset(tzAlias.getRawOffset() * count);
|
||||
continue;
|
||||
}
|
||||
if (tzAlias.hasSameRules(tz)) {
|
||||
throw new RuntimeException("NEWMAP: " + MAPPING_PROPERTY_NAME
|
||||
+ "=" + prop + ": " + id
|
||||
+ " is an alias of " + oldmap.get(id));
|
||||
}
|
||||
tz = TimeZone.getTimeZone(newmap.get(id));
|
||||
if (!tzAlias.hasSameRules(tz)) {
|
||||
throw new RuntimeException("NEWMAP: " + MAPPING_PROPERTY_NAME
|
||||
+ "=" + prop + ": " + id
|
||||
+ " isn't an alias of " + newmap.get(id));
|
||||
}
|
||||
if (count == 0) {
|
||||
System.out.println(" " + id + " => " + newmap.get(id));
|
||||
}
|
||||
tzAlias.setRawOffset(tzAlias.getRawOffset() * count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, 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.
|
||||
*/
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
class TzIDOldMapping {
|
||||
static final Map<String, String> MAP = new HashMap<String, String>();
|
||||
static {
|
||||
String[][] oldmap = {
|
||||
{ "ACT", "Australia/Darwin" },
|
||||
{ "AET", "Australia/Sydney" },
|
||||
{ "AGT", "America/Argentina/Buenos_Aires" },
|
||||
{ "ART", "Africa/Cairo" },
|
||||
{ "AST", "America/Anchorage" },
|
||||
{ "BET", "America/Sao_Paulo" },
|
||||
{ "BST", "Asia/Dhaka" },
|
||||
{ "CAT", "Africa/Harare" },
|
||||
{ "CNT", "America/St_Johns" },
|
||||
{ "CST", "America/Chicago" },
|
||||
{ "CTT", "Asia/Shanghai" },
|
||||
{ "EAT", "Africa/Addis_Ababa" },
|
||||
{ "ECT", "Europe/Paris" },
|
||||
{ "EST", "America/New_York" },
|
||||
{ "HST", "Pacific/Honolulu" },
|
||||
{ "IET", "America/Indianapolis" },
|
||||
{ "IST", "Asia/Calcutta" },
|
||||
{ "JST", "Asia/Tokyo" },
|
||||
{ "MIT", "Pacific/Apia" },
|
||||
{ "MST", "America/Denver" },
|
||||
{ "NET", "Asia/Yerevan" },
|
||||
{ "NST", "Pacific/Auckland" },
|
||||
{ "PLT", "Asia/Karachi" },
|
||||
{ "PNT", "America/Phoenix" },
|
||||
{ "PRT", "America/Puerto_Rico" },
|
||||
{ "PST", "America/Los_Angeles" },
|
||||
{ "SST", "Pacific/Guadalcanal" },
|
||||
{ "VST", "Asia/Saigon" },
|
||||
};
|
||||
for (String[] pair : oldmap) {
|
||||
MAP.put(pair[0], pair[1]);
|
||||
}
|
||||
}
|
||||
}
|
@ -85,13 +85,6 @@ public class ZoneInfoOld extends TimeZone {
|
||||
private static final long ABBR_MASK = 0xf00L;
|
||||
private static final int TRANSITION_NSHIFT = 12;
|
||||
|
||||
// Flag for supporting JDK backward compatible IDs, such as "EST".
|
||||
static final boolean USE_OLDMAPPING;
|
||||
static {
|
||||
String oldmapping = System.getProperty("sun.timezone.ids.oldmapping", "false").toLowerCase(Locale.ROOT);
|
||||
USE_OLDMAPPING = (oldmapping.equals("yes") || oldmapping.equals("true"));
|
||||
}
|
||||
|
||||
// IDs having conflicting data between Olson and JDK 1.1
|
||||
static final Map<String, String> conflictingIDs = Map.of(
|
||||
"EST", "America/Panama",
|
||||
@ -653,18 +646,6 @@ public class ZoneInfoOld extends TimeZone {
|
||||
public static TimeZone getTimeZone(String ID) {
|
||||
String givenID = null;
|
||||
|
||||
/*
|
||||
* If old JDK compatibility is specified, get the old alias
|
||||
* name.
|
||||
*/
|
||||
if (USE_OLDMAPPING) {
|
||||
String compatibleID = TzIDOldMapping.MAP.get(ID);
|
||||
if (compatibleID != null) {
|
||||
givenID = ID;
|
||||
ID = compatibleID;
|
||||
}
|
||||
}
|
||||
|
||||
ZoneInfoOld zi = ZoneInfoFile.getZoneInfoOld(ID);
|
||||
if (zi == null) {
|
||||
// if we can't create an object for the ID, try aliases.
|
||||
@ -842,10 +823,8 @@ public class ZoneInfoOld extends TimeZone {
|
||||
if (aliases == null) {
|
||||
aliases = ZoneInfoFile.getZoneAliases();
|
||||
if (aliases != null) {
|
||||
if (!USE_OLDMAPPING) {
|
||||
// Replace old mappings from `jdk11_backward`
|
||||
aliases.putAll(conflictingIDs);
|
||||
}
|
||||
// Replace old mappings from `jdk11_backward`
|
||||
aliases.putAll(conflictingIDs);
|
||||
aliasTable = new SoftReference<Map<String, String>>(aliases);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user