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

Null icon returned for .exe without custom icon

XMLWordPrintable

    • b07
    • 21
    • b07
    • x86_64
    • windows

        A DESCRIPTION OF THE PROBLEM :
        The Open file dialog hangs when selecting a folder that contains .exe files with the default Windows exe icon.

        Someone has already reported this bug (https://bugs.java.com/bugdatabase/view_bug?bug_id=8297529​), and it was marked as resolved. However, when I download the latest JDK version (jdk 21.0.1), the issue still persists. The root cause is that the 'newIcon' variable becomes null in the 'getIcon' function of the 'Win32ShellFolder2.class.'

        The NullPointerException occurs as follows:

        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.paintDoubleBufferedFPScales(RepaintManager.java:1720)
        at java.desktop/javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1629)
        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(InvocationEvent.java:318)
        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 demo.showOpenFileDialog(demo.java:90)
        at demo.access$0(demo.java:51)
        at demo$1.actionPerformed(demo.java:28)
        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)

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1. Open the Open file dialog.
        2. Navigate to a folder containing .exe files with the default Windows exe icon.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The Open file dialog should not hang, and all files in the specified folder should load and be selectable within the dialog.
        ACTUAL -
        Throws NullPointerException

        ---------- BEGIN SOURCE ----------
        import java.awt.FlowLayout;
        import java.awt.event.ActionEvent;
        import java.awt.event.ActionListener;
        import java.io.File;
        import javax.swing.JButton;
        import javax.swing.JFileChooser;
        import javax.swing.JFrame;
        import javax.swing.SwingUtilities;
        import javax.swing.UIManager;
        import javax.swing.filechooser.FileNameExtensionFilter;

        public class demo extends JFrame {

        private JButton buttonBrowse;

            public demo() {
                super("Demo File Type Filter");
                setLayout(new FlowLayout());
                buttonBrowse = new JButton("Browse...");
         
                buttonBrowse.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent arg0) {
                        showOpenFileDialog();
                    }
                });
         
                getContentPane().add(buttonBrowse);
                setSize(300, 100);
                setLocationRelativeTo(null);
                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                setVisible(true);
            }
         
            public static void main(String[] args) {
                try {
                 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (Exception e) { }
         
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        new demo();
                    }
                });
            }
         
            private void showOpenFileDialog() {
            // Contain some exe files with the default Windows exe icon
             File fileTest = new File("D:/Downloads/Test");
            
                JFileChooser fileChooser = new JFileChooser();
                fileChooser.setCurrentDirectory(fileTest);
                fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
         
                fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("EXE File","exe"));

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

              kizune Alexander Zuev
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              10 Start watching this issue

                Created:
                Updated:
                Resolved: