<Swing Dev> [9] Review request for JDK-8039383: NPE when changing Windows Theme

Alexey Ivanov alexey.ivanov at oracle.com
Fri Apr 18 08:09:32 UTC 2014

Hello Swing and AWT teams,

Could you please review the fix for jdk9:
     bug: https://bugs.openjdk.java.net/browse/JDK-8039383
     webrev: http://cr.openjdk.java.net/~dmarkov/8039383/jdk9/webrev.00/

Problem description:
When changing Windows themes from a theme with visual styles (Windows 
Aero or Windows Basic) to a classic one, NullPointerException could be 
thrown from Swing code during component tree validation, or 
InternalError could be thrown during component painting.

Root cause:
Windows theme data are "cached" in XPStyle object. When the theme is 
switched to a classic one, HTHEME handle becomes unavailable and data 
cannot be accessed from the theme any more. The change in theme in 
posted to EDT via invokeLater. At the same time, the UI needs to repaint 
itself as soon as Windows changed the theme, and paint code is often 
called before the theme change is handled in Java. This leads to NPE and 
InternalError as the code tries to access the data that has become 

The fix:
Update "win.xpstyle.themeActive" desktop property and invalidate the 
cached XPStyle as soon as windowsSettingChange() is called from native 
code. Thus when Swing code needs to access theme data, it will see no 
theme is available and will fallback to classic painting.

Note: Before the fix, PropertyChangeEvents for desktop properties in 
Windows were fired on the Event Dispatch Thread. With this change, 
property "win.xpstyle.themeActive" change is fired on the toolkit 
thread; all other properties are changed on the EDT as before.


More information about the swing-dev mailing list