Hi,

I've added the information below to the bug report for you.

David

On 11/08/2015 2:13 PM, Cyrille Artho wrote:
Dear all,
I'd like to write a response to my bug report at
https://bugs.openjdk.java.net/browse/JDK-8114832
but I didn't get an OpenJDK login when I submitted the report.

In this particular case, it should be noted that my test was minimal. If
one has at least one element in the list before the iterator is created,
then it.next() throws no exception when used on any collection except
ArrayList/Stack/Vector.

This means that ArrayList and its legacy brethren are the only classes
that generate a spurious exception, and only after list.remove(-1) was
called before using the iterator. The spurious exception prevents future
access to data where other containers work as expected.

Currently it is being considered to keep the current (faulty) behavior,
but based on the new test case, I strongly advise correcting this bug.

With the new test case, the information about the bug becomes:

EXPECTED -
it.next() returns 42
ACTUAL -
ConcurrentModificationException

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.NoSuchElementException;

public class iterator_test {
    public static void main(String[] argv) {
      /* BUG: Sequence of arrayList.iterator,
         arrayList.add(new Integer(1)),
         arrayList.remove(-1),
         iterator.next
         produces ConcurrentModificationException. */
      ArrayList<Integer> testArrayList = new ArrayList<Integer>();
      testArrayList.add(new Integer(42));
      Iterator<Integer> it = testArrayList.iterator();
      try {
        testArrayList.remove(-1);
      } catch (IndexOutOfBoundsException e) {
      }
      try {
        Integer result = it.next();
        assert(result == 42);
      } catch (ConcurrentModificationException e) {
        System.err.println("Should be 42!");
      }
    }
}

---------- END SOURCE ----------

Reply via email to