United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6945316 The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
JDK-6945316 : The Win32ShellFolderManager2.isFileSystemRoot can throw NPE

Details
Type:
Bug
Submit Date:
2010-04-20
Status:
Closed
Updated Date:
2011-03-07
Project Name:
JDK
Resolved Date:
2011-03-07
Component:
client-libs
OS:
windows
Sub-Component:
javax.swing
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:
Relates:

Sub Tasks

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
                                     
2010-04-20



Hardware and Software, Engineered to Work Together