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

JFileChooser throws a null exception in JDK 21 (works in 20)

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      Windows 11 Home

      java version "21" 2023-09-19 LTS
      Java(TM) SE Runtime Environment (build 21+35-LTS-2513)
      Java HotSpot(TM) 64-Bit Server VM (build 21+35-LTS-2513, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      1. Creating a JFileChooser throws a NullPointerException in Java 21
      ONLY when using the System Look and Feel.

      2. Works with the Cross Platform Look and Feel

      3. Switching to Java 20 and running the same code works with the System Look and Feel

      REGRESSION : Last worked in version 20

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      1. The Swing JFrame window should show

      2. Shows when run with Java 20
      ACTUAL -
      The JFrame window doesn't show and program terminates with the following trace


      Java version : 21
      Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.awt.Image.getWidth(java.awt.image.ImageObserver)" because "retVal" is null
              at java.desktop/sun.awt.shell.Win32ShellFolder2$MultiResolutionIconImage.getResolutionVariant(Win32ShellFolder2.java:1459)
              at java.desktop/sun.awt.shell.Win32ShellFolder2$MultiResolutionIconImage.getBaseImage(Win32ShellFolder2.java:1438)
              at java.desktop/java.awt.image.AbstractMultiResolutionImage.getProperty(AbstractMultiResolutionImage.java:140)
              at java.desktop/javax.swing.ImageIcon.<init>(ImageIcon.java:255)
              at java.desktop/javax.swing.ImageIcon.<init>(ImageIcon.java:241)
              at java.desktop/javax.swing.filechooser.FileSystemView.getSystemIcon(FileSystemView.java:252)
              at java.desktop/com.sun.java.swing.plaf.windows.WindowsFileChooserUI$WindowsFileView.getIcon(WindowsFileChooserUI.java:1352)
              at java.desktop/javax.swing.JFileChooser.getIcon(JFileChooser.java:1613)
              at java.desktop/com.sun.java.swing.plaf.windows.WindowsFileChooserUI$DirectoryComboBoxRenderer.getListCellRendererComponent(WindowsFileChooserUI.java:1047)
              at java.desktop/javax.swing.plaf.basic.BasicListUI.updateLayoutState(BasicListUI.java:1444)
              at java.desktop/javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(BasicListUI.java:1394)
              at java.desktop/javax.swing.plaf.basic.BasicListUI$Handler.valueChanged(BasicListUI.java:2815)
              at java.desktop/javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:231)
              at java.desktop/javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:206)
              at java.desktop/javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:258)
              at java.desktop/javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:459)
              at java.desktop/javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:469)
              at java.desktop/javax.swing.DefaultListSelectionModel.setSelectionInterval(DefaultListSelectionModel.java:513)
              at java.desktop/javax.swing.JList.setSelectedIndex(JList.java:2232)
              at java.desktop/javax.swing.plaf.basic.BasicComboPopup.setListSelection(BasicComboPopup.java:1281)
              at java.desktop/javax.swing.plaf.basic.BasicComboPopup$Handler.itemStateChanged(BasicComboPopup.java:1097)
              at java.desktop/javax.swing.JComboBox.fireItemStateChanged(JComboBox.java:1257)
              at java.desktop/javax.swing.JComboBox.selectedItemChanged(JComboBox.java:1318)
              at java.desktop/javax.swing.JComboBox.contentsChanged(JComboBox.java:1365)
              at java.desktop/javax.swing.AbstractListModel.fireContentsChanged(AbstractListModel.java:127)
              at java.desktop/com.sun.java.swing.plaf.windows.WindowsFileChooserUI$DirectoryComboBoxModel.setSelectedItem(WindowsFileChooserUI.java:1190)
              at java.desktop/com.sun.java.swing.plaf.windows.WindowsFileChooserUI$DirectoryComboBoxModel.addItem(WindowsFileChooserUI.java:1161)
              at java.desktop/com.sun.java.swing.plaf.windows.WindowsFileChooserUI.doDirectoryChanged(WindowsFileChooserUI.java:777)
              at java.desktop/com.sun.java.swing.plaf.windows.WindowsFileChooserUI$11.propertyChange(WindowsFileChooserUI.java:868)
              at java.desktop/java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:343)
              at java.desktop/java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:335)
              at java.desktop/java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:268)
              at java.desktop/java.awt.Component.firePropertyChange(Component.java:8717)
              at java.desktop/javax.swing.JFileChooser.setCurrentDirectory(JFileChooser.java:610)
              at java.desktop/javax.swing.JFileChooser.<init>(JFileChooser.java:364)
              at java.desktop/javax.swing.JFileChooser.<init>(JFileChooser.java:310)
              at TestSwing.main(TestSwing.java:35)

      ---------- BEGIN SOURCE ----------
      public class TestSwing {

          static JFileChooser fc = null;

          public static void main(String[] args) throws Exception {

              System.out.println("Java version : " + System.getProperty("java.version"));

              // Code works with cross platform look and feel
              UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

              JFrame frame = new JFrame();
              frame.setSize(new Dimension(400, 400));
              JPanel panel = new JPanel();
              JButton btn = new JButton("Show");
              
              fc = new JFileChooser();

              btn.addActionListener(e -> {
                  fc.showOpenDialog(frame);
              });

              panel.add(btn);
              frame.add(panel);
              frame.setVisible(true);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          }

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Not aware of a workaround

      FREQUENCY : always


        1. bug-report.mp4
          29.38 MB
        2. JDK8319082_ScreenRecording.zip
          4.90 MB
        3. TestSwing.java
          1.0 kB
        4. Windows_Build_versioin.png
          Windows_Build_versioin.png
          5 kB

            tr Tejesh R
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: