JDK-8180458 : NPE at Win32ShellFolderManager2.createShellFolder
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 8u131,9
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_10
  • CPU: x86
  • Submitted: 2017-05-14
  • Updated: 2019-08-02
  • Resolved: 2017-05-17
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [version 10.0.15063]

A DESCRIPTION OF THE PROBLEM :
This is an upstream bug for:
https://josm.openstreetmap.de/ticket/14795

As per quality outreach please add label "josm-found" to this bug report.

On Windows 10, a JFileChooser can fails to be initialized with the following stacktrace:

java.lang.NullPointerException
	at sun.awt.shell.Win32ShellFolderManager2.createShellFolder(Unknown Source)
	at sun.awt.shell.Win32ShellFolderManager2.getRecent(Unknown Source)
	at sun.awt.shell.Win32ShellFolderManager2.get(Unknown Source)
	at sun.awt.shell.ShellFolder.get(Unknown Source)
	at sun.swing.WindowsPlacesBar.<init>(Unknown Source)
	at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.updateUseShellFolder(Unknown Source)
	at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.installComponents(Unknown Source)
	at javax.swing.plaf.basic.BasicFileChooserUI.installUI(Unknown Source)
	at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.installUI(Unknown Source)
	at javax.swing.JComponent.setUI(Unknown Source)
	at javax.swing.JFileChooser.updateUI(Unknown Source)
	at javax.swing.JFileChooser.setup(Unknown Source)
	at javax.swing.JFileChooser.<init>(Unknown Source)
	at javax.swing.JFileChooser.<init>(Unknown Source)

Looking at the source code it seems the most plausible explanation is that an exception occurs in Win32ShellFolderManager2.getDesktop but is silently ignored. Thus getDesktop() returns null:

    static Win32ShellFolder2 getDesktop() {
        if (desktop == null) {
            try {
                desktop = new Win32ShellFolder2(DESKTOP);
            } catch (SecurityException e) {
                // Ignore error
            } catch (IOException e) {
                // Ignore error
            } catch (InterruptedException e) {
                // Ignore error
            }
        }
        return desktop;
    }

And the NPE occurs because of parent (desktop) is null:

    static Win32ShellFolder2 createShellFolder(Win32ShellFolder2 parent, File file)
            throws FileNotFoundException, InterruptedException {
        long pIDL;
        try {
            pIDL = parent.parseDisplayName(file.getCanonicalPath());
        } catch (IOException ex) {
            pIDL = 0;
        }
        if (pIDL == 0) {
            // Shouldn't happen but watch for it anyway
            throw new FileNotFoundException("File " + file.getAbsolutePath() + " not found");
        }

        try {
            return createShellFolderFromRelativePIDL(parent, pIDL);
        } finally {
            Win32ShellFolder2.releasePIDL(pIDL);
        }
    }


ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NullPointerException
	at sun.awt.shell.Win32ShellFolderManager2.createShellFolder(Unknown Source)
	at sun.awt.shell.Win32ShellFolderManager2.getRecent(Unknown Source)
	at sun.awt.shell.Win32ShellFolderManager2.get(Unknown Source)
	at sun.awt.shell.ShellFolder.get(Unknown Source)
	at sun.swing.WindowsPlacesBar.<init>(Unknown Source)
	at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.updateUseShellFolder(Unknown Source)
	at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.installComponents(Unknown Source)
	at javax.swing.plaf.basic.BasicFileChooserUI.installUI(Unknown Source)
	at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.installUI(Unknown Source)
	at javax.swing.JComponent.setUI(Unknown Source)
	at javax.swing.JFileChooser.updateUI(Unknown Source)
	at javax.swing.JFileChooser.setup(Unknown Source)
	at javax.swing.JFileChooser.<init>(Unknown Source)
	at javax.swing.JFileChooser.<init>(Unknown Source)

REPRODUCIBILITY :
This bug can be reproduced rarely.


Comments
Closing this as duplicate of JDK-8179014
17-05-2017

Submitter informed that the bug has been reported by an anonymous user and he use JOSM daily on Windows 10 creators update with Windows L&F without any issue. The issue is likely fixed in 8179014.
17-05-2017

From the stack trace it seems to be a duplicate of JDK-8179014. However, written back to the submitter requesting additional information.
17-05-2017