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

(coll) AbstractList.Iterator doesn't throw expected ConcurrentModificationException

XMLWordPrintable

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



      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)
      ======================================================================

            martin Martin Buchholz
            bstrathesunw Bill Strathearn (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: