Return-Path: Delivered-To: apmail-incubator-harmony-dev-archive@www.apache.org Received: (qmail 69361 invoked from network); 21 Aug 2006 06:11:17 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 21 Aug 2006 06:11:17 -0000 Received: (qmail 73143 invoked by uid 500); 21 Aug 2006 06:11:15 -0000 Delivered-To: apmail-incubator-harmony-dev-archive@incubator.apache.org Received: (qmail 73100 invoked by uid 500); 21 Aug 2006 06:11:15 -0000 Mailing-List: contact harmony-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: harmony-dev@incubator.apache.org Delivered-To: mailing list harmony-dev@incubator.apache.org Received: (qmail 73084 invoked by uid 99); 21 Aug 2006 06:11:14 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 20 Aug 2006 23:11:14 -0700 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=DNS_FROM_RFC_ABUSE,HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of liyilei1979@gmail.com designates 66.249.92.173 as permitted sender) Received: from [66.249.92.173] (HELO ug-out-1314.google.com) (66.249.92.173) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 20 Aug 2006 23:11:13 -0700 Received: by ug-out-1314.google.com with SMTP id u40so1475905ugc for ; Sun, 20 Aug 2006 23:10:52 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=hUeleZxuiDilgZ3oUp3Q/81m/2dVvhjqWp785F5dDVeWGMtI7cshb+fTqREutskzt01pPblSY7XRBHLVuSOzg1RBoLzOhHh7nf10pdtJhOii6EMKv4k36Rlj3rIYhzfztKIE+JsIWzKRHphYzZNIHPlxhDuoL3q+g0Sm9kPqPi0= Received: by 10.66.222.9 with SMTP id u9mr3388557ugg; Sun, 20 Aug 2006 23:10:52 -0700 (PDT) Received: by 10.67.29.6 with HTTP; Sun, 20 Aug 2006 23:10:51 -0700 (PDT) Message-ID: Date: Mon, 21 Aug 2006 14:10:51 +0800 From: "Leo Li" To: harmony-dev@incubator.apache.org Subject: Re: [classlib][luni] Suspicious behavior of java.util.EnumSet In-Reply-To: <44E93CFB.1010801@gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_42003_24606380.1156140651995" References: <44E6D04B.5000401@gmail.com> <44E93CFB.1010801@gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N ------=_Part_42003_24606380.1156140651995 Content-Type: text/plain; charset=ISO-2022-JP; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline 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". On 8/21/06, Spark Shen 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| > 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 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 set = EnumSet.noneOf(EnumFoo.class); > >> set.add(EnumFoo.a); > >> Iterator 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 > >> > >> > > > > > > > -- > 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 ------=_Part_42003_24606380.1156140651995--