8016311: Update j.u.c. tests to avoid using Thread.stop(Throwable)
Reviewed-by: alanb
Contributed-by: martinrb@google.com
--- a/jdk/test/java/util/concurrent/Executors/PrivilegedCallables.java Tue Jun 11 11:22:28 2013 +0100
+++ b/jdk/test/java/util/concurrent/Executors/PrivilegedCallables.java Tue Jun 11 11:25:59 2013 +0100
@@ -43,7 +43,8 @@
final Random rnd = new Random();
- @SuppressWarnings("serial") Throwable[] throwables = {
+ @SuppressWarnings("serial")
+ Throwable[] throwables = {
new Exception() {},
new RuntimeException() {},
new Error() {}
@@ -51,6 +52,11 @@
Throwable randomThrowable() {
return throwables[rnd.nextInt(throwables.length)];
}
+ void throwThrowable(Throwable t) throws Exception {
+ if (t instanceof Error) throw (Error) t;
+ if (t instanceof RuntimeException) throw (RuntimeException) t;
+ throw (Exception) t;
+ }
//----------------------------------------------------------------
// A Policy class designed to make permissions fiddling very easy.
@@ -119,9 +125,8 @@
if (rnd.nextBoolean()) {
final Throwable t = randomThrowable();
real = new Callable<Integer>() {
- @SuppressWarnings("deprecation")
public Integer call() throws Exception {
- Thread.currentThread().stop(t);
+ throwThrowable(t);
return null; }};
try {
c.call();
--- a/jdk/test/java/util/concurrent/FutureTask/Throw.java Tue Jun 11 11:22:28 2013 +0100
+++ b/jdk/test/java/util/concurrent/FutureTask/Throw.java Tue Jun 11 11:25:59 2013 +0100
@@ -31,10 +31,9 @@
public class Throw {
- @SuppressWarnings("deprecation")
static void THROW(final Throwable t) {
if (t != null)
- Thread.currentThread().stop(t);
+ Throw.<RuntimeException>uncheckedThrow(t);
}
Callable<Void> thrower(final Throwable t) {
@@ -138,4 +137,8 @@
catch (Throwable t) {
if (k.isAssignableFrom(t.getClass())) pass();
else unexpected(t);}}
+ @SuppressWarnings("unchecked") static <T extends Throwable>
+ void uncheckedThrow(Throwable t) throws T {
+ throw (T)t; // rely on vacuous cast
+ }
}
--- a/jdk/test/java/util/concurrent/ThreadPoolExecutor/ThrowingTasks.java Tue Jun 11 11:22:28 2013 +0100
+++ b/jdk/test/java/util/concurrent/ThreadPoolExecutor/ThrowingTasks.java Tue Jun 11 11:25:59 2013 +0100
@@ -101,8 +101,10 @@
static class Thrower implements Runnable {
Throwable t;
Thrower(Throwable t) { this.t = t; }
- @SuppressWarnings("deprecation")
- public void run() { if (t != null) Thread.currentThread().stop(t); }
+ public void run() {
+ if (t != null)
+ ThrowingTasks.<RuntimeException>uncheckedThrow(t);
+ }
}
static final Thrower noThrower = new Thrower(null);
@@ -265,4 +267,8 @@
try {realMain(args);} catch (Throwable t) {unexpected(t);}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new AssertionError("Some tests failed");}
+ @SuppressWarnings("unchecked") static <T extends Throwable>
+ void uncheckedThrow(Throwable t) throws T {
+ throw (T)t; // rely on vacuous cast
+ }
}
--- a/jdk/test/java/util/concurrent/locks/Lock/FlakyMutex.java Tue Jun 11 11:22:28 2013 +0100
+++ b/jdk/test/java/util/concurrent/locks/Lock/FlakyMutex.java Tue Jun 11 11:25:59 2013 +0100
@@ -37,7 +37,7 @@
* tryAcquire method that randomly throws various Throwable
* subclasses.
*/
-@SuppressWarnings({"deprecation", "serial"})
+@SuppressWarnings("serial")
public class FlakyMutex implements Lock {
static class MyError extends Error {}
static class MyException extends Exception {}
@@ -49,7 +49,7 @@
switch (rnd.nextInt(10)) {
case 0: throw new MyError();
case 1: throw new MyRuntimeException();
- case 2: Thread.currentThread().stop(new MyException()); break;
+ case 2: FlakyMutex.<RuntimeException>uncheckedThrow(new MyException());
default: /* Do nothing */ break;
}
}
@@ -146,4 +146,8 @@
try {realMain(args);} catch (Throwable t) {unexpected(t);}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new AssertionError("Some tests failed");}
+ @SuppressWarnings("unchecked") static <T extends Throwable>
+ void uncheckedThrow(Throwable t) throws T {
+ throw (T)t; // rely on vacuous cast
+ }
}