Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JFileChooser/6741890/bug6741890.java
38854 views
/*1* Copyright (c) 2009, 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 674189025@summary Deadlock in Win32ShellFolderManager226@author Pavel Porvatov27@run main bug674189028*/2930import sun.awt.shell.ShellFolder;31import sun.awt.OSInfo;3233import java.io.File;34import java.lang.reflect.Field;35import java.util.concurrent.Callable;3637public class bug6741890 {38/**39* This mux is used to prevent NPE in the isLink and isFileSystem methods40*/41private static final Object mux = new Object();4243private static final int COUNT = 100000;4445public static void main(String[] args) throws Exception {46if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {47System.out.println("The test is applicable only for Windows. Skipped.");4849return;50}5152String tmpDir = System.getProperty("java.io.tmpdir");5354if (tmpDir.length() == 0) { //'java.io.tmpdir' isn't guaranteed to be defined55tmpDir = System.getProperty("user.home");56}5758final ShellFolder tmpFile = ShellFolder.getShellFolder(new File(tmpDir));5960System.out.println("Temp directory: " + tmpDir);6162System.out.println("Stress test was run");6364Thread thread = new Thread() {65public void run() {66while (!isInterrupted()) {67ShellFolder.invoke(new Callable<Void>() {68public Void call() throws Exception {69synchronized (mux) {70tmpFile.isFileSystem();71tmpFile.isLink();72}7374return null;75}76});77}78}79};8081thread.start();8283for (int i = 0; i < COUNT; i++) {84synchronized (mux) {85clearField(tmpFile, "cachedIsLink");86clearField(tmpFile, "cachedIsFileSystem");87}8889tmpFile.isFileSystem();90tmpFile.isLink();91}9293thread.interrupt();94thread.join();9596System.out.println("Test passed successfully");97}9899private static void clearField(Object o, String fieldName) throws Exception {100Field field = o.getClass().getDeclaredField(fieldName);101102field.setAccessible(true);103104field.set(o, null);105}106}107108109