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

NPE JFileChooser Windows L&F opening Windows folder

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10, Windows 10 pro, Windows 11

      A DESCRIPTION OF THE PROBLEM :
      Opening Windows folder with JFileChooser and com.sun.java.swing.plaf.windows.WindowsLookAndFeel causes a NullPointerException: Caused by: java.lang.NullPointerException: Cannot invoke "java.awt.Image.getWidth(java.awt.image.ImageObserver)" because "retVal" is null

      Probably somehow related with JDK-8293862, JDK-8320692.
      Problem does not occur with JDK 23.0.0.beta.11. so a backport might help.

      Problem was also reported by customers who used a network share to open files. But I was not able to reproduce that- definetely reproducible by opening the windows folder

      REGRESSION : Last worked in version 17.0.10

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Use windows Operating System (windows 10 or 11).
      Set Look and feel to "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"
      Create a Swing dialog that opens a JFileChooser.
      Navigate to Windows Folder.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Windows directory opens and all entries are shown
      ACTUAL -
      Windows folder is not opened, JFileChooser can not open any other directory afterwards. NPE is thrown:

      Exception in thread "AWT-EventQueue-0" 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/sun.swing.FilePane$FileRenderer.getListCellRendererComponent(FilePane.java:1635)
      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.paintImpl(BasicListUI.java:330)
      at java.desktop/javax.swing.plaf.basic.BasicListUI.paint(BasicListUI.java:306)
      at java.desktop/javax.swing.plaf.ComponentUI.update(ComponentUI.java:161)
      at java.desktop/javax.swing.JComponent.paintComponent(JComponent.java:852)
      at java.desktop/javax.swing.JComponent.paint(JComponent.java:1128)
      at java.desktop/javax.swing.JComponent.paintToOffscreen(JComponent.java:5318)
      at java.desktop/javax.swing.RepaintManager$PaintManager.paintDoubleBufferedImpl(RepaintManager.java:1656)
      at java.desktop/javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1631)
      at java.desktop/javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1569)
      at java.desktop/javax.swing.RepaintManager.paint(RepaintManager.java:1336)
      at java.desktop/javax.swing.JComponent._paintImmediately(JComponent.java:5266)
      at java.desktop/javax.swing.JComponent.paintImmediately(JComponent.java:5076)
      at java.desktop/javax.swing.RepaintManager$4.run(RepaintManager.java:878)
      at java.desktop/javax.swing.RepaintManager$4.run(RepaintManager.java:861)
      at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
      at java.desktop/javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:861)
      at java.desktop/javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:834)
      at java.desktop/javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:784)
      at java.desktop/javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1897)
      at java.desktop/java.awt.event.InvocationEvent.dispatch$$$capture(InvocationEvent.java:318)
      at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java)
      at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714)
      at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
      at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
      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.pumpEventsForFilter(EventDispatchThread.java:117)
      at java.desktop/java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:191)
      at java.desktop/java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:236)
      at java.desktop/java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:234)
      at java.base/java.security.AccessController.doPrivileged(AccessController.java:319)
      at java.desktop/java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:234)
      at java.desktop/java.awt.Dialog.show(Dialog.java:1079)
      at java.desktop/javax.swing.JFileChooser.showDialog(JFileChooser.java:771)
      at java.desktop/javax.swing.JFileChooser.showOpenDialog(JFileChooser.java:668)
      at org.example.JFileChooserBugDemo.showOpenFileDialog(JFileChooserBugDemo.java:34)
      at org.example.JFileChooserBugDemo.lambda$new$0(JFileChooserBugDemo.java:14)
      at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1972)
      at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2314)
      at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:407)
      at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
      at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
      at java.desktop/java.awt.Component.processMouseEvent(Component.java:6621)
      at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3398)
      at java.desktop/java.awt.Component.processEvent(Component.java:6386)
      at java.desktop/java.awt.Container.processEvent(Container.java:2266)
      at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4996)
      at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)
      at java.desktop/java.awt.Component.dispatchEvent(Component.java:4828)
      at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4948)
      at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4575)
      at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4516)
      at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2310)
      at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2780)
      at java.desktop/java.awt.Component.dispatchEvent(Component.java:4828)
      at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:775)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714)
      at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:98)
      at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:747)
      at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
      at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
      at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:744)
      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)
      Exception in thread "AWT-EventQueue-0" 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/sun.swing.FilePane$FileRenderer.getListCellRendererComponent(FilePane.java:1635)
      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.locationToIndex(BasicListUI.java:1009)
      at java.desktop/javax.swing.JList.locationToIndex(JList.java:1627)
      at java.desktop/javax.swing.JList.getToolTipText(JList.java:1562)
      at java.desktop/javax.swing.ToolTipManager$insideTimerAction.actionPerformed(ToolTipManager.java:693)
      at java.desktop/javax.swing.Timer.fireActionPerformed(Timer.java:311)
      at java.desktop/javax.swing.Timer$DoPostEvent.run(Timer.java:243)
      at java.desktop/java.awt.event.InvocationEvent.dispatch$$$capture(InvocationEvent.java:318)
      at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java)
      at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714)
      at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
      at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
      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.pumpEventsForFilter(EventDispatchThread.java:117)
      at java.desktop/java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:191)
      at java.desktop/java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:236)
      at java.desktop/java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:234)
      at java.base/java.security.AccessController.doPrivileged(AccessController.java:319)
      at java.desktop/java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:234)
      at java.desktop/java.awt.Dialog.show(Dialog.java:1079)
      at java.desktop/javax.swing.JFileChooser.showDialog(JFileChooser.java:771)
      at java.desktop/javax.swing.JFileChooser.showOpenDialog(JFileChooser.java:668)
      at org.example.JFileChooserBugDemo.showOpenFileDialog(JFileChooserBugDemo.java:34)
      at org.example.JFileChooserBugDemo.lambda$new$0(JFileChooserBugDemo.java:14)
      at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1972)
      at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2314)
      at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:407)
      at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
      at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
      at java.desktop/java.awt.Component.processMouseEvent(Component.java:6621)
      at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3398)
      at java.desktop/java.awt.Component.processEvent(Component.java:6386)
      at java.desktop/java.awt.Container.processEvent(Container.java:2266)
      at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4996)
      at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)
      at java.desktop/java.awt.Component.dispatchEvent(Component.java:4828)
      at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4948)
      at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4575)
      at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4516)
      at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2310)
      at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2780)
      at java.desktop/java.awt.Component.dispatchEvent(Component.java:4828)
      at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:775)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714)
      at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:98)
      at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:747)
      at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
      at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
      at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:744)
      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)

      ---------- BEGIN SOURCE ----------
      public class JFileChooserBugDemo extends JFrame {

          public JFileChooserBugDemo() {
              super("bug demo");
              setLayout(new FlowLayout());
              JButton buttonBrowse = new JButton("Browse...");

              buttonBrowse.addActionListener(arg0 -> showOpenFileDialog());

              getContentPane().add(buttonBrowse);
              setSize(300, 100);
              setLocationRelativeTo(null);
              setDefaultCloseOperation(EXIT_ON_CLOSE);
              setVisible(true);
          }

          public static void main(String[] args)
                  throws UnsupportedLookAndFeelException, ClassNotFoundException, InstantiationException,
                  IllegalAccessException {
              //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

              SwingUtilities.invokeLater(JFileChooserBugDemo::new);
          }

          private void showOpenFileDialog() {
              JFileChooser fileChooser = new JFileChooser();
              int result = fileChooser.showOpenDialog(this);

              if (result == JFileChooser.APPROVE_OPTION) {
                  File selectedFile = fileChooser.getSelectedFile();
                  System.out.println("Selected file: " + selectedFile.getAbsolutePath());
              }
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      user must copy necessary files to a different location. Might not be appropriate for all use cases.

      FREQUENCY : always


            aivanov Alexey Ivanov
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: