Path: blob/master/test/jdk/javax/swing/JFileChooser/6741890/bug6741890.java
41153 views
/*1* Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24@bug 6741890 817136325@summary Deadlock in Win32ShellFolderManager226@author Pavel Porvatov27@modules java.desktop/sun.awt28java.desktop/sun.awt.shell:+open29@run main bug674189030*/3132import sun.awt.shell.ShellFolder;33import sun.awt.OSInfo;3435import java.io.File;36import java.lang.reflect.Field;37import java.util.concurrent.Callable;3839public class bug6741890 {40/**41* This mux is used to prevent NPE in the isLink and isFileSystem methods42*/43private static final Object mux = new Object();4445private static final int COUNT = 100000;4647public static void main(String[] args) throws Exception {48if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {49System.out.println("The test is applicable only for Windows. Skipped.");5051return;52}5354String tmpDir = System.getProperty("java.io.tmpdir");5556if (tmpDir.length() == 0) { //'java.io.tmpdir' isn't guaranteed to be defined57tmpDir = System.getProperty("user.home");58}5960final ShellFolder tmpFile = ShellFolder.getShellFolder(new File(tmpDir));6162System.out.println("Temp directory: " + tmpDir);6364System.out.println("Stress test was run");6566Thread thread = new Thread() {67public void run() {68while (!isInterrupted()) {69ShellFolder.invoke(new Callable<Void>() {70public Void call() throws Exception {71synchronized (mux) {72tmpFile.isFileSystem();73tmpFile.isLink();74}7576return null;77}78});79}80}81};8283thread.start();8485for (int i = 0; i < COUNT; i++) {86synchronized (mux) {87clearField(tmpFile, "cachedIsLink");88clearField(tmpFile, "cachedIsFileSystem");89}9091tmpFile.isFileSystem();92tmpFile.isLink();93}9495thread.interrupt();96thread.join();9798System.out.println("Test passed successfully");99}100101private static void clearField(Object o, String fieldName) throws Exception {102Field field = o.getClass().getDeclaredField(fieldName);103104field.setAccessible(true);105106field.set(o, null);107}108}109110111