--- jsr166/src/test/tck/Collection8Test.java 2016/12/18 20:47:28 1.44 +++ jsr166/src/test/tck/Collection8Test.java 2016/12/26 19:54:46 1.45 @@ -727,6 +727,31 @@ public class Collection8Test extends JSR } /** + * Concurrent Spliterators, once exhausted, stay exhausted. + */ + public void testStickySpliteratorExhaustion() throws Throwable { + if (!impl.isConcurrent()) return; + if (!testImplementationDetails) return; + final ThreadLocalRandom rnd = ThreadLocalRandom.current(); + final Consumer alwaysThrows = e -> { throw new AssertionError(); }; + final Collection c = impl.emptyCollection(); + final Spliterator s = c.spliterator(); + if (rnd.nextBoolean()) { + assertFalse(s.tryAdvance(alwaysThrows)); + } else { + s.forEachRemaining(alwaysThrows); + } + final Object one = impl.makeElement(1); + // Spliterator should not notice added element + c.add(one); + if (rnd.nextBoolean()) { + assertFalse(s.tryAdvance(alwaysThrows)); + } else { + s.forEachRemaining(alwaysThrows); + } + } + + /** * Motley crew of threads concurrently randomly hammer the collection. */ public void testDetectRaces() throws Throwable {