harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leo Li" <liyilei1...@gmail.com>
Subject Re: [classlib][luni] Suspicious behavior of java.util.EnumSet
Date Mon, 21 Aug 2006 03:24:29 GMT
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.:)


On 8/19/06, Spark Shen <smallsmallorgan@gmail.com> 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: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>
>


-- 
Leo Li
China Software Development Lab, IBM

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message