8198004: javax/swing/JFileChooser/6868611/bug6868611.java throws error
Reviewed-by: serb, ssadetsky, kaddepalli
This commit is contained in:
parent
f0499d1caa
commit
83256c19ee
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -21,73 +21,74 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* @test
|
||||
@bug 6868611
|
||||
@summary FileSystemView throws NullPointerException
|
||||
@author Pavel Porvatov
|
||||
@run main bug6868611
|
||||
*/
|
||||
/*
|
||||
* @test
|
||||
* @bug 6868611 8198004
|
||||
* @summary FileSystemView throws NullPointerException
|
||||
* @author Pavel Porvatov
|
||||
* @run main bug6868611
|
||||
*/
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.filechooser.FileSystemView;
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class bug6868611 {
|
||||
private static final int COUNT = 1000;
|
||||
private static File tempFolder;
|
||||
private static File files[] = new File[COUNT];
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String tempDirProp = System.getProperty("java.io.tmpdir");
|
||||
int fileCount = 0;
|
||||
try {
|
||||
tempFolder = Files.createTempDirectory("temp_folder").toFile();
|
||||
|
||||
final String tempDir = tempDirProp == null || !new File(tempDirProp).isDirectory() ?
|
||||
System.getProperty("user.home") : tempDirProp;
|
||||
|
||||
System.out.println("Temp directory: " + tempDir);
|
||||
|
||||
// Create 1000 files
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
new File(tempDir, "temp" + i).createNewFile();
|
||||
}
|
||||
|
||||
// Init default FileSystemView
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
public void run() {
|
||||
FileSystemView.getFileSystemView().getFiles(new File(tempDir), false);
|
||||
// Try creating 1000 files
|
||||
for (fileCount = 0; fileCount < COUNT; fileCount++) {
|
||||
files[fileCount] = new
|
||||
File(tempFolder, "temp" + fileCount + ".txt");
|
||||
files[fileCount].createNewFile();
|
||||
}
|
||||
});
|
||||
|
||||
for (int i = 0; i < COUNT; i++) {
|
||||
Thread thread = new MyThread(tempDir);
|
||||
// Init default FileSystemView
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
public void run() {
|
||||
FileSystemView.getFileSystemView().
|
||||
getFiles(tempFolder, false);
|
||||
}
|
||||
});
|
||||
|
||||
thread.start();
|
||||
for (int i = 0; i < COUNT; i++) {
|
||||
Thread thread = new MyThread(tempFolder);
|
||||
|
||||
Thread.sleep((long) (Math.random() * 100));
|
||||
thread.start();
|
||||
|
||||
thread.interrupt();
|
||||
Thread.sleep((long) (Math.random() * 100));
|
||||
|
||||
if (i % 100 == 0) {
|
||||
System.out.print("*");
|
||||
thread.interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
|
||||
// Remove 1000 files
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
new File(tempDir, "temp" + i).delete();
|
||||
} finally {
|
||||
// Remove created files
|
||||
for (int i = 0; i < fileCount; i++) {
|
||||
Files.delete(files[i].toPath());
|
||||
}
|
||||
Files.delete(tempFolder.toPath());
|
||||
}
|
||||
}
|
||||
|
||||
private static class MyThread extends Thread {
|
||||
private final String dir;
|
||||
private final File dir;
|
||||
|
||||
private MyThread(String dir) {
|
||||
private MyThread(File dir) {
|
||||
this.dir = dir;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
FileSystemView fileSystemView = FileSystemView.getFileSystemView();
|
||||
|
||||
fileSystemView.getFiles(new File(dir), false);
|
||||
fileSystemView.getFiles(dir, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user