1 /* 2 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* @test 25 @bug 6868611 26 @summary FileSystemView throws NullPointerException 27 @author Pavel Porvatov 28 @run main bug6868611 29 @key randomness 30 */ 31 32 import javax.swing.*; 33 import javax.swing.filechooser.FileSystemView; 34 import java.io.File; 35 36 public class bug6868611 { 37 private static final int COUNT = 1000; 38 39 public static void main(String[] args) throws Exception { 40 String tempDirProp = System.getProperty("java.io.tmpdir"); 41 42 final String tempDir = tempDirProp == null || !new File(tempDirProp).isDirectory() ? 43 System.getProperty("user.home") : tempDirProp; 44 45 System.out.println("Temp directory: " + tempDir); 46 47 // Create 1000 files 48 for (int i = 0; i < 1000; i++) { 49 new File(tempDir, "temp" + i).createNewFile(); 50 } 51 52 // Init default FileSystemView 53 SwingUtilities.invokeAndWait(new Runnable() { 54 public void run() { 55 FileSystemView.getFileSystemView().getFiles(new File(tempDir), false); 56 } 57 }); 58 59 for (int i = 0; i < COUNT; i++) { 60 Thread thread = new MyThread(tempDir); 61 62 thread.start(); 63 64 Thread.sleep((long) (Math.random() * 100)); 65 66 thread.interrupt(); 67 68 if (i % 100 == 0) { 69 System.out.print("*"); 70 } 71 } 72 73 System.out.println(); 74 75 // Remove 1000 files 76 for (int i = 0; i < 1000; i++) { 77 new File(tempDir, "temp" + i).delete(); 78 } 79 } 80 81 private static class MyThread extends Thread { 82 private final String dir; 83 84 private MyThread(String dir) { 85 this.dir = dir; 86 } 87 88 public void run() { 89 FileSystemView fileSystemView = FileSystemView.getFileSystemView(); 90 91 fileSystemView.getFiles(new File(dir), false); 92 } 93 } 94 }