Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/test/java/lang/Thread/StopBeforeStart.java
+++ new/test/java/lang/Thread/StopBeforeStart.java
1 1 /*
2 2 * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation.
8 8 *
9 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 12 * version 2 for more details (a copy is included in the LICENSE file that
13 13 * accompanied this code).
14 14 *
15 15 * You should have received a copy of the GNU General Public License version
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
16 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 18 *
19 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 20 * or visit www.oracle.com if you need additional information or have any
21 21 * questions.
22 22 */
23 23
24 24 /*
25 25 * @test
26 - * @bug 4519200
26 + * @bug 4519200 6562203
27 27 * @summary Confirm a Thread.stop before start complies with the spec
28 28 * @author Pete Soper
29 29 *
30 30 * Confirm that a thread that had its stop method invoked before start
31 - * does properly terminate with expected exception behavior. NOTE that
32 - * arbitrary application threads could return from their run methods faster
33 - * than the VM can throw an async exception.
31 + * does properly terminate with expected exception behavior.
34 32 */
35 33 public class StopBeforeStart {
36 34
37 35 private static final int JOIN_TIMEOUT=10000;
38 36
39 - private class MyThrowable extends Throwable {
40 - }
37 + @SuppressWarnings("serial")
38 + private class MyThrowable extends Throwable { }
41 39
42 40 private class Catcher implements Thread.UncaughtExceptionHandler {
43 - private boolean nullaryStop;
41 + private final boolean nullaryStop;
44 42 private Throwable theThrowable;
45 43 private Throwable expectedThrowable;
46 44 private boolean exceptionThrown;
47 45
48 46 Catcher(boolean nullaryStop) {
49 47 this.nullaryStop = nullaryStop;
50 48 if (!nullaryStop) {
51 49 expectedThrowable = new MyThrowable();
52 50 }
53 51 }
54 52
55 53 public void uncaughtException(Thread t, Throwable th) {
56 54 exceptionThrown = true;
57 55 theThrowable = th;
58 56 }
59 57
60 58 void check(String label) throws Throwable {
61 59 if (!exceptionThrown) {
62 60 throw new RuntimeException(label +
63 61 " test:" + " missing uncaught exception");
64 62 }
65 63
66 64 if (nullaryStop) {
67 65 if (! (theThrowable instanceof ThreadDeath)) {
68 66 throw new RuntimeException(label +
69 67 " test:" + " expected ThreadDeath in uncaught handler");
70 68 }
71 69 } else if (theThrowable != expectedThrowable) {
72 70 throw new RuntimeException(label +
73 71 " test:" + " wrong Throwable in uncaught handler");
74 72 }
75 73 }
76 74 }
77 75
78 76 private class MyRunnable implements Runnable {
79 77 public void run() {
80 78 while(true)
81 79 ;
82 80 }
83 81 }
84 82
85 83 private class MyThread extends Thread {
86 84 public void run() {
87 85 while(true)
88 86 ;
89 87 }
90 88 }
91 89
92 90
93 91 public static void main(String args[]) throws Throwable {
94 92 (new StopBeforeStart()).doit();
95 93 System.out.println("Test passed");
96 94 }
97 95
98 96 private void doit() throws Throwable {
99 97
100 98 runit(false, new Thread(new MyRunnable()),"Thread");
101 99 runit(true, new Thread(new MyRunnable()),"Thread");
102 100 runit(false, new MyThread(),"Runnable");
↓ open down ↓ |
49 lines elided |
↑ open up ↑ |
103 101 runit(true, new MyThread(),"Runnable");
104 102 }
105 103
106 104 private void runit(boolean nullaryStop, Thread thread,
107 105 String type) throws Throwable {
108 106
109 107 Catcher c = new Catcher(nullaryStop);
110 108 thread.setUncaughtExceptionHandler(c);
111 109
112 110 if (nullaryStop) {
113 - thread.stop();
111 + stop(thread);
114 112 } else {
115 - thread.stop(c.expectedThrowable);
113 + stop(thread, c.expectedThrowable);
116 114 }
117 115
118 116 thread.start();
119 117 thread.join(JOIN_TIMEOUT);
120 118
121 119 if (thread.getState() != Thread.State.TERMINATED) {
122 120
123 - thread.stop();
121 + stop(thread);
124 122
125 123 // Under high load this could be a false positive
126 124 throw new RuntimeException(type +
127 125 " test:" + " app thread did not terminate");
128 126 }
129 127
130 128 c.check(type);
131 129 }
130 +
131 + @SuppressWarnings("deprecation")
132 + void stop(Thread thread) {
133 + thread.stop();
134 + }
135 +
136 + @SuppressWarnings("deprecation")
137 + void stop(Thread thread, Throwable t) {
138 + thread.stop(t);
139 + }
132 140 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX