--- jsr166/src/test/tck/JSR166TestCase.java 2017/12/11 00:27:08 1.238 +++ jsr166/src/test/tck/JSR166TestCase.java 2018/01/23 20:44:11 1.239 @@ -99,7 +99,6 @@ import java.util.concurrent.atomic.Atomi import java.util.concurrent.atomic.AtomicReference; import java.util.regex.Pattern; -import junit.framework.AssertionFailedError; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestResult; @@ -733,7 +732,7 @@ public class JSR166TestCase extends Test String msg = toString() + ": " + String.format(format, args); System.err.println(msg); dumpTestThreads(); - throw new AssertionFailedError(msg); + throw new AssertionError(msg); } /** @@ -754,12 +753,8 @@ public class JSR166TestCase extends Test throw (RuntimeException) t; else if (t instanceof Exception) throw (Exception) t; - else { - AssertionFailedError afe = - new AssertionFailedError(t.toString()); - afe.initCause(t); - throw afe; - } + else + throw new AssertionError(t.toString(), t); } if (Thread.interrupted()) @@ -793,83 +788,83 @@ public class JSR166TestCase extends Test /** * Just like fail(reason), but additionally recording (using - * threadRecordFailure) any AssertionFailedError thrown, so that - * the current testcase will fail. + * threadRecordFailure) any AssertionError thrown, so that the + * current testcase will fail. */ public void threadFail(String reason) { try { fail(reason); - } catch (AssertionFailedError t) { - threadRecordFailure(t); - throw t; + } catch (AssertionError fail) { + threadRecordFailure(fail); + throw fail; } } /** * Just like assertTrue(b), but additionally recording (using - * threadRecordFailure) any AssertionFailedError thrown, so that - * the current testcase will fail. + * threadRecordFailure) any AssertionError thrown, so that the + * current testcase will fail. */ public void threadAssertTrue(boolean b) { try { assertTrue(b); - } catch (AssertionFailedError t) { - threadRecordFailure(t); - throw t; + } catch (AssertionError fail) { + threadRecordFailure(fail); + throw fail; } } /** * Just like assertFalse(b), but additionally recording (using - * threadRecordFailure) any AssertionFailedError thrown, so that - * the current testcase will fail. + * threadRecordFailure) any AssertionError thrown, so that the + * current testcase will fail. */ public void threadAssertFalse(boolean b) { try { assertFalse(b); - } catch (AssertionFailedError t) { - threadRecordFailure(t); - throw t; + } catch (AssertionError fail) { + threadRecordFailure(fail); + throw fail; } } /** * Just like assertNull(x), but additionally recording (using - * threadRecordFailure) any AssertionFailedError thrown, so that - * the current testcase will fail. + * threadRecordFailure) any AssertionError thrown, so that the + * current testcase will fail. */ public void threadAssertNull(Object x) { try { assertNull(x); - } catch (AssertionFailedError t) { - threadRecordFailure(t); - throw t; + } catch (AssertionError fail) { + threadRecordFailure(fail); + throw fail; } } /** * Just like assertEquals(x, y), but additionally recording (using - * threadRecordFailure) any AssertionFailedError thrown, so that - * the current testcase will fail. + * threadRecordFailure) any AssertionError thrown, so that the + * current testcase will fail. */ public void threadAssertEquals(long x, long y) { try { assertEquals(x, y); - } catch (AssertionFailedError t) { - threadRecordFailure(t); - throw t; + } catch (AssertionError fail) { + threadRecordFailure(fail); + throw fail; } } /** * Just like assertEquals(x, y), but additionally recording (using - * threadRecordFailure) any AssertionFailedError thrown, so that - * the current testcase will fail. + * threadRecordFailure) any AssertionError thrown, so that the + * current testcase will fail. */ public void threadAssertEquals(Object x, Object y) { try { assertEquals(x, y); - } catch (AssertionFailedError fail) { + } catch (AssertionError fail) { threadRecordFailure(fail); throw fail; } catch (Throwable fail) { @@ -879,13 +874,13 @@ public class JSR166TestCase extends Test /** * Just like assertSame(x, y), but additionally recording (using - * threadRecordFailure) any AssertionFailedError thrown, so that - * the current testcase will fail. + * threadRecordFailure) any AssertionError thrown, so that the + * current testcase will fail. */ public void threadAssertSame(Object x, Object y) { try { assertSame(x, y); - } catch (AssertionFailedError fail) { + } catch (AssertionError fail) { threadRecordFailure(fail); throw fail; } @@ -907,8 +902,8 @@ public class JSR166TestCase extends Test /** * Records the given exception using {@link #threadRecordFailure}, - * then rethrows the exception, wrapping it in an - * AssertionFailedError if necessary. + * then rethrows the exception, wrapping it in an AssertionError + * if necessary. */ public void threadUnexpectedException(Throwable t) { threadRecordFailure(t); @@ -917,12 +912,8 @@ public class JSR166TestCase extends Test throw (RuntimeException) t; else if (t instanceof Error) throw (Error) t; - else { - AssertionFailedError afe = - new AssertionFailedError("unexpected exception: " + t); - afe.initCause(t); - throw afe; - } + else + throw new AssertionError("unexpected exception: " + t, t); } /** @@ -1284,16 +1275,13 @@ public class JSR166TestCase extends Test /** * Sleeps until the given time has elapsed. - * Throws AssertionFailedError if interrupted. + * Throws AssertionError if interrupted. */ static void sleep(long millis) { try { delay(millis); } catch (InterruptedException fail) { - AssertionFailedError afe = - new AssertionFailedError("Unexpected InterruptedException"); - afe.initCause(fail); - throw afe; + throw new AssertionError("Unexpected InterruptedException", fail); } } @@ -1384,7 +1372,7 @@ public class JSR166TestCase extends Test // r.run(); // } catch (Throwable fail) { threadUnexpectedException(fail); } // if (millisElapsedSince(startTime) > timeoutMillis/2) -// throw new AssertionFailedError("did not return promptly"); +// throw new AssertionError("did not return promptly"); // } // void assertTerminatesPromptly(Runnable r) { @@ -1401,7 +1389,7 @@ public class JSR166TestCase extends Test assertEquals(expectedValue, f.get(timeoutMillis, MILLISECONDS)); } catch (Throwable fail) { threadUnexpectedException(fail); } if (millisElapsedSince(startTime) > timeoutMillis/2) - throw new AssertionFailedError("timed get did not return promptly"); + throw new AssertionError("timed get did not return promptly"); } void checkTimedGet(Future f, T expectedValue) { @@ -1643,7 +1631,7 @@ public class JSR166TestCase extends Test // long startTime = System.nanoTime(); // while (!flag.get()) { // if (millisElapsedSince(startTime) > timeoutMillis) -// throw new AssertionFailedError("timed out"); +// throw new AssertionError("timed out"); // Thread.yield(); // } // } @@ -1730,7 +1718,7 @@ public class JSR166TestCase extends Test /** * A CyclicBarrier that uses timed await and fails with - * AssertionFailedErrors instead of throwing checked exceptions. + * AssertionErrors instead of throwing checked exceptions. */ public static class CheckedBarrier extends CyclicBarrier { public CheckedBarrier(int parties) { super(parties); } @@ -1739,12 +1727,9 @@ public class JSR166TestCase extends Test try { return super.await(2 * LONG_DELAY_MS, MILLISECONDS); } catch (TimeoutException timedOut) { - throw new AssertionFailedError("timed out"); + throw new AssertionError("timed out"); } catch (Exception fail) { - AssertionFailedError afe = - new AssertionFailedError("Unexpected exception: " + fail); - afe.initCause(fail); - throw afe; + throw new AssertionError("Unexpected exception: " + fail, fail); } } } @@ -1867,14 +1852,11 @@ public class JSR166TestCase extends Test try { throwingAction.run(); } catch (Throwable t) { threw = true; - if (!expectedExceptionClass.isInstance(t)) { - AssertionFailedError afe = - new AssertionFailedError - ("Expected " + expectedExceptionClass.getName() + - ", got " + t.getClass().getName()); - afe.initCause(t); - threadUnexpectedException(afe); - } + if (!expectedExceptionClass.isInstance(t)) + throw new AssertionError( + "Expected " + expectedExceptionClass.getName() + + ", got " + t.getClass().getName(), + t); } if (!threw) shouldThrow(expectedExceptionClass.getName());