JDK-6945316 : The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows
  • CPU: generic
  • Submitted: 2010-04-20
  • Updated: 2011-03-07
  • Resolved: 2011-03-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7
6u21Fixed 7 b94Fixed
Related Reports
Relates :  
Description
The following NPE can be thrown:
Exception in thread "Thread-8" java.lang.NullPointerException
	at sun.awt.shell.Win32ShellFolderManager2.isFileSystemRoot(Win32ShellFolderManager2.java:406)
	at sun.awt.shell.ShellFolder.isFileSystemRoot(ShellFolder.java:269)

The problem is in the Win32ShellFolderManager2.isFileSystemRoot method. It contains the next code: "Arrays.asList(drives.listFiles())". At the same time drives.listFiles() returns null if current thread is interrupted and the Arrays.asList(null) throws NPE. Note that in that case common functionality is not broken, just the NPE is written in log.

The following test helps to catch the problem:

public class Main {
    public static void main(String[] args) throws Exception {
        if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
            System.out.println("The test is suitable only for Windows OS. Skipped.");

            return;
        }

        // Init toolkit because it shouldn't be interrupted while initialization
        Toolkit.getDefaultToolkit();

        // To get NPE the path must obey the following rules:
        // path.length() == 3 && path.charAt(1) == ':' 
        final File tempFile = new File("c:\\");

        Random random = new Random();

        for (int i = 0; i < 1000; i++) {
            final Thread thread = new Thread() {
                @Override
                public void run() {
                    while (!isInterrupted()) {
                        ShellFolder.isFileSystemRoot(tempFile);
                    }
                }
            };

            thread.start();

            // Give some time for the thread
            Thread.sleep(Math.abs(random.nextInt()) % 10 + 1);

            thread.interrupt();
        }
    }
}

Comments
EVALUATION The Win32ShellFolderManager2.isFileSystemRoot method should work if the listFiles() method returns null
20-04-2010