Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JFileChooser/6868611/bug6868611.java
41153 views
1
/*
2
* Copyright (c) 2009, 2018, 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
/*
25
* @test
26
* @bug 6868611 8198004
27
* @summary FileSystemView throws NullPointerException
28
* @author Pavel Porvatov
29
* @run main bug6868611
30
*/
31
32
import javax.swing.*;
33
import javax.swing.filechooser.FileSystemView;
34
import java.io.File;
35
import java.nio.file.Files;
36
37
public class bug6868611 {
38
private static final int COUNT = 1000;
39
private static File tempFolder;
40
private static File files[] = new File[COUNT];
41
42
public static void main(String[] args) throws Exception {
43
int fileCount = 0;
44
try {
45
tempFolder = Files.createTempDirectory("temp_folder").toFile();
46
47
// Try creating 1000 files
48
for (fileCount = 0; fileCount < COUNT; fileCount++) {
49
files[fileCount] = new
50
File(tempFolder, "temp" + fileCount + ".txt");
51
files[fileCount].createNewFile();
52
}
53
54
// Init default FileSystemView
55
SwingUtilities.invokeAndWait(new Runnable() {
56
public void run() {
57
FileSystemView.getFileSystemView().
58
getFiles(tempFolder, false);
59
}
60
});
61
62
for (int i = 0; i < COUNT; i++) {
63
Thread thread = new MyThread(tempFolder);
64
65
thread.start();
66
67
Thread.sleep((long) (Math.random() * 100));
68
69
thread.interrupt();
70
}
71
} finally {
72
// Remove created files
73
for (int i = 0; i < fileCount; i++) {
74
Files.delete(files[i].toPath());
75
}
76
Files.delete(tempFolder.toPath());
77
}
78
}
79
80
private static class MyThread extends Thread {
81
private final File dir;
82
83
private MyThread(File dir) {
84
this.dir = dir;
85
}
86
87
public void run() {
88
FileSystemView fileSystemView = FileSystemView.getFileSystemView();
89
90
fileSystemView.getFiles(dir, false);
91
}
92
}
93
}
94
95
96