Making java.util.Iterator.remove() for the iterators for EnumSet more resilient

Mike Duigou mike.duigou at oracle.com
Tue Jan 25 19:24:32 UTC 2011


Hi Neil;

This sounds like an excellent suggestion and the changes look good to me. I have created an RFE change request (CR# 7014637) and posted the webrev at cr.openjdk.java.net:

http://cr.openjdk.java.net/~mduigou/7014637/webrev.00/webrev/

Mike

On Jan 25 2011, at 06:28 , Neil Richards wrote:

> The Javadoc for java.util.Iterator.remove() states that the behaviour
> of the method is "unspecified" if the underlying collection has been
> modified.
> 
> Ideally, Iterator.remove() would be resilient - which is to say, it
> would not modify the underlying collection if the element to be
> removed has already been removed from the collection.
> 
> In the general case, I can see the rationale behind the Javadoc
> defining things the way they are - it would be overly onerous to
> require resilient behaviour on iterators for all types of collection.
> 
> However, in the specific case of the iterators for java.util.EnumSet,
> I believe it is simple to implement them such that their remove()
> method does behave in the resilient manner described above.
> 
> Given that it's basicaly as easy for these to behave resiliently as
> for them not to, I believe to would be beneficial to change them to be
> resilient in this fashion.
> 
> To that end, please find attached a zip file containing a webrev which
> modifies the Iterators for EnumSet (specifically
> java.util.RegularEnumSet.EnumSetIterator and
> java.util.JumboEnumSet.EnumSetIterator) so that they are resilient,
> together with a couple of testcases to demonstrate the enhancement.
> 
> I have searched the Java Bug Database, but have not found a bug (or
> RFE) relating to this item.
> Therefore, I'm unsure if I should raise an RFE for it there or in the
> OpenJDK bugzilla.
> 
> As always, any comments, queries or guidance on any of the above
> gratefully received.
> 
> - Neil




More information about the core-libs-dev mailing list