Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6588271

NPE when changing 'Windows and buttons' style

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 6, 6u5, 7u51
    • Fix Version/s: 7-pool
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Introduced In Version:
      6
    • CPU:
      x86
    • OS:
      windows_xp, windows_vista, windows_7

      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 ----------

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              aivanov Alexey Ivanov
              Reporter:
              ryeung Roger Yeung (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: