Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4363349

java.util.LinkedList remove in iterator did not fail fast

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.0
    • core-libs
    • None

      //In the following program with i.remove()
      //ConcurrentModificationException not thrown.

      import java.util.*;

      public class Test {
          public static void main(String[] args) throws Exception {
              List orgLinkedList = new LinkedList();
             
              for (int i=0; i<100; i++) {
                  orgLinkedList.add(new Integer(i));
              }
             
              List copyLinkedList = new LinkedList(orgLinkedList);
           
              try {
                  ListIterator i = copyLinkedList.listIterator();
                  i.next();
                  copyLinkedList.add(1,new Integer(8888));
                  i.remove();
                  //i.add(new Integer(2222));
                  throw new Exception("remove in iterator didn't fail fast");
              } catch(ConcurrentModificationException e) {
                  System.out.println("ConcurrentModificationException = " + e);
              }
          }
      }

            jjb Josh Bloch (Inactive)
            spandeorcl Shantaram Pande (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: