Fwd: [jdom-interest] elt.getContent().iterator().remove() - a bug?

Attila Szegedi szegedia at freemail.hu
Fri Oct 5 00:26:18 PDT 2001

> > >From the LinkedList javadoc:
> > The list-iterator is fail-fast: if the list is structurally modified at
> > time after the Iterator is created, in any way except through the
> > list-iterator's own remove or add methods, the list-iterator will throw
> > ConcurrentModificationException. Thus, in the face of concurrent
> > modification, the iterator fails quickly and cleanly, rather than
> > arbitrary, non-deterministic behavior at an undetermined time in the
> >
> > That means my iterator will stop working after
> > e.removeContent((Comment)o), ain't it?
> You may be right.

He is right, unfortunately. The irony of this is that there's no algorithmic
reason for a *linked list* to invalidate the iterator for any operation
except for the removal of the item that would be returned next. Right now,
any mutation of the list will also invalidate the iterator. Sun folks didn't
really thought it over, they just made the behavior uniform for all
collections (that is, any mutation of the collection invalidates all current
iterators except the one through which the mutation is made (if it's made
through an iterator at all)). This is reasonable for unordered collections,
but not for ordered ones where removal or addition to already-visited or
not-yet-visited parts of the iterator sequence could be tolerated.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 2848 bytes
Desc: not available
Url : http://jdom.org/pipermail/jdom-interest/attachments/20011005/b38d682a/smime.bin

More information about the jdom-interest mailing list