< prev index next >

test/jdk/java/util/concurrent/tck/Collection8Test.java

Print this page
8203662: remove increment of modCount from ArrayList and Vector replaceAll()
Reviewed-by: martin, igerasim, redestad, dholmes, smarks, jrose, plevart


 962         assertEquals(c, c);
 963         if (c instanceof List)
 964             assertCollectionsEquals(c, new ArrayList(c));
 965         else if (c instanceof Set)
 966             assertCollectionsEquals(c, new HashSet(c));
 967         else if (c instanceof Deque)
 968             assertCollectionsEquivalent(c, new ArrayDeque(c));
 969 
 970         Collection clone = cloneableClone(c);
 971         if (clone != null) {
 972             assertSame(c.getClass(), clone.getClass());
 973             assertCollectionsEquivalent(c, clone);
 974         }
 975         try {
 976             Collection serialClone = serialClonePossiblyFailing(c);
 977             assertSame(c.getClass(), serialClone.getClass());
 978             assertCollectionsEquivalent(c, serialClone);
 979         } catch (java.io.NotSerializableException acceptable) {}
 980     }
 981 
 982     public void DISABLED_testReplaceAllIsNotStructuralModification() {
 983         Collection c = impl.emptyCollection();
 984         if (!(c instanceof List))
 985             return;
 986         List list = (List) c;
 987         ThreadLocalRandom rnd = ThreadLocalRandom.current();
 988         for (int n = rnd.nextInt(2, 10); n--> 0; )
 989             list.add(impl.makeElement(rnd.nextInt()));
 990         ArrayList copy = new ArrayList(list);
 991         int size = list.size(), half = size / 2;
 992         Iterator it = list.iterator();
 993         for (int i = 0; i < half; i++)
 994             assertEquals(it.next(), copy.get(i));
 995         list.replaceAll(n -> n);
 996         // ConcurrentModificationException must not be thrown here.
 997         for (int i = half; i < size; i++)
 998             assertEquals(it.next(), copy.get(i));
 999     }
1000 
1001 //     public void testCollection8DebugFail() {
1002 //         fail(impl.klazz().getSimpleName());


 962         assertEquals(c, c);
 963         if (c instanceof List)
 964             assertCollectionsEquals(c, new ArrayList(c));
 965         else if (c instanceof Set)
 966             assertCollectionsEquals(c, new HashSet(c));
 967         else if (c instanceof Deque)
 968             assertCollectionsEquivalent(c, new ArrayDeque(c));
 969 
 970         Collection clone = cloneableClone(c);
 971         if (clone != null) {
 972             assertSame(c.getClass(), clone.getClass());
 973             assertCollectionsEquivalent(c, clone);
 974         }
 975         try {
 976             Collection serialClone = serialClonePossiblyFailing(c);
 977             assertSame(c.getClass(), serialClone.getClass());
 978             assertCollectionsEquivalent(c, serialClone);
 979         } catch (java.io.NotSerializableException acceptable) {}
 980     }
 981 
 982     public void testReplaceAllIsNotStructuralModification() {
 983         Collection c = impl.emptyCollection();
 984         if (!(c instanceof List))
 985             return;
 986         List list = (List) c;
 987         ThreadLocalRandom rnd = ThreadLocalRandom.current();
 988         for (int n = rnd.nextInt(2, 10); n--> 0; )
 989             list.add(impl.makeElement(rnd.nextInt()));
 990         ArrayList copy = new ArrayList(list);
 991         int size = list.size(), half = size / 2;
 992         Iterator it = list.iterator();
 993         for (int i = 0; i < half; i++)
 994             assertEquals(it.next(), copy.get(i));
 995         list.replaceAll(n -> n);
 996         // ConcurrentModificationException must not be thrown here.
 997         for (int i = half; i < size; i++)
 998             assertEquals(it.next(), copy.get(i));
 999     }
1000 
1001 //     public void testCollection8DebugFail() {
1002 //         fail(impl.klazz().getSimpleName());
< prev index next >