test/java/lang/Thread/StopBeforeStart.java
Print this page
@@ -21,28 +21,26 @@
* questions.
*/
/*
* @test
- * @bug 4519200
+ * @bug 4519200 6562203
* @summary Confirm a Thread.stop before start complies with the spec
* @author Pete Soper
*
* Confirm that a thread that had its stop method invoked before start
- * does properly terminate with expected exception behavior. NOTE that
- * arbitrary application threads could return from their run methods faster
- * than the VM can throw an async exception.
+ * does properly terminate with expected exception behavior.
*/
public class StopBeforeStart {
private static final int JOIN_TIMEOUT=10000;
- private class MyThrowable extends Throwable {
- }
+ @SuppressWarnings("serial")
+ private class MyThrowable extends Throwable { }
private class Catcher implements Thread.UncaughtExceptionHandler {
- private boolean nullaryStop;
+ private final boolean nullaryStop;
private Throwable theThrowable;
private Throwable expectedThrowable;
private boolean exceptionThrown;
Catcher(boolean nullaryStop) {
@@ -108,25 +106,35 @@
Catcher c = new Catcher(nullaryStop);
thread.setUncaughtExceptionHandler(c);
if (nullaryStop) {
- thread.stop();
+ stop(thread);
} else {
- thread.stop(c.expectedThrowable);
+ stop(thread, c.expectedThrowable);
}
thread.start();
thread.join(JOIN_TIMEOUT);
if (thread.getState() != Thread.State.TERMINATED) {
- thread.stop();
+ stop(thread);
// Under high load this could be a false positive
throw new RuntimeException(type +
" test:" + " app thread did not terminate");
}
c.check(type);
}
+
+ @SuppressWarnings("deprecation")
+ void stop(Thread thread) {
+ thread.stop();
+ }
+
+ @SuppressWarnings("deprecation")
+ void stop(Thread thread, Throwable t) {
+ thread.stop(t);
+ }
}