mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-19 23:05:28 +00:00
8016311: Update j.u.c. tests to avoid using Thread.stop(Throwable)
Reviewed-by: alanb
This commit is contained in:
parent
096a439d06
commit
fadbd21469
@ -43,7 +43,8 @@ public class PrivilegedCallables {
|
||||
|
||||
final Random rnd = new Random();
|
||||
|
||||
@SuppressWarnings("serial") Throwable[] throwables = {
|
||||
@SuppressWarnings("serial")
|
||||
Throwable[] throwables = {
|
||||
new Exception() {},
|
||||
new RuntimeException() {},
|
||||
new Error() {}
|
||||
@ -51,6 +52,11 @@ public class PrivilegedCallables {
|
||||
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 @@ public class PrivilegedCallables {
|
||||
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();
|
||||
|
||||
@ -31,10 +31,9 @@ import java.util.concurrent.*;
|
||||
|
||||
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 @@ public class Throw {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,8 +101,10 @@ public class ThrowingTasks {
|
||||
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 @@ public class ThrowingTasks {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ import java.util.concurrent.locks.*;
|
||||
* 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 @@ public class FlakyMutex implements Lock {
|
||||
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 @@ public class FlakyMutex implements Lock {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user