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

The Win32ShellFolderManager2.isFileSystemRoot can throw NPE

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 7
    • 7
    • client-libs
    • b94
    • generic
    • windows
    • Verified

        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();
                }
            }
        }

              rupashka Pavel Porvatov (Inactive)
              rupashka Pavel Porvatov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: