--- old/src/windows/classes/sun/awt/windows/WToolkit.java 2014-07-10 18:20:01.933945100 +0400 +++ new/src/windows/classes/sun/awt/windows/WToolkit.java 2014-07-10 18:20:01.325867800 +0400 @@ -36,6 +36,7 @@ import java.beans.PropertyChangeListener; import java.security.AccessController; import java.security.PrivilegedAction; +import sun.awt.AppContext; import sun.awt.AWTAutoShutdown; import sun.awt.AppContext; import sun.awt.SunToolkit; @@ -70,6 +71,9 @@ private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.windows.WToolkit"); + // Desktop property which specifies whether XP visual styles are in effect + public static final String XPSTYLE_THEME_ACTIVE = "win.xpstyle.themeActive"; + static GraphicsConfiguration config; // System clipboard. @@ -829,7 +833,7 @@ private synchronized void lazilyInitWProps() { if (wprops == null) { wprops = new WDesktopProperties(this); - updateProperties(); + updateProperties(wprops.getProperties()); } } @@ -864,21 +868,41 @@ * Windows doesn't always send WM_SETTINGCHANGE when it should. */ private void windowsSettingChange() { - EventQueue.invokeLater(new Runnable() { - @Override - public void run() { - updateProperties(); - } - }); + // JDK-8039383: Have to update the value of XPSTYLE_THEME_ACTIVE property + // as soon as possible to prevent NPE and other errors because theme data + // has become unavailable. + final Map props = getWProps(); + if (props == null) { + // props has not been initialized, so we have nothing to update + return; + } + + updateXPStyleEnabled(props.get(XPSTYLE_THEME_ACTIVE)); + + if (AppContext.getAppContext() == null) { + // We cannot post the update to any EventQueue. Listeners will + // be called on EDTs by DesktopPropertyChangeSupport + updateProperties(props); + } else { + // Cannot update on Toolkit thread. + // DesktopPropertyChangeSupport will call listeners on Toolkit + // thread if it has AppContext (standalone mode) + EventQueue.invokeLater(new Runnable() { + @Override + public void run() { + updateProperties(props); + } + }); + } } - private synchronized void updateProperties() { - if (null == wprops) { - // wprops has not been initialized, so we have nothing to update + private synchronized void updateProperties(final Map props) { + if (null == props) { return; } - Map props = wprops.getProperties(); + updateXPStyleEnabled(props.get(XPSTYLE_THEME_ACTIVE)); + for (String propName : props.keySet()) { Object val = props.get(propName); if (log.isLoggable(PlatformLogger.FINER)) { @@ -1007,6 +1031,14 @@ private native synchronized int getNumberOfButtonsImpl(); + private synchronized Map getWProps() { + return (wprops != null) ? wprops.getProperties() : null; + } + + private void updateXPStyleEnabled(final Object dskProp) { + ThemeReader.xpStyleEnabled = Boolean.TRUE.equals(dskProp); + } + @Override public int getNumberOfButtons(){ if (numberOfButtons == 0) {