-
Bug
-
Resolution: Fixed
-
P4
-
7
-
b136
-
generic
-
generic
-
Verified
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
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
- relates to
-
JDK-7028133 RegularEnumSet serialVersionUID changed, causes test/java/util/EnumSet/BogusEnumSet.java to fail
- Closed