--- jsr166/src/test/tck/AbstractQueuedSynchronizerTest.java 2019/08/15 16:06:13 1.72 +++ jsr166/src/test/tck/AbstractQueuedSynchronizerTest.java 2019/08/16 02:32:26 1.73 @@ -13,6 +13,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.AbstractQueuedSynchronizer; import java.util.concurrent.locks.AbstractQueuedSynchronizer.ConditionObject; @@ -1314,16 +1315,26 @@ public class AbstractQueuedSynchronizerT public void testInterruptedFailingAcquire() throws Throwable { class PleaseThrow extends RuntimeException {} final PleaseThrow ex = new PleaseThrow(); + final AtomicBoolean thrown = new AtomicBoolean(); // A synchronizer only offering a choice of failure modes class Sync extends AbstractQueuedSynchronizer { volatile boolean pleaseThrow; + void maybeThrow() { + if (pleaseThrow) { + // assert: tryAcquire methods can throw at most once + if (! thrown.compareAndSet(false, true)) + throw new AssertionError(); + throw ex; + } + } + @Override protected boolean tryAcquire(int ignored) { - if (pleaseThrow) throw ex; + maybeThrow(); return false; } @Override protected int tryAcquireShared(int ignored) { - if (pleaseThrow) throw ex; + maybeThrow(); return -1; } @Override protected boolean tryRelease(int ignored) { @@ -1407,6 +1418,9 @@ public class AbstractQueuedSynchronizerT } awaitTermination(thread); + if (! acquireInterruptibly) + assertTrue(thrown.get()); + assertNull(s.getFirstQueuedThread()); assertFalse(s.hasQueuedPredecessors()); assertFalse(s.hasQueuedThreads());