--- jsr166/src/test/tck/Collection8Test.java 2016/12/12 20:49:34 1.42 +++ jsr166/src/test/tck/Collection8Test.java 2016/12/26 19:54:46 1.45 @@ -541,18 +541,14 @@ public class Collection8Test extends JSR } catch (ConcurrentModificationException ex) { r1 = ConcurrentModificationException.class; assertFalse(impl.isConcurrent()); - } catch (UnsupportedOperationException ex) { - r1 = UnsupportedOperationException.class; } try { it2.forEachRemaining(iteratedForEachRemaining::add); r2 = iteratedForEachRemaining; } catch (ConcurrentModificationException ex) { r2 = ConcurrentModificationException.class; - } catch (UnsupportedOperationException ex) { - r2 = UnsupportedOperationException.class; + assertFalse(impl.isConcurrent()); } - if (!r1.equals(r2)) System.err.println(impl.klazz()); assertEquals(r1, r2); } @@ -731,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 {