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

The Win32ShellFolderManager2.isFileSystemRoot can throw NPE

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 7
    • Fix Version/s: 7
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b94
    • CPU:
      generic
    • OS:
      windows
    • Verification:
      Verified

      Backports

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

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: