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

Selecting a JComboBox using the cross-platform LAF causes a NullPointerException

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      macOS 10.15.4, JDK 15 EAB 21

      A DESCRIPTION OF THE PROBLEM :
      When I use the cross-platform LAF (Look and Feel) and select a JComboBox displayed using a Frame, a NullPointerException is thrown. This does not occur when I do not set the LAF. Here is the stack trace:

      Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
      at java.desktop/com.apple.laf.AquaMenuPainter.paintSelectedMenuItemBackground(AquaMenuPainter.java:157)
      at java.desktop/com.apple.laf.AquaComboBoxRendererInternal.paintComponent(AquaComboBoxRendererInternal.java:147)
      at java.desktop/javax.swing.JComponent.paint(JComponent.java:1074)
      at java.desktop/javax.swing.CellRendererPane.paintComponent(CellRendererPane.java:165)
      at java.desktop/javax.swing.plaf.basic.BasicListUI.paintCell(BasicListUI.java:288)
      at java.desktop/javax.swing.plaf.basic.BasicListUI.paintImpl(BasicListUI.java:378)
      at java.desktop/javax.swing.plaf.basic.BasicListUI.paint(BasicListUI.java:301)
      at java.desktop/javax.swing.plaf.ComponentUI.update(ComponentUI.java:161)
      at java.desktop/javax.swing.JComponent.paintComponent(JComponent.java:797)
      at java.desktop/javax.swing.JComponent.paint(JComponent.java:1074)
      at java.desktop/javax.swing.JComponent.paintChildren(JComponent.java:907)
      at java.desktop/javax.swing.JComponent.paint(JComponent.java:1083)
      at java.desktop/javax.swing.JViewport.paint(JViewport.java:737)
      at java.desktop/javax.swing.JComponent.paintChildren(JComponent.java:907)
      at java.desktop/javax.swing.JComponent.paint(JComponent.java:1083)
      at java.desktop/javax.swing.JComponent.paintChildren(JComponent.java:907)
      at java.desktop/javax.swing.JComponent.paint(JComponent.java:1083)
      at java.desktop/javax.swing.JComponent.paintChildren(JComponent.java:907)
      at java.desktop/javax.swing.JComponent.paint(JComponent.java:1083)
      at java.desktop/javax.swing.JComponent.paintChildren(JComponent.java:907)
      at java.desktop/javax.swing.JComponent.paint(JComponent.java:1083)
      at java.desktop/javax.swing.JLayeredPane.paint(JLayeredPane.java:586)
      at java.desktop/javax.swing.JComponent.paintChildren(JComponent.java:907)
      at java.desktop/javax.swing.JComponent.paintToOffscreen(JComponent.java:5262)
      at java.desktop/javax.swing.RepaintManager$PaintManager.paintDoubleBufferedImpl(RepaintManager.java:1643)
      at java.desktop/javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1618)
      at java.desktop/javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1556)
      at java.desktop/javax.swing.RepaintManager.paint(RepaintManager.java:1323)
      at java.desktop/javax.swing.JComponent.paint(JComponent.java:1060)
      at java.desktop/java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:39)
      at java.desktop/sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:75)
      at java.desktop/sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:112)
      at java.desktop/java.awt.Container.paint(Container.java:2002)
      at java.desktop/java.awt.Window.paint(Window.java:3928)
      at java.desktop/javax.swing.RepaintManager$4.run(RepaintManager.java:876)
      at java.desktop/javax.swing.RepaintManager$4.run(RepaintManager.java:848)
      at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
      at java.desktop/javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:848)
      at java.desktop/javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:823)
      at java.desktop/javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:772)
      at java.desktop/javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1884)
      at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:316)
      at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
      at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
      at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
      at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
      at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
      at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
      at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
      at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
      at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Compile and run the source code given
      2. Click on the JComboBox on the form
      3. A NullPointerException is thrown and the list of items of the combo box are blank (like a gray rectangle)

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expect the cross-platform LAF to behave like the default, and display the items of the combo box when I click on it.
      ACTUAL -
      A NullPointerException is thrown and the list of items of the combo box are blank. When I attempt to click on the combo box again, the items do appear, but additional NullPointerExceptions are thrown.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;

      public class Bar {
          public static void main(String[] args) {
              JComboBox<String> comboBox = new JComboBox<>();
              JPanel panel = new JPanel();
              JFrame frame = new JFrame();

              try {
                  UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
              } catch (Exception e) {
                  e.printStackTrace();

                  return;
              } //end try catch

              comboBox.addItem("Foo");

              comboBox.addItem("Bar");

              comboBox.addItem("Baz");

              panel.add(comboBox);

              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

              frame.setLocationRelativeTo(null);

              frame.setContentPane(panel);

              frame.pack();

              frame.setVisible(true);
          } //main
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      If I do not set the LAF of the form, the error does not occur.

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                psadhukhan Prasanta Sadhukhan
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: