JDK-6588271 : NPE when changing 'Windows and buttons' style
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6,6u5,7u51
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • OS: windows_xp,windows_vista,windows_7
  • CPU: x86
  • Submitted: 2007-08-02
  • Updated: 2014-07-14
  • Resolved: 2014-07-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
JDK 7
7-poolResolved
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_02"
Java(TM) SE Runtime Environment (build 1.6.0_02-b06)
Java Hotspot(TM) Client VM (build 1.6.0_02-b06, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
One of the following exceptions is thrown when switching between 'Windows XP style' and 'Windows Classic style' in the Appearance pane of the Display Properties system control panel:
NullPointerException at com.sun.java.swing.plaf.windows.XPStyle$Skin.getWidth
InternalError: HTHEME is null (at sun.awt.windows.ThemeReader.paintBackground)

The NPE may occur from WindowsIconFactory$CheckBoxIcon.getIconWidth, WindowsScrollBarUI.paintThumb, WindowsBorders$ToolBarBorder.paintBorder, and possibly other places.

The InternalError comes from XPStyle$SkinPainter.paintToImage via
WindowsToolBarUI.paint or WindowsButtonUI.paintXPButtonBackground:
java.lang.InternalError: HTHEME is null
	at sun.awt.windows.ThemeReader.paintBackground(Native Method)
	at sun.awt.windows.ThemeReader.paintBackground(Unknown Source)
	at com.sun.java.swing.plaf.windows.XPStyle$SkinPainter.paintToImage(Unknown Source)
	at sun.swing.CachedPainter.paint0(Unknown Source)
	at sun.swing.CachedPainter.paint(Unknown Source)

This bug may be related to 6470308 and/or 6194328, but is reproducible in Java 6 Update 2.
Although I have provided a reproducible case that involves changing Appearance settings in the Display Properties control panel, I have received many reports from customers who ran into this bug without knowingly making any such changes in their Display Properties.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Open Windows 'Display Properties' control panel in Windows XP.
Choose the 'Windows XP' theme.
Click 'Apply'.

Run the attached test case:
java ErrorTest scrollpane

Open Windows 'Display Properties' control panel in Windows XP.
in the 'Appearance' tab, change the 'Windows and buttons' setting to 'Windows Classic style'
Click 'Apply'.

An error should occur immediately, but it sometimes does not occur the first time the style is changed.  If needed, continue changing the style back and forth between 'Windows XP Style' and 'Windows Classic Style' until the error occurs.

The attached ErrorTest program takes a single argument to indicate which UI component to test:
scrollpane
scrollbar
table
toolbar
checkbox

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No exception when changing Theme settings.
ACTUAL -
Either an NPE or InternalError when changing Theme settings.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Here are some sample stack traces.  I have many more available.

java.lang.NullPointerException
	at com.sun.java.swing.plaf.windows.XPStyle$Skin.getWidth(Unknown Source)
	at com.sun.java.swing.plaf.windows.XPStyle$Skin.getWidth(Unknown Source)
	at com.sun.java.swing.plaf.windows.WindowsIconFactory$CheckBoxIcon.getIconWidth(Unknown Source)
	at javax.swing.SwingUtilities.layoutCompoundLabelImpl(Unknown Source)
	at javax.swing.SwingUtilities.layoutCompoundLabel(Unknown Source)
	at javax.swing.plaf.basic.BasicRadioButtonUI.paint(Unknown Source)
	at javax.swing.plaf.ComponentUI.update(Unknown Source)
	at javax.swing.JComponent.paintComponent(Unknown Source)

java.lang.NullPointerException
	at com.sun.java.swing.plaf.windows.XPStyle$Skin.getWidth(Unknown Source)
	at com.sun.java.swing.plaf.windows.XPStyle$Skin.getWidth(Unknown Source)
	at com.sun.java.swing.plaf.windows.WindowsToolBarSeparatorUI.paint(Unknown Source)
	at javax.swing.plaf.ComponentUI.update(Unknown Source)
	at javax.swing.JComponent.paintComponent(Unknown Source)

java.lang.NullPointerException
	at com.sun.java.swing.plaf.windows.XPStyle$Skin.getWidth(Unknown Source)
	at com.sun.java.swing.plaf.windows.XPStyle$Skin.getWidth(Unknown Source)
	at com.sun.java.swing.plaf.windows.WindowsScrollBarUI.paintThumb(Unknown Source)
	at javax.swing.plaf.basic.BasicScrollBarUI.paint(Unknown Source)
	at javax.swing.plaf.ComponentUI.update(Unknown Source)
	at javax.swing.JComponent.paintComponent(Unknown Source)

java.lang.InternalError: HTHEME is null
	at sun.awt.windows.ThemeReader.paintBackground(Native Method)
	at sun.awt.windows.ThemeReader.paintBackground(Unknown Source)
	at com.sun.java.swing.plaf.windows.XPStyle$SkinPainter.paintToImage(Unknown Source)
	at sun.swing.CachedPainter.paint0(Unknown Source)
	at sun.swing.CachedPainter.paint(Unknown Source)
	at com.sun.java.swing.plaf.windows.XPStyle$Skin.paintSkin(Unknown Source)
	at com.sun.java.swing.plaf.windows.XPStyle$Skin.paintSkin(Unknown Source)
	at com.sun.java.swing.plaf.windows.WindowsIconFactory$CheckBoxIcon.paintIcon(Unknown Source)

java.lang.InternalError: HTHEME is null
	at sun.awt.windows.ThemeReader.paintBackground(Native Method)
	at sun.awt.windows.ThemeReader.paintBackground(Unknown Source)
	at com.sun.java.swing.plaf.windows.XPStyle$SkinPainter.paintToImage(Unknown Source)
	at sun.swing.CachedPainter.paint0(Unknown Source)
	at sun.swing.CachedPainter.paint(Unknown Source)
	at com.sun.java.swing.plaf.windows.XPStyle$Skin.paintSkinRaw(Unknown Source)
	at com.sun.java.swing.plaf.windows.XPStyle$Skin.paintSkin(Unknown Source)
	at com.sun.java.swing.plaf.windows.WindowsButtonUI.paintXPButtonBackground(Unknown Source)
	at com.sun.java.swing.plaf.windows.WindowsButtonUI.paint(Unknown Source)
	at javax.swing.plaf.ComponentUI.update(Unknown Source)
	at javax.swing.JComponent.paintComponent(Unknown Source)


REPRODUCIBILITY :
This bug can be reproduced often.

---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import javax.swing.*;

public class ErrorTest
{
	public static void main( String[] args )
	{
		if ( (args == null) || (args.length == 0) ) {
			args = new String[] { "table" };
		}
		try {
			//Setting look and feel...
			javax.swing.UIManager.setLookAndFeel( javax.swing.UIManager.getSystemLookAndFeelClassName() );
		} catch (Throwable exc ) {
			exc.printStackTrace();
		}
		
		JFrame frame = new JFrame( "XPStyle/HTHEME test" );
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		JPanel contentPane = new JPanel( new BorderLayout( 5, 5 ) );
		
		String testType = args[0];
		if ( "scrollbar".equalsIgnoreCase( testType ) ) {
			 //	--- naked JScrollBar test ---
			 
			//It may be harder to reproduce the error with this naked scrollbar,
			//	than it does when using a JScrollPane.
			
			contentPane.add( new JScrollBar( JScrollBar.HORIZONTAL, 50, 10, 0, 100 ), BorderLayout.NORTH );
			contentPane.add( Box.createGlue(), BorderLayout.CENTER );
		} else if ( "scrollpane".equals( testType ) ) {
			 //	--- JScrollPane test ---
			 
			contentPane.add( new JScrollPane( Box.createRigidArea( new java.awt.Dimension( 800, 800 ) ) ), BorderLayout.CENTER );
		} else if ( "toolbar".equalsIgnoreCase( testType ) ) {
			//	--- JToolBar test ---
			
			JToolBar toolbar = new JToolBar();
			for ( int i = 0; i < 5; i++ ) {
				toolbar.add( new JButton( String.valueOf(i) ) );
				toolbar.addSeparator();
			}
			contentPane.add( toolbar, BorderLayout.NORTH );
			contentPane.add( Box.createGlue(), BorderLayout.CENTER );
		} else if ( "table".equalsIgnoreCase( testType ) ) {
			//	--- JTable in JScrollPane test ---
			 
			// Create columns names
			String columns[] = { " A ", "Column 2", "Third" };
			
			// Create some data
			String data[][] = new String[ 25 ][];
			for ( int i = 0; i < data.length; i++ ) {
				data[i] = new String[ columns.length ];
				for ( int j = 0; j < columns.length; j++ ) {
					data[i][j] = String.valueOf( Math.random() * 100 );
				}
			}
			JTable table = new JTable( new javax.swing.table.DefaultTableModel( data, columns ) );
			contentPane.add( new JScrollPane( table ), BorderLayout.CENTER );
		} else if ( "checkbox".equalsIgnoreCase( testType ) ) {
			//	--- JCheckBox test ---
			
			//Sometimes this test displays the error the first time you change the 'Windows and Buttons' style.
			//	Other times, it takes several changes to cause it.
			
			contentPane.setLayout( new BoxLayout( contentPane, BoxLayout.Y_AXIS ) );
			
			for ( int i = 0; i < 25; i++ ) {
				contentPane.add( new JCheckBox( "Checkbox " + i, (Math.random() > 0.5d) ) );
				contentPane.add( Box.createVerticalStrut( 4 ) );
			}
		} else {
			System.out.println( "Please specify one of:" );
			System.out.println( "scrollpane" );
			System.out.println( "toolbar" );
			System.out.println( "table" );
			System.out.println( "checkbox" );
		}
		
		frame.setContentPane( contentPane );
		
		frame.setSize( 400, 400 );
		frame.setVisible( true );
	}
}

---------- END SOURCE ----------

Comments
The same issue has been addressed under JDK-8046559 for jdk 9/8/7. See also JDK-8039383. There are no plans to fix it in jdk 6 at this time.
2014-07-14

CAP member can still experience this problem on JDK 8u5.
2014-06-10

PUBLIC COMMENTS Reproducible on jdk1.6.0_21b05 as well
2010-06-24