jdk/test/javax/swing/JFileChooser/6741890/bug6741890.java
author rupashka
Fri, 30 Oct 2009 14:05:48 +0300
changeset 4273 19adfe928d6c
parent 4269 0283fbab043c
child 5506 202f599c92aa
permissions -rw-r--r--
6894504: javax/swing/JFileChooser/6741890/bug6741890.java fails w/ RuntimeException Reviewed-by: malenkov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4269
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
     1
/*
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
     2
 * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
     4
 *
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
     8
 *
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    13
 * accompanied this code).
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    14
 *
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    18
 *
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    21
 * have any questions.
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    22
 */
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    23
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    24
/* @test
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    25
   @bug 6741890
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    26
   @summary Deadlock in Win32ShellFolderManager2
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    27
   @author Pavel Porvatov
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    28
   @run main bug6741890
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    29
*/
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    30
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    31
import sun.awt.shell.ShellFolder;
4273
19adfe928d6c 6894504: javax/swing/JFileChooser/6741890/bug6741890.java fails w/ RuntimeException
rupashka
parents: 4269
diff changeset
    32
import sun.awt.OSInfo;
4269
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    33
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    34
import java.io.File;
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    35
import java.lang.reflect.Field;
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    36
import java.util.concurrent.Callable;
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    37
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    38
public class bug6741890 {
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    39
    /**
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    40
     * This mux is used to prevent NPE in the isLink and isFileSystem methods
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    41
     */
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    42
    private static final Object mux = new Object();
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    43
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    44
    private static final int COUNT = 100000;
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    45
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    46
    public static void main(String[] args) throws Exception {
4273
19adfe928d6c 6894504: javax/swing/JFileChooser/6741890/bug6741890.java fails w/ RuntimeException
rupashka
parents: 4269
diff changeset
    47
        if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
19adfe928d6c 6894504: javax/swing/JFileChooser/6741890/bug6741890.java fails w/ RuntimeException
rupashka
parents: 4269
diff changeset
    48
            System.out.println("The test is applicable only for Windows. Skipped.");
19adfe928d6c 6894504: javax/swing/JFileChooser/6741890/bug6741890.java fails w/ RuntimeException
rupashka
parents: 4269
diff changeset
    49
19adfe928d6c 6894504: javax/swing/JFileChooser/6741890/bug6741890.java fails w/ RuntimeException
rupashka
parents: 4269
diff changeset
    50
            return;
19adfe928d6c 6894504: javax/swing/JFileChooser/6741890/bug6741890.java fails w/ RuntimeException
rupashka
parents: 4269
diff changeset
    51
        }
19adfe928d6c 6894504: javax/swing/JFileChooser/6741890/bug6741890.java fails w/ RuntimeException
rupashka
parents: 4269
diff changeset
    52
4269
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    53
        String tmpDir = System.getProperty("java.io.tmpdir");
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    54
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    55
        if (tmpDir.length() == 0) { //'java.io.tmpdir' isn't guaranteed to be defined
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    56
            tmpDir = System.getProperty("user.home");
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    57
        }
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    58
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    59
        final ShellFolder tmpFile = ShellFolder.getShellFolder(new File(tmpDir));
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    60
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    61
        System.out.println("Temp directory: " + tmpDir);
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    62
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    63
        System.out.println("Stress test was run");
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    64
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    65
        Thread thread = new Thread() {
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    66
            public void run() {
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    67
                while (!isInterrupted()) {
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    68
                    ShellFolder.invoke(new Callable<Void>() {
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    69
                        public Void call() throws Exception {
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    70
                            synchronized (mux) {
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    71
                                tmpFile.isFileSystem();
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    72
                                tmpFile.isLink();
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    73
                            }
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    74
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    75
                            return null;
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    76
                        }
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    77
                    });
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    78
                }
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    79
            }
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    80
        };
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    81
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    82
        thread.start();
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    83
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    84
        for (int i = 0; i < COUNT; i++) {
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    85
            synchronized (mux) {
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    86
                clearField(tmpFile, "cachedIsLink");
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    87
                clearField(tmpFile, "cachedIsFileSystem");
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    88
            }
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    89
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    90
            tmpFile.isFileSystem();
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    91
            tmpFile.isLink();
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    92
        }
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    93
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    94
        thread.interrupt();
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    95
        thread.join();
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    96
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    97
        System.out.println("Test passed successfully");
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    98
    }
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
    99
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
   100
    private static void clearField(Object o, String fieldName) throws Exception {
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
   101
        Field field = o.getClass().getDeclaredField(fieldName);
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
   102
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
   103
        field.setAccessible(true);
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
   104
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
   105
        field.set(o, null);
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
   106
    }
0283fbab043c 6892340: Part of the CR 6741890 should be forwardported
rupashka
parents:
diff changeset
   107
}