changeset 9821:4626083470a2

8039097: Some tests fail with NPE since 7u60 b12 Reviewed-by: serb, alexsch
author pchelko
date Mon, 07 Apr 2014 15:34:22 +0400
parents e1481cf280ca
children af8da6fc2176
files src/share/classes/java/awt/Toolkit.java src/windows/classes/sun/awt/windows/WToolkit.java
diffstat 2 files changed, 25 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/awt/Toolkit.java	Sun Apr 06 23:53:37 2014 +0200
+++ b/src/share/classes/java/awt/Toolkit.java	Mon Apr 07 15:34:22 2014 +0400
@@ -2557,23 +2557,30 @@
         public void firePropertyChange(final PropertyChangeEvent evt) {
             Object oldValue = evt.getOldValue();
             Object newValue = evt.getNewValue();
+            String propertyName = evt.getPropertyName();
             if (oldValue != null && newValue != null && oldValue.equals(newValue)) {
                 return;
             }
+            Runnable updater = new Runnable() {
+                public void run() {
+                    PropertyChangeSupport pcs = (PropertyChangeSupport)
+                            AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
+                    if (null != pcs) {
+                        pcs.firePropertyChange(evt);
+                    }
+                }
+            };
+            final AppContext currentAppContext = AppContext.getAppContext();
             for (AppContext appContext : AppContext.getAppContexts()) {
                 if (null == appContext || appContext.isDisposed()) {
                     continue;
                 }
-                final PeerEvent e = new PeerEvent(source,
-                        () -> {
-                            PropertyChangeSupport pcs = (PropertyChangeSupport)
-                                    AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
-                            if (null != pcs) {
-                                pcs.firePropertyChange(evt);
-                            }
-                        },
-                        PeerEvent.ULTIMATE_PRIORITY_EVENT);
-                SunToolkit.postEvent(appContext, e);
+                if (currentAppContext == appContext) {
+                    updater.run();
+                } else {
+                    final PeerEvent e = new PeerEvent(source, updater, PeerEvent.ULTIMATE_PRIORITY_EVENT);
+                    SunToolkit.postEvent(appContext, e);
+                }
             }
         }
     }
--- a/src/windows/classes/sun/awt/windows/WToolkit.java	Sun Apr 06 23:53:37 2014 +0200
+++ b/src/windows/classes/sun/awt/windows/WToolkit.java	Mon Apr 07 15:34:22 2014 +0400
@@ -38,6 +38,7 @@
 import java.security.PrivilegedAction;
 import sun.awt.AWTAutoShutdown;
 import sun.awt.LightweightFrame;
+import sun.awt.AppContext;
 import sun.awt.SunToolkit;
 import sun.misc.ThreadGroupUtils;
 import sun.awt.Win32GraphicsDevice;
@@ -866,7 +867,13 @@
      * Windows doesn't always send WM_SETTINGCHANGE when it should.
      */
     private void windowsSettingChange() {
-        updateProperties();
+        if (AppContext.getAppContext() == null) {
+            // No AppContext, so we can update properties on the current thread,
+            // DesktopPropertyChangeSupport will only post events.
+            updateProperties();
+        } else {
+            EventQueue.invokeLater(this::updateProperties);
+        }
     }
 
     private synchronized void updateProperties() {