8042590: Running form URL throws NPE
authorpchelko
Mon, 14 Jul 2014 18:16:16 +0400
changeset 25548 42af94daa9dc
parent 25547 5f7926fa7380
child 25549 a2f898967541
8042590: Running form URL throws NPE Reviewed-by: anthony, serb
jdk/src/windows/classes/sun/awt/windows/ThemeReader.java
jdk/src/windows/classes/sun/awt/windows/WToolkit.java
--- a/jdk/src/windows/classes/sun/awt/windows/ThemeReader.java	Thu May 08 19:18:36 2014 +0400
+++ b/jdk/src/windows/classes/sun/awt/windows/ThemeReader.java	Mon Jul 14 18:16:16 2014 +0400
@@ -60,18 +60,12 @@
         new ReentrantReadWriteLock();
     private static final Lock readLock = readWriteLock.readLock();
     private static final Lock writeLock = readWriteLock.writeLock();
+    private static volatile boolean valid = false;
 
     static void flush() {
-        writeLock.lock();
-        try {
-            // Close old themes.
-            for (Long value : widgetToTheme.values()) {
-                closeTheme(value.longValue());
-            }
-            widgetToTheme.clear();
-        } finally {
-            writeLock.unlock();
-        }
+        // Could be called on Toolkit thread, so do not try to aquire locks
+        // to avoid deadlock with theme initialization
+        valid = false;
     }
 
     public static native boolean isThemed();
@@ -98,6 +92,24 @@
     // returns theme value
     // this method should be invoked with readLock locked
     private static Long getTheme(String widget) {
+        if (!valid) {
+            readLock.unlock();
+            writeLock.lock();
+            try {
+                if (!valid) {
+                    // Close old themes.
+                    for (Long value : widgetToTheme.values()) {
+                        closeTheme(value);
+                    }
+                    widgetToTheme.clear();
+                    valid = true;
+                }
+            } finally {
+                readLock.lock();
+                writeLock.unlock();
+            }
+        }
+
         // mostly copied from the javadoc for ReentrantReadWriteLock
         Long theme = widgetToTheme.get(widget);
         if (theme == null) {
--- a/jdk/src/windows/classes/sun/awt/windows/WToolkit.java	Thu May 08 19:18:36 2014 +0400
+++ b/jdk/src/windows/classes/sun/awt/windows/WToolkit.java	Mon Jul 14 18:16:16 2014 +0400
@@ -931,7 +931,16 @@
      * Windows doesn't always send WM_SETTINGCHANGE when it should.
      */
     private void windowsSettingChange() {
-        EventQueue.invokeLater(this::updateProperties);
+        if (AppContext.getAppContext() == null) {
+            // We cannot post the update to any EventQueue. Listeners will
+            // be called on EDTs by DesktopPropertyChangeSupport
+            updateProperties();
+        } else {
+            // Cannot update on Toolkit thread.
+            // DesktopPropertyChangeSupport will call listeners on Toolkit
+            // thread if it has AppContext (standalone mode)
+            EventQueue.invokeLater(this::updateProperties);
+        }
     }
 
     private synchronized void updateProperties() {