Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JFileChooser/6713352/bug6713352.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 671335225@summary Deadlock in JFileChooser with synchronized custom FileSystemView26@author Pavel Porvatov27@run main bug671335228*/2930import sun.awt.shell.ShellFolder;3132import javax.swing.*;33import javax.swing.filechooser.FileSystemView;34import java.io.File;35import java.io.FileNotFoundException;36import java.io.IOException;3738public class bug6713352 {39public static void main(String[] args) throws Exception {40SwingUtilities.invokeAndWait(new Runnable() {41public void run() {42String tempDir = System.getProperty("java.io.tmpdir");4344if (tempDir == null || !new File(tempDir).isDirectory()) {45tempDir = System.getProperty("user.home");46}4748MyFileSystemView systemView = new MyFileSystemView();4950synchronized (systemView) { // Get SystemView lock51new JFileChooser(systemView);5253// Wait a little bit. BasicDirectoryModel will lock Invoker and stop on54// the bug6713352.MyFileSystemView.getFiles() method55try {56Thread.sleep(5000);57} catch (InterruptedException e) {58throw new RuntimeException(e);59}6061try {62System.out.println("Try to get Invokers lock");6364ShellFolder.getShellFolder(new File(tempDir)).listFiles(true);65} catch (FileNotFoundException e) {66throw new RuntimeException(e);67}68}6970// To avoid RejectedExecutionException in BasicDirectoryModel wait a second71try {72Thread.sleep(1000);73} catch (InterruptedException e) {74throw new RuntimeException(e);75}76}77});78}7980private static class MyFileSystemView extends FileSystemView {8182public File createNewFolder(File containingDir) throws IOException {83return null;84}8586public File[] getFiles(File dir, boolean useFileHiding) {87System.out.println("getFiles start");8889File[] result;9091synchronized (this) {92result = super.getFiles(dir, useFileHiding);93}9495System.out.println("getFiles finished");9697return result;98}99100public synchronized Boolean isTraversable(File f) {101return super.isTraversable(f);102}103}104}105106107