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

REGRESSION: Disabled JMenuitem with an empty imageicon will crash.

XMLWordPrintable

      A DESCRIPTION OF THE REGRESSION :
      JDK: Mustang b75
      OS:Windows Professional SP1+
      When set a disabled JMenuitem's icon property to an imageicon constructed with new ImageIcon("") will cause an exception.
      Stack Trace:
      Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Width
       (-1) and height (-1) cannot be <= 0
              at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Direct
      ColorModel.java:999)
              at java.awt.image.BufferedImage.<init>(BufferedImage.java:321)
              at com.sun.java.swing.plaf.windows.WindowsLookAndFeel.getDisabledIcon(Wi
      ndowsLookAndFeel.java:2336)
              at javax.swing.AbstractButton.getDisabledIcon(AbstractButton.java:633)
              at javax.swing.plaf.basic.BasicMenuItemUI.paintMenuItem(BasicMenuItemUI.
      java:620)
              at javax.swing.plaf.basic.BasicMenuItemUI.paint(BasicMenuItemUI.java:533
      )
              at javax.swing.plaf.basic.BasicMenuItemUI.update(BasicMenuItemUI.java:52
      9)
              at javax.swing.JComponent.paintComponent(JComponent.java:703)
              at javax.swing.JComponent.paint(JComponent.java:967)
              at javax.swing.JComponent.paintChildren(JComponent.java:804)
              at javax.swing.JComponent.paint(JComponent.java:976)
              at javax.swing.JComponent.paintChildren(JComponent.java:804)
              at javax.swing.JComponent.paint(JComponent.java:976)
              at javax.swing.JComponent.paintChildren(JComponent.java:804)
              at javax.swing.JComponent.paint(JComponent.java:976)
              at javax.swing.JLayeredPane.paint(JLayeredPane.java:559)
              at javax.swing.JComponent.paintChildren(JComponent.java:804)
              at javax.swing.JComponent.paint(JComponent.java:976)
              at javax.swing.JComponent.paintToOffscreen(JComponent.java:5076)
              at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManag
      er.java:279)
              at javax.swing.RepaintManager.paint(RepaintManager.java:1105)
              at javax.swing.JComponent._paintImmediately(JComponent.java:5024)
              at javax.swing.JComponent.paintImmediately(JComponent.java:4842)
              at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)

              at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:670)

              at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:6
      50)
              at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(System
      EventQueueUtilities.java:128)
              at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
              at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
              at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
      ad.java:273)
              at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
      java:183)
              at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
      ad.java:173)
              at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)

              at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)

              at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)


      REPRODUCIBLE TESTCASE OR STEPS TO REPRODUCE:
      package testbug;

      import java.awt.BorderLayout;
      import java.awt.Dimension;

      import javax.swing.ImageIcon;
      import javax.swing.JFrame;
      import javax.swing.JMenu;
      import javax.swing.JMenuBar;
      import javax.swing.JMenuItem;
      import javax.swing.JPanel;
      import javax.swing.UIManager;


      public class TestDisabledIcon extends JFrame{

          private JPanel jPanel1 = new JPanel();
          private BorderLayout borderLayout1 = new BorderLayout();
          private JMenuBar jMenuBar1 = new JMenuBar();
          private JMenu jMenu1 = new JMenu();
          private JMenuItem jMenuItem2 = new JMenuItem();
          private ImageIcon icon = new ImageIcon("");


          public TestDisabledIcon() {
              try {
                  jbInit();
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }

          private void jbInit() throws Exception {
              this.setSize(new Dimension(400, 343));
              this.setJMenuBar(jMenuBar1);
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              jPanel1.setLayout(borderLayout1);
              jMenu1.setText("Click Me");
              jMenuItem2.setText("Error");
              jMenuItem2.setEnabled(false);
              jMenuItem2.setIcon(icon);
              this.getContentPane().add(jPanel1, null);
              jMenu1.add(jMenuItem2);
              jMenuBar1.add(jMenu1);
          }
          
          public static void main(String[] argv){
              try {
                  UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                  TestDisabledIcon dlg = new TestDisabledIcon();
                  dlg.setVisible(true);
                  
              } catch (Exception e) {
              }
          }
      }


      RELEASE LAST WORKED:
      5.0 Update 6

      RELEASE TEST FAILS:
      mustang-beta

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No exception , because sometimes we use new ImageIcon("") as the default
      ACTUAL -
      An exception is throwed and the menu is not drawed.

      Release Regression From : 5.0u6
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.

            shickeysunw Shannon Hickey (Inactive)
            dbessono Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: