JDK-7014637 : Improve behavior of EnumSet Iterator.remove()
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-01-25
  • Updated: 2019-07-10
  • Resolved: 2011-04-27
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b136Fixed
Related Reports
Relates :  
Description
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

Comments
PUBLIC COMMENTS Committed as : http://hg.openjdk.java.net/jdk7/tl-gate/jdk/rev/7d1b13126574
15-03-2011

SUGGESTED FIX Webrev posted to http://cr.openjdk.java.net/~mduigou/7014637/webrev.00/webrev/
25-01-2011

EVALUATION Neil has provided a patch.
25-01-2011