changeset 7358:5bc43002133c

8042590: Running form URL throws NPE Reviewed-by: anthony, serb
author pchelko
date Fri, 11 Jul 2014 19:00:27 +0100
parents ae0e4cd74a2d
children 159b53697379
files src/windows/classes/sun/awt/windows/ThemeReader.java src/windows/classes/sun/awt/windows/WToolkit.java src/windows/classes/sun/awt/windows/WWindowPeer.java
diffstat 3 files changed, 34 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/windows/classes/sun/awt/windows/ThemeReader.java	Tue May 13 15:41:23 2014 +0400
+++ b/src/windows/classes/sun/awt/windows/ThemeReader.java	Fri Jul 11 19:00:27 2014 +0100
@@ -56,18 +56,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 native static boolean isThemed();
@@ -94,6 +88,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/src/windows/classes/sun/awt/windows/WToolkit.java	Tue May 13 15:41:23 2014 +0400
+++ b/src/windows/classes/sun/awt/windows/WToolkit.java	Fri Jul 11 19:00:27 2014 +0100
@@ -863,11 +863,17 @@
      * Windows doesn't always send WM_SETTINGCHANGE when it should.
      */
     private void windowsSettingChange() {
-        EventQueue.invokeLater(new Runnable() {
-            public void run() {
-                updateProperties();
-            }
-        });
+        if (AppContext.getAppContext() == null) {
+            // We cannot post the update to any EventQueue. Listeners will
+            // be called on EDTs by DesktopPropertyChangeSupport
+            updateProperties();
+        } else {
+            EventQueue.invokeLater(new Runnable() {
+                public void run() {
+                    updateProperties();
+                }
+            });
+        }
     }
 
     private synchronized void updateProperties() {
--- a/src/windows/classes/sun/awt/windows/WWindowPeer.java	Tue May 13 15:41:23 2014 +0400
+++ b/src/windows/classes/sun/awt/windows/WWindowPeer.java	Fri Jul 11 19:00:27 2014 +0100
@@ -421,6 +421,7 @@
      */
     public static long[] getActiveWindowHandles() {
         AppContext appContext = AppContext.getAppContext();
+        if (appContext == null) return null;
         synchronized (appContext) {
             List<WWindowPeer> l = (List<WWindowPeer>)appContext.get(ACTIVE_WINDOWS_KEY);
             if (l == null) {