In my opinion, it is just RI' s implementation and it is up to you as a
developer to make the choice.:)

On 8/21/06, Spark Shen <[EMAIL PROTECTED]> wrote:

Leo Li 写道:
> If so, we cannot regard it as RI's bug. And I believe the size of 64
> and the
> existence of the deleted element depends on RI's algorithm especially it
> does not provide concurrent assurance. Maybe it is due to performance
> concerns, I am not sure.
> The curious thing is whether we should behave as RI since it says "it
> may or
> may not show the effects of any modifications to the set that occur
while
> the iteration is in progress".
>
>
So, what is your opinion? Should we follow RI on this behavior?

Best regards
> On 8/21/06, Spark Shen <[EMAIL PROTECTED]> wrote:
>>
>> Leo Li 写道:
>> > Hi, Spark:
>> > Yes, I think it is RI's bug.
>> > But It should throw ConcurrentModificationException as spec says:
>> > 1. This exception may be thrown by methods that have detected
>> > concurrent modification of an object when such modification is not
>> > permissible.
>> > 2. Note that this exception does not always indicate that an object
>> has
>> > been concurrently modified by a *different* thread. If a single
thread
>> > issues a sequence of method invocations that violates the contract
>> of an
>> > object, the object may throw this exception. For example, if a thread
>> > modifies a collection directly while it is iterating over the
>> collection
>> > with a fail-fast iterator, the iterator will throw this exception.
>> >
>> > The iterator 's remove() action relies on the result of previous
>> > next(), but is interrupted by the set.remove() method. I think it
>> is the
>> > case.
>> >
>> > Besides, If the same thing is applied to Hashset:
>> > public static void main(String[] args) {
>> > HashSet set = new HashSet();
>> > Object o = new Object();
>> > set.add(o);
>> > Iterator iter = set.iterator();
>> > iter.next();
>> > set.remove(o);
>> > iter.remove();
>> > }
>> > It will throw ConcurrentModificationException as expected.:)
>> >
>> >
>> There is a paragraph from spec clearly states that
>> ConcurrentModificationException will never be thrown out from the
>> iterator returned
>> by EnumSet. Cited below:
>> "The returned iterator is /weakly consistent/: it will never throw
>> |ConcurrentModificationException|
>> <cid:part1.01020909.06080700@gmail.com>
>> and it may or may not show the effects of any modifications to the set
>> that occur while the iteration is in progress."
>>
>> Best regards
>> > On 8/19/06, Spark Shen <[EMAIL PROTECTED]> wrote:
>> >>
>> >> Hi All:
>> >> The following behavior of RI java.util.EnumSet seems odd. Do you
have
>> >> any opinion on whether it is a bug of RI?
>> >>
>> >> import java.util.EnumSet;
>> >> import java.util.Iterator;
>> >> public class Test {
>> >> static enum EnumFoo {
>> >> a, b,
>> >> }
>> >>
>> >> public static void main(String[] args){
>> >> EnumSet<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
>> >> set.add(EnumFoo.a);
>> >> Iterator<EnumFoo> iterator = set.iterator();
>> >> iterator.next();
>> >>
>> >> set.remove(EnumFoo.a);
>> >> iterator.remove(); (1)
>> >> // The output value is true
>> >> System.out.println(set.contains(EnumFoo.a));
>> >> // The output value is 64
>> >> System.out.println(set.size());
>> >> }
>> >> }
>> >> IMHO, when (1) is executed, an IllegalStateException should be
thrown
>> >> out, since the element EnumFoo.a does not exist at the moment.
>> >> Any thoughts?
>> >>
>> >> Best regards
>> >>
>> >> --
>> >> Spark Shen
>> >> China Software Development Lab, IBM
>> >>
>> >>
>> >>
---------------------------------------------------------------------
>> >> Terms of use : http://incubator.apache.org/harmony/mailing.html
>> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> >> For additional commands, e-mail:
>> [EMAIL PROTECTED]
>> >>
>> >>
>> >
>> >
>>
>>
>> --
>> Spark Shen
>> China Software Development Lab, IBM
>>
>>
>> ---------------------------------------------------------------------
>> Terms of use : http://incubator.apache.org/harmony/mailing.html
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>
>


--
Spark Shen
China Software Development Lab, IBM


---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




--
Leo Li
China Software Development Lab, IBM

Reply via email to