2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
2
|
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 |
*
|
5506
|
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.
|
2
|
22 |
*/
|
|
23 |
|
|
24 |
/* @test
|
|
25 |
@bug 6526376
|
|
26 |
@summary DeleteOnExitHook.add() produces NullPointerException
|
|
27 |
*/
|
|
28 |
|
|
29 |
import java.io.*;
|
|
30 |
|
|
31 |
/* NullPointerException in exec'ed process if fails.
|
|
32 |
* This testcase is timing sensitive. It may sometimes pass even with this bug
|
|
33 |
* present, but will never fail without it.
|
|
34 |
*/
|
|
35 |
|
|
36 |
public class DeleteOnExitNPE implements Runnable
|
|
37 |
{
|
|
38 |
public static void main(String[] args) throws Exception {
|
|
39 |
if (args.length == 0) {
|
|
40 |
runTest();
|
|
41 |
} else {
|
|
42 |
doTest();
|
|
43 |
}
|
|
44 |
}
|
|
45 |
|
|
46 |
public static void runTest() throws Exception {
|
|
47 |
String cmd = System.getProperty("java.home") + File.separator +
|
|
48 |
"bin" + File.separator + "java";
|
|
49 |
Process process = Runtime.getRuntime().exec(cmd + " DeleteOnExitNPE -test");
|
|
50 |
BufferedReader isReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
|
51 |
BufferedReader esReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
|
|
52 |
|
|
53 |
process.waitFor();
|
|
54 |
|
|
55 |
boolean failed = false;
|
|
56 |
String str;
|
|
57 |
while ((str = isReader.readLine()) != null) {
|
|
58 |
failed = true;
|
|
59 |
System.out.println(str);
|
|
60 |
}
|
|
61 |
while ((str = esReader.readLine()) != null) {
|
|
62 |
failed = true;
|
|
63 |
System.err.println(str);
|
|
64 |
}
|
|
65 |
|
|
66 |
if (failed)
|
|
67 |
throw new RuntimeException("Failed: No output should have been received from the process");
|
|
68 |
}
|
|
69 |
|
|
70 |
public static void doTest() {
|
|
71 |
try {
|
|
72 |
File file = File.createTempFile("DeleteOnExitNPE", null);
|
|
73 |
file.deleteOnExit();
|
|
74 |
|
|
75 |
Thread thread = new Thread(new DeleteOnExitNPE());
|
|
76 |
thread.start();
|
|
77 |
|
|
78 |
try {
|
|
79 |
Thread.sleep(2000);
|
|
80 |
} catch (InterruptedException ie) {
|
|
81 |
ie.printStackTrace();
|
|
82 |
}
|
|
83 |
|
|
84 |
System.exit(0);
|
|
85 |
} catch (IOException ioe) {
|
|
86 |
ioe.printStackTrace();
|
|
87 |
}
|
|
88 |
}
|
|
89 |
|
|
90 |
public void run() {
|
|
91 |
File file = new File("xxyyzz");
|
|
92 |
|
|
93 |
try {
|
|
94 |
for (;;) {
|
|
95 |
file.deleteOnExit();
|
|
96 |
}
|
|
97 |
} catch (IllegalStateException ise) {
|
|
98 |
// ignore. This is ok.
|
|
99 |
// Trying to add a file to the list of files marked as deleteOnExit when
|
|
100 |
// shutdown is in progress and the DeleteOnExitHook is running.
|
|
101 |
}
|
|
102 |
}
|
|
103 |
}
|