diff options
Diffstat (limited to 'external/ikvm/openjdk/java/util/TimeZone.java')
-rw-r--r-- | external/ikvm/openjdk/java/util/TimeZone.java | 69 |
1 files changed, 43 insertions, 26 deletions
diff --git a/external/ikvm/openjdk/java/util/TimeZone.java b/external/ikvm/openjdk/java/util/TimeZone.java index e3b7cbd54b..63f1028c82 100644 --- a/external/ikvm/openjdk/java/util/TimeZone.java +++ b/external/ikvm/openjdk/java/util/TimeZone.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 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 @@ -43,7 +43,8 @@ import java.lang.ref.SoftReference; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.concurrent.ConcurrentHashMap; -import sun.awt.AppContextDC; +import sun.misc.SharedSecrets; +import sun.misc.JavaAWTAccess; import sun.security.action.GetPropertyAction; import sun.util.TimeZoneNameUtility; import sun.util.calendar.ZoneInfo; @@ -718,15 +719,27 @@ abstract public class TimeZone implements Serializable, Cloneable { * Returns the default TimeZone in an AppContext if any AppContext * has ever used. null is returned if any AppContext hasn't been * used or if the AppContext doesn't have the default TimeZone. - */ - private synchronized static TimeZone getDefaultInAppContext() { - if (!hasSetInAppContext) { - return null; - } - - AppContextDC ac = AppContextDC.getAppContext(); - if (ac != null && !ac.isDisposed()) { - return (TimeZone) ac.get(TimeZone.class); + * + * Note that javaAWTAccess may be null if sun.awt.AppContext class hasn't + * been loaded. If so, it implies that AWTSecurityManager is not our + * SecurityManager and we can use a local static variable. + * This works around a build time issue. + */ + private static TimeZone getDefaultInAppContext() { + // JavaAWTAccess provides access implementation-private methods without using reflection. + JavaAWTAccess javaAWTAccess = SharedSecrets.getJavaAWTAccess(); + if (javaAWTAccess == null) { + return mainAppContextDefault; + } else { + if (!javaAWTAccess.isDisposed()) { + TimeZone tz = (TimeZone) + javaAWTAccess.get(TimeZone.class); + if (tz == null && javaAWTAccess.isMainAppContext()) { + return mainAppContextDefault; + } else { + return tz; + } + } } return null; } @@ -736,19 +749,23 @@ abstract public class TimeZone implements Serializable, Cloneable { * tz. null is handled special: do nothing if any AppContext * hasn't been used, remove the default TimeZone in the * AppContext otherwise. - */ - private synchronized static void setDefaultInAppContext(TimeZone tz) { - if (!hasSetInAppContext && tz == null) { - return; - } - - AppContextDC ac = AppContextDC.getAppContext(); - if (ac != null && !ac.isDisposed()) { - if (tz != null) { - ac.put(TimeZone.class, tz); - hasSetInAppContext = true; - } else { - ac.remove(TimeZone.class); + * + * Note that javaAWTAccess may be null if sun.awt.AppContext class hasn't + * been loaded. If so, it implies that AWTSecurityManager is not our + * SecurityManager and we can use a local static variable. + * This works around a build time issue. + */ + private static void setDefaultInAppContext(TimeZone tz) { + // JavaAWTAccess provides access implementation-private methods without using reflection. + JavaAWTAccess javaAWTAccess = SharedSecrets.getJavaAWTAccess(); + if (javaAWTAccess == null) { + mainAppContextDefault = tz; + } else { + if (!javaAWTAccess.isDisposed()) { + javaAWTAccess.put(TimeZone.class, tz); + if (javaAWTAccess.isMainAppContext()) { + mainAppContextDefault = null; + } } } } @@ -804,8 +821,8 @@ abstract public class TimeZone implements Serializable, Cloneable { static final String GMT_ID = "GMT"; private static final int GMT_ID_LENGTH = 3; - // true if the default TimeZone has been set in any AppContext - private static boolean hasSetInAppContext; + // a static TimeZone we can reference if no AppContext is in place + private static volatile TimeZone mainAppContextDefault; /** * Parses a custom time zone identifier and returns a corresponding zone. |