diff --git a/make/tools/src/build/tools/javazic/Mappings.java b/make/tools/src/build/tools/javazic/Mappings.java index 5e5498a675ca551754394419cbd5a62d4acb024e..885b9a091b6adff668f1d301000f0c70cb40140d 100644 --- a/make/tools/src/build/tools/javazic/Mappings.java +++ b/make/tools/src/build/tools/javazic/Mappings.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2012, 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 @@ -26,6 +26,7 @@ package build.tools.javazic; import java.util.ArrayList; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -162,6 +163,20 @@ class Mappings { for (String key : toBeRemoved) { aliases.remove(key); } + // Eliminate any alias-to-alias mappings. For example, if + // there are A->B and B->C, A->B is changed to A->C. + Map newMap = new HashMap(); + for (String key : aliases.keySet()) { + String realid = aliases.get(key); + String leaf = realid; + while (aliases.get(leaf) != null) { + leaf = aliases.get(leaf); + } + if (!realid.equals(leaf)) { + newMap.put(key, leaf); + } + } + aliases.putAll(newMap); } Map getAliases() { diff --git a/src/share/classes/sun/util/calendar/ZoneInfo.java b/src/share/classes/sun/util/calendar/ZoneInfo.java index 975e3ed1087f14fc3382d33fea0faf356ed0019a..2838be44603c9a457d6b5b3eceb633f7d589fc45 100644 --- a/src/share/classes/sun/util/calendar/ZoneInfo.java +++ b/src/share/classes/sun/util/calendar/ZoneInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2012, 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 @@ -79,13 +79,18 @@ public class ZoneInfo extends TimeZone { private static final int TRANSITION_NSHIFT = 12; // Flag for supporting JDK backward compatible IDs, such as "EST". - private static final boolean USE_OLDMAPPING; + static final boolean USE_OLDMAPPING; static { String oldmapping = AccessController.doPrivileged( new sun.security.action.GetPropertyAction("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 String[] conflictingIDs = { + "EST", "MST", "HST" + }; + private static final CalendarSystem gcal = CalendarSystem.getGregorianCalendar(); /** @@ -808,32 +813,41 @@ public class ZoneInfo extends TimeZone { private static SoftReference> aliasTable; - /** - * Returns a Map from alias time zone IDs to their standard - * time zone IDs. - * - * @return the Map that holds the mappings from alias time zone IDs - * to their standard time zone IDs, or null if - * ZoneInfoMappings file is not available. - */ - public synchronized static Map getAliasTable() { + static Map getCachedAliasTable() { Map aliases = null; SoftReference> cache = aliasTable; if (cache != null) { aliases = cache.get(); - if (aliases != null) { - return aliases; - } - } - - aliases = ZoneInfoFile.getZoneAliases(); - if (aliases != null) { - aliasTable = new SoftReference<>(aliases); } return aliases; } + /** + * Returns a Map from alias time zone IDs to their standard + * time zone IDs. + * + * @return the Map that holds the mappings from alias time zone IDs + * to their standard time zone IDs, or null if + * ZoneInfoMappings file is not available. + */ + public synchronized static Map getAliasTable() { + Map aliases = getCachedAliasTable(); + if (aliases == null) { + aliases = ZoneInfoFile.getZoneAliases(); + if (aliases != null) { + if (!USE_OLDMAPPING) { + // Remove the conflicting IDs from the alias table. + for (String key : conflictingIDs) { + aliases.remove(key); + } + } + aliasTable = new SoftReference>(aliases); + } + } + return aliases; + } + private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); diff --git a/src/share/classes/sun/util/calendar/ZoneInfoFile.java b/src/share/classes/sun/util/calendar/ZoneInfoFile.java index 2ad72b0e535be0fc6f966c1185a7cc6f22adc4de..094c956a3655cc3a4bcbca3efeac006d3c5446e7 100644 --- a/src/share/classes/sun/util/calendar/ZoneInfoFile.java +++ b/src/share/classes/sun/util/calendar/ZoneInfoFile.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2012, 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 @@ -473,6 +473,8 @@ public class ZoneInfoFile { private static Map zoneInfoObjects = null; + private static final ZoneInfo GMT = new ZoneInfo("GMT", 0); + private static final String ziDir = AccessController.doPrivileged( new PrivilegedAction() { public String run() { @@ -553,8 +555,15 @@ public class ZoneInfoFile { * id. */ public static ZoneInfo getZoneInfo(String id) { + //treat GMT zone as special + if ("GMT".equals(id)) + return (ZoneInfo) GMT.clone(); ZoneInfo zi = getFromCache(id); if (zi == null) { + Map aliases = ZoneInfo.getCachedAliasTable(); + if (aliases != null && aliases.get(id) != null) { + return null; + } zi = createZoneInfo(id); if (zi == null) { return null; @@ -1031,30 +1040,26 @@ public class ZoneInfoFile { * @return the buffer, or null if any I/O error occurred. */ private static byte[] readZoneInfoFile(final String fileName) { + if (fileName.indexOf("..") >= 0) { + return null; + } byte[] buffer = null; try { buffer = AccessController.doPrivileged(new PrivilegedExceptionAction() { public byte[] run() throws IOException { File file = new File(ziDir, fileName); - if (!file.exists() || !file.isFile()) { - return null; - } - file = file.getCanonicalFile(); - String path = file.getCanonicalPath(); byte[] buf = null; - if (path != null && path.startsWith(ziDir)) { - int filesize = (int)file.length(); - if (filesize > 0) { - FileInputStream fis = new FileInputStream(file); - buf = new byte[filesize]; - try { - if (fis.read(buf) != filesize) { - throw new IOException("read error on " + fileName); - } - } finally { - fis.close(); + int filesize = (int)file.length(); + if (filesize > 0) { + FileInputStream fis = new FileInputStream(file); + buf = new byte[filesize]; + try { + if (fis.read(buf) != filesize) { + throw new IOException("read error on " + fileName); } + } finally { + fis.close(); } } return buf;