Path: blob/master/test/jdk/javax/swing/JFileChooser/6868611/bug6868611.java
41153 views
/*1* Copyright (c) 2009, 2018, 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/*24* @test25* @bug 6868611 819800426* @summary FileSystemView throws NullPointerException27* @author Pavel Porvatov28* @run main bug686861129*/3031import javax.swing.*;32import javax.swing.filechooser.FileSystemView;33import java.io.File;34import java.nio.file.Files;3536public class bug6868611 {37private static final int COUNT = 1000;38private static File tempFolder;39private static File files[] = new File[COUNT];4041public static void main(String[] args) throws Exception {42int fileCount = 0;43try {44tempFolder = Files.createTempDirectory("temp_folder").toFile();4546// Try creating 1000 files47for (fileCount = 0; fileCount < COUNT; fileCount++) {48files[fileCount] = new49File(tempFolder, "temp" + fileCount + ".txt");50files[fileCount].createNewFile();51}5253// Init default FileSystemView54SwingUtilities.invokeAndWait(new Runnable() {55public void run() {56FileSystemView.getFileSystemView().57getFiles(tempFolder, false);58}59});6061for (int i = 0; i < COUNT; i++) {62Thread thread = new MyThread(tempFolder);6364thread.start();6566Thread.sleep((long) (Math.random() * 100));6768thread.interrupt();69}70} finally {71// Remove created files72for (int i = 0; i < fileCount; i++) {73Files.delete(files[i].toPath());74}75Files.delete(tempFolder.toPath());76}77}7879private static class MyThread extends Thread {80private final File dir;8182private MyThread(File dir) {83this.dir = dir;84}8586public void run() {87FileSystemView fileSystemView = FileSystemView.getFileSystemView();8889fileSystemView.getFiles(dir, false);90}91}92}93949596