JDK-4460107 : (coll) AbstractList.Iterator doesn't throw expected ConcurrentModificationException
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2001-05-17
  • Updated: 2012-10-08
  • Resolved: 2007-03-18
Related Reports
Duplicate :  
Description

Name: bsC130419			Date: 05/17/2001


java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)


There is a problem with Iterator in Vector (AbstractList) - that iterator not
always throws ConcurrentModificationException, as it should.
Example source code shows it clearly:

import java.util.*;

public class IteratorTest {

  interface Worker {
    public void close();
  };

  interface Manager {
    public void remove(Worker w);
  }

  class ManagerImpl implements Manager {
    private Vector _vector;

    ManagerImpl(Vector v) { _vector = v; }
    public void remove(Worker w) { _vector.remove(w); }
  }


  class SimpleObject implements Worker {
    private int _i;
    private Manager _manager;

    SimpleObject(int i, Manager m) {
      this._i = i;
      this._manager = m;
      System.out.println("created " + i);
    }

    public void close() {
      System.out.println("closing " + _i);
      _manager.remove(this);
    }

  }


  public static void main(String[] args) {
    new IteratorTest(2);
    // almost everything ok, besides only one element is 'closed'
    // and the most important: no ConcurrentModificationException !

    System.out.println();

    new IteratorTest(3);
    // fails, becouse of ConcurrentModificationException - so OK - as expected.
  }

  IteratorTest(int n) {
    Vector v = new Vector();
    Manager m = new ManagerImpl(v);

    for(int j = 0; j < n; ++j)
      v.add( new SimpleObject( j+1, m ) );

    for(Iterator i = v.iterator(); i.hasNext(); ) {
      Worker w = (Worker) i.next();
      w.close();
    }

  }
}
(Review ID: 124539) 
======================================================================

Comments
EVALUATION This appears to be a dup of 4902078: concurrent modification not detected on 2nd to last iteration which Sun chose not to fix. See the evaluation of 4902078
18-03-2007