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

Neil Richards neil.richards at
Tue Jan 25 14:28:36 UTC 2011

The Javadoc for java.util.Iterator.remove() states that the behaviour
of the method is "unspecified" if the underlying collection has been

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

Unless stated above:
IBM email: neil_richards at
IBM United Kingdom Limited - Registered in England and Wales with number 741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
-------------- next part --------------
A non-text attachment was scrubbed...
Type: application/zip
Size: 92460 bytes
Desc: not available
URL: <>

More information about the core-libs-dev mailing list