-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.3.0
-
x86
-
windows_nt
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)
======================================================================
- duplicates
-
JDK-4902078 concurrent modification not detected on 2nd to last iteration
-
- Closed
-