harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Spark Shen <smallsmallor...@gmail.com>
Subject Re: [classlib][luni] Suspicious behavior of java.util.EnumSet
Date Mon, 21 Aug 2006 04:09:51 GMT
Jimmy, Jing Lv 写道:
> Spark Shen 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
>>
>
> Not very familiar with Enumset, but I think it is strange behavior 
> caused by iterator
Agree.
>
> This test can pass on RI
> void test{
> EnumSet<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
> set.add(EnumFoo.a);
> assertTrue(set.size() == 1);
> assertTrue(set.remove(EnumFoo.a));
> assertTrue(set.size() == 0);
> assertFalse(set.remove(EnumFoo.a));
> assertFalse(set.contains(EnumFoo.a));
> }
>
> Without Iterator influence, the EnumSet behave well. I think better to 
> focus on how iterator works there.
But, do you agree to following RI on this strange behavior? Personally, 
I think throw an IllegalStateException here is more appropriate.

Best regards

-- 
Spark Shen
China Software Development Lab, IBM


---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Mime
View raw message