# HG changeset patch # User pchelko # Date 1405347376 -14400 # Node ID 42af94daa9dc484f1cda7290e2032c5abc5d1488 # Parent 5f7926fa7380594acd3411e9a82deecc6c878028 8042590: Running form URL throws NPE Reviewed-by: anthony, serb diff -r 5f7926fa7380 -r 42af94daa9dc jdk/src/windows/classes/sun/awt/windows/ThemeReader.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) { diff -r 5f7926fa7380 -r 42af94daa9dc jdk/src/windows/classes/sun/awt/windows/WToolkit.java --- 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() {