changeset 8280:31ee59886c95

check forEach throws ConcurrentModificationException
author akhil
date Sat, 20 Apr 2013 20:47:53 -0700
parents a8b9c58fbd24
children f51da04f3899
files test/java/util/Collection/ListDefaults.java
diffstat 1 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/util/Collection/ListDefaults.java	Sat Apr 20 20:42:26 2013 -0700
+++ b/test/java/util/Collection/ListDefaults.java	Sat Apr 20 20:47:53 2013 -0700
@@ -420,6 +420,27 @@
     }
 
     @Test
+    public void testForEachThrowsCME() throws Exception {
+        final CollectionSupplier supplier = new CollectionSupplier(LIST_CME_CLASSES, SIZE);
+        for (final CollectionSupplier.TestCase test : supplier.get()) {
+            final List<Integer> list = ((List<Integer>) test.collection);
+            if (list.size() <= 1) {
+                continue;
+            }
+            boolean gotException = false;
+            try {
+                // bad predicate that modifies its list, should throw CME
+                list.forEach((x) -> {list.add(x);});
+            } catch (ConcurrentModificationException cme) {
+                gotException = true;
+            }
+            if (!gotException) {
+                fail("expected CME was not thrown from " + test);
+            }
+        }
+    }
+
+    @Test
     public void testRemoveIfThrowsCME() throws Exception {
         final CollectionSupplier supplier = new CollectionSupplier(LIST_CME_CLASSES, SIZE);
         for (final CollectionSupplier.TestCase test : supplier.get()) {