changeset 7357:8cff6ce00a91 jdk7u65-b15

8042590: Running form URL throws NPE Reviewed-by: anthony, serb
author pchelko
date Mon, 19 May 2014 18:31:48 +0400
parents 355c2e9a57de
children 190017413768 07fc91c550da
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, 35 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/windows/classes/sun/awt/windows/ThemeReader.java	Wed May 28 02:34:16 2014 -0700
+++ b/src/windows/classes/sun/awt/windows/ThemeReader.java	Mon May 19 18:31:48 2014 +0400
@@ -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	Wed May 28 02:34:16 2014 -0700
+++ b/src/windows/classes/sun/awt/windows/WToolkit.java	Mon May 19 18:31:48 2014 +0400
@@ -864,12 +864,18 @@
      * Windows doesn't always send WM_SETTINGCHANGE when it should.
      */
     private void windowsSettingChange() {
-        EventQueue.invokeLater(new Runnable() {
-            @Override
-            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() {
+                @Override
+                public void run() {
+                    updateProperties();
+                }
+            });
+        }
     }
 
     private synchronized void updateProperties() {
--- a/src/windows/classes/sun/awt/windows/WWindowPeer.java	Wed May 28 02:34:16 2014 -0700
+++ b/src/windows/classes/sun/awt/windows/WWindowPeer.java	Mon May 19 18:31:48 2014 +0400
@@ -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) {