8013196: TimeZone.getDefault() throws NPE due to sun.awt.AppContext.getAppContext()
authorcoffeys
Thu, 09 May 2013 20:31:47 +0100
changeset 18265 7d1bf89ba22c
parent 18264 286a7973575a
child 18266 26e69da689b9
8013196: TimeZone.getDefault() throws NPE due to sun.awt.AppContext.getAppContext() Reviewed-by: mchung, okutsu
jdk/src/share/classes/sun/awt/AppContext.java
jdk/src/share/classes/sun/misc/SharedSecrets.java
--- a/jdk/src/share/classes/sun/awt/AppContext.java	Wed May 08 12:09:35 2013 -0700
+++ b/jdk/src/share/classes/sun/awt/AppContext.java	Thu May 09 20:31:47 2013 +0100
@@ -814,16 +814,24 @@
     static {
         sun.misc.SharedSecrets.setJavaAWTAccess(new sun.misc.JavaAWTAccess() {
             public Object get(Object key) {
-                return getAppContext().get(key);
+                AppContext ac = getAppContext();
+                return (ac == null) ? null : ac.get(key);
             }
             public void put(Object key, Object value) {
-                getAppContext().put(key, value);
+                AppContext ac = getAppContext();
+                if (ac != null) {
+                    ac.put(key, value);
+                }
             }
             public void remove(Object key) {
-                getAppContext().remove(key);
+                AppContext ac = getAppContext();
+                if (ac != null) {
+                    ac.remove(key);
+                }
             }
             public boolean isDisposed() {
-                return getAppContext().isDisposed();
+                AppContext ac = getAppContext();
+                return (ac == null) ? true : ac.isDisposed();
             }
             public boolean isMainAppContext() {
                 return (numAppContexts.get() == 1 && mainAppContext != null);
--- a/jdk/src/share/classes/sun/misc/SharedSecrets.java	Wed May 08 12:09:35 2013 -0700
+++ b/jdk/src/share/classes/sun/misc/SharedSecrets.java	Thu May 09 20:31:47 2013 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 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
@@ -170,6 +170,9 @@
     public static JavaAWTAccess getJavaAWTAccess() {
         // this may return null in which case calling code needs to
         // provision for.
+        if (javaAWTAccess == null || javaAWTAccess.getContext() == null) {
+            return null;
+        }
         return javaAWTAccess;
     }
 }