commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael A. Smith" <...@apache.org>
Subject Re: [Collections] Bug or Feature? - SequencedHashMap iterators do not throw ConcurrentModificationExceptions
Date Wed, 08 May 2002 19:42:07 GMT
On Wed, 8 May 2002, Morgan Delagrange wrote:
> Making a modification-resistant iterator might be a
> little tricky.  E.g. what happens when, while
> iterating over a keySet, you iterate a, then remove a,
> and readd it later in the iteration?  A set iteration 
> with duplicates?  :)

yes, definately a bug.  

> > I assume your get looks like this:
> > 
> >   public Object get(Object key) {
> >     // need explicit check for contains so we don't
> > add in a mapping to
> >     // null if a mapping to null didn't exist
> > before.
> >     if(!contains(key)) return null;
> > 
> >     Object value = remove(key);
> >     put(key, value);
> > 
> >     return value;
> >   }
> 
> Yep, except that the containsKey() check is still in
> my notes, not in CVS.

I'll add it.  :)

> > and something is iterating and calling get within
> > the iterator...  
> 
> Right, it's the testSequenceMap test in your
> TestSequencedHashMap class.  I overrode it in my
> TestHashMap subclass just to avoid the infinite loop;
> you'll want to comment my override out.

ok.

michael


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message