--- jsr166/src/test/tck/Collection8Test.java 2016/11/07 00:37:53 1.21 +++ jsr166/src/test/tck/Collection8Test.java 2016/11/15 00:08:25 1.25 @@ -61,12 +61,23 @@ public class Collection8Test extends JSR } /** Checks properties of empty collections. */ - public void testEmptyMeansEmpty() throws InterruptedException { + public void testEmptyMeansEmpty() throws Throwable { Collection c = impl.emptyCollection(); emptyMeansEmpty(c); - if (c instanceof java.io.Serializable) - emptyMeansEmpty(serialClone(c)); + if (c instanceof java.io.Serializable) { + try { + emptyMeansEmpty(serialClonePossiblyFailing(c)); + } catch (java.io.NotSerializableException ex) { + // excusable when we have a serializable wrapper around + // a non-serializable collection, as can happen with: + // Vector.subList() => wrapped AbstractList$RandomAccessSubList + if (testImplementationDetails + && (! c.getClass().getName().matches( + "java.util.Collections.*"))) + throw ex; + } + } Collection clone = cloneableClone(c); if (clone != null) @@ -241,6 +252,8 @@ public class Collection8Test extends JSR public void testRemoveIf() { Collection c = impl.emptyCollection(); + boolean ordered = + c.spliterator().hasCharacteristics(Spliterator.ORDERED); ThreadLocalRandom rnd = ThreadLocalRandom.current(); int n = rnd.nextInt(6); for (int i = 0; i < n; i++) c.add(impl.makeElement(i)); @@ -272,7 +285,13 @@ public class Collection8Test extends JSR assertEquals(modified, accepts.size() > 0); assertEquals(modified, rejects.size() != n); assertEquals(accepts.size() + rejects.size(), n); - assertEquals(rejects, Arrays.asList(c.toArray())); + if (ordered) { + assertEquals(rejects, + Arrays.asList(c.toArray())); + } else { + assertEquals(new HashSet(rejects), + new HashSet(Arrays.asList(c.toArray()))); + } } catch (ArithmeticException ok) { assertNotNull(threwAt.get()); assertTrue(c.contains(threwAt.get())); @@ -293,11 +312,22 @@ public class Collection8Test extends JSR assertTrue(c.containsAll(rejects)); assertTrue(c.containsAll(survivors)); assertTrue(survivors.containsAll(rejects)); - assertEquals(n - accepts.size(), c.size()); - for (Object x : accepts) assertFalse(c.contains(x)); + if (threwAt.get() == null) { + assertEquals(n - accepts.size(), c.size()); + for (Object x : accepts) assertFalse(c.contains(x)); + } else { + // Two acceptable behaviors: entire removeIf call is one + // transaction, or each element processed is one transaction. + assertTrue(n == c.size() || n == c.size() + accepts.size()); + int k = 0; + for (Object x : accepts) if (c.contains(x)) k++; + assertTrue(k == accepts.size() || k == 0); + } } catch (Throwable ex) { System.err.println(impl.klazz()); - System.err.printf("c=%s%n", c); + // c is at risk of corruption if we got here, so be lenient + try { System.err.printf("c=%s%n", c); } + catch (Throwable t) { t.printStackTrace(); } System.err.printf("n=%d%n", n); System.err.printf("orig=%s%n", orig); System.err.printf("accepts=%s%n", accepts); @@ -370,7 +400,7 @@ public class Collection8Test extends JSR public void testRemoveAfterForEachRemaining() { Collection c = impl.emptyCollection(); ThreadLocalRandom rnd = ThreadLocalRandom.current(); - { + testCollection: { int n = 3 + rnd.nextInt(2); for (int i = 0; i < n; i++) c.add(impl.makeElement(i)); Iterator it = c.iterator(); @@ -383,7 +413,10 @@ public class Collection8Test extends JSR if (c instanceof java.util.concurrent.ArrayBlockingQueue) { assertIteratorExhausted(it); } else { - it.remove(); + try { it.remove(); } + catch (UnsupportedOperationException ok) { + break testCollection; + } assertEquals(n - 1, c.size()); for (int i = 0; i < n - 1; i++) assertTrue(c.contains(impl.makeElement(i)));