jdk/test/javax/swing/JFileChooser/6945316/bug6945316.java
author duke
Wed, 05 Jul 2017 17:52:05 +0200
changeset 10620 9df40a1578ef
parent 5506 202f599c92aa
child 31448 1066345d2a8a
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5448
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5448
diff changeset
     2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
5448
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
     4
 *
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
     7
 * published by the Free Software Foundation.
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
     8
 *
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    13
 * accompanied this code).
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    14
 *
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5448
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5448
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5448
diff changeset
    21
 * questions.
5448
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    22
 */
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    23
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    24
/* @test
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    25
   @bug 6945316
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    26
   @summary The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    27
   @author Pavel Porvatov
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    28
   @run main bug6945316
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    29
*/
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    30
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    31
import sun.awt.OSInfo;
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    32
import sun.awt.shell.ShellFolder;
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    33
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    34
import java.awt.*;
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    35
import java.io.File;
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    36
import java.util.concurrent.CountDownLatch;
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    37
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    38
public class bug6945316 {
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    39
    public static void main(String[] args) throws Exception {
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    40
        if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    41
            System.out.println("The test is suitable only for Windows OS. Skipped.");
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    42
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    43
            return;
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    44
        }
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    45
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    46
        // Init toolkit because it shouldn't be interrupted while initialization
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    47
        Toolkit.getDefaultToolkit();
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    48
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    49
        // Init the sun.awt.shell.Win32ShellFolderManager2.drives field
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    50
        ShellFolder.get("fileChooserComboBoxFolders");
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    51
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    52
        // To get NPE the path must obey the following rules:
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    53
        // path.length() == 3 && path.charAt(1) == ':'
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    54
        final File tempFile = new File("c:\\");
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    55
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    56
        for (int i = 0; i < 10000; i++) {
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    57
            final CountDownLatch countDownLatch = new CountDownLatch(1);
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    58
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    59
            final Thread thread = new Thread() {
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    60
                public void run() {
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    61
                    countDownLatch.countDown();
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    62
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    63
                    ShellFolder.isFileSystemRoot(tempFile);
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    64
                }
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    65
            };
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    66
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    67
            thread.start();
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    68
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    69
            countDownLatch.await();
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    70
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    71
            thread.interrupt();
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    72
        }
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    73
    }
96e9d2b5c719 6945316: The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
rupashka
parents:
diff changeset
    74
}