Return-Path: Delivered-To: apmail-incubator-harmony-dev-archive@www.apache.org Received: (qmail 88328 invoked from network); 21 Sep 2006 02:43:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 21 Sep 2006 02:43:50 -0000 Received: (qmail 54593 invoked by uid 500); 21 Sep 2006 02:43:47 -0000 Delivered-To: apmail-incubator-harmony-dev-archive@incubator.apache.org Received: (qmail 54471 invoked by uid 500); 21 Sep 2006 02:43:47 -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 54460 invoked by uid 99); 21 Sep 2006 02:43:47 -0000 Received: from idunn.apache.osuosl.org (HELO idunn.apache.osuosl.org) (140.211.166.84) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Sep 2006 19:43:47 -0700 Authentication-Results: idunn.apache.osuosl.org smtp.mail=smallsmallorgan@gmail.com; spf=unknown X-ASF-Spam-Status: No, hits=0.4 required=5.0 tests=DNS_FROM_RFC_ABUSE Received-SPF: unknown (idunn.apache.osuosl.org: domain gmail.com does not designate 202.81.18.152 as permitted sender) Received: from [202.81.18.152] ([202.81.18.152:45179] helo=ausmtp04.au.ibm.com) by idunn.apache.osuosl.org (ecelerity 2.1.1.8 r(12930)) with ESMTP id 8C/D8-04092-C5CF1154 for ; Wed, 20 Sep 2006 19:43:41 -0700 Received: from sd0208e0.au.ibm.com (d23rh904.au.ibm.com [202.81.18.202]) by ausmtp04.au.ibm.com (8.13.6/8.13.5) with ESMTP id k8L2pWnH180804 for ; Thu, 21 Sep 2006 12:51:38 +1000 Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.250.244]) by sd0208e0.au.ibm.com (8.13.6/8.13.6/NCO v8.1.1) with ESMTP id k8L2kPTx093142 for ; Thu, 21 Sep 2006 12:46:25 +1000 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id k8L2h0Yx018047 for ; Thu, 21 Sep 2006 12:43:00 +1000 Received: from d23m0011.cn.ibm.com (d23m0011.cn.ibm.com [9.181.32.74]) by d23av03.au.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id k8L2gxkE018003 for ; Thu, 21 Sep 2006 12:42:59 +1000 Received: from [9.181.106.234] ([9.181.106.234]) by d23m0011.cn.ibm.com (Lotus Domino Release 6.5.5HF262) with ESMTP id 2006092110414523-2203 ; Thu, 21 Sep 2006 10:41:45 +0800 Message-ID: <4511FC2B.3010507@gmail.com> Date: Thu, 21 Sep 2006 10:42:51 +0800 From: Spark Shen User-Agent: Thunderbird 1.5.0.7 (Windows/20060909) MIME-Version: 1.0 To: harmony-dev@incubator.apache.org Subject: Re: [classlib][luni] JIRA 1492 Constructor of HashMap throw unexpected exception References: <009501c6dd16$2fda9130$0201a8c0@LITTLEGUY> In-Reply-To: <009501c6dd16$2fda9130$0201a8c0@LITTLEGUY> X-MIMETrack: Itemize by SMTP Server on D23M0011/23/M/IBM(Release 6.5.5HF262 | April 5, 2006) at 21/09/2006 10:41:45, Serialize by Router on D23M0011/23/M/IBM(Release 6.5.5HF262 | April 5, 2006) at 21/09/2006 10:41:47, Serialize complete at 21/09/2006 10:41:47 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-2022-JP X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Nathan Beyer 写道: > I'm still waiting to see a real and non-trivial piece of code that does > this. Does anyone have one? > > I don't disagree with the various comments about class design, but this > seems indicative of a larger problem with the entire implementation. > > -Nathan > Hi Nathan: Thank you for your agreement. :-) Can I conclude that you do think this may be a design pitfall and will bring potential problem. Best regards > >> -----Original Message----- >> From: Andrew Zhang [mailto:zhanghuangzhu@gmail.com] >> Sent: Wednesday, September 20, 2006 3:28 AM >> To: harmony-dev@incubator.apache.org >> Subject: Re: [classlib][luni] JIRA 1492 Constructor of HashMap throw >> unexpected exception >> >> Josh Bloch has given an excellent comment on this issue in his famouse >> book "effective java", item 15 "Design and document for inheritance or >> else >> prohibit it". >> [quote from "effective java"] >> There are a few more restrictions that a class must obey to allow >> inheritance. Constructors >> must not invoke overridable methods, directly or indirectly. If this rule >> is >> violated, it is >> likely that program failure will result. The superclass constructor runs >> before the subclass >> constructor, so the overriding method in the subclass will get invoked >> before the subclass >> constructor has run. If the overriding method depends on any >> initialization >> performed by the >> subclass constructor, then the method will not behave as expected. >> [/quote] >> >> So I'd like to agree with Paulex that we'd better fix this problem. :-) >> >> >> On 9/20/06, Alexey Petrenko wrote: >> >>> Are you trying to say that the methods in Harmony can use only methods >>> used in corresponding RI implementations? >>> >>> 2006/9/20, Spark Shen : >>> >>>> Spark Shen 写道: >>>> >>>>> Hi : >>>>> Following is the discussion about JIRA 1492, shall we discuss it >>>>> >> here? >> >>>>> public class SubMapTest extends TestCase { >>>>> public void testSubclass() { >>>>> HashMap map = new HashMap(); >>>>> map.put("a", "a"); >>>>> SubMap map2 = new SubMap(map); // Harmony will throw an unexpected >>>>> exception here. >>>>> } >>>>> } >>>>> >>>>> class SubMap extends HashMap { >>>>> >>>>> public V put(K key, V value) { >>>>> throw new RuntimeException(); >>>>> } >>>>> } >>>>> >>>>> >>>>> >>>>>> Nathan Beyer >>>>>> Harmony's behavior may be different in this case, but I'm not sure >>>>>> >> I >> >>>>> would consider this a valid issue. What's a real use case for this >>>>> type of sub-classing? >>>>> [ Show ≫ ] >>>>> Nathan Beyer >>>>> >>>>> [18/Sep/06 08:41 PM] Harmony's behavior may be different in this >>>>> >> case, >> >>>>> but I'm not sure I would consider this a valid issue. What's a real >>>>> use case for this type of sub-classing? >>>>> >>>>> >>>>> >> > >>>>> Spark >>>>> Shen >>>>> >>>>>> What if change the RuntimeException to >>>>>> >> UnsupportedOperationException? >> >>>>> [ Show ≫ ] >>>>> spark shen >>>>> >>>>> >> > >>>>> [18/Sep/06 08:48 PM] What if change the RuntimeException to >>>>> UnsupportedOperationException? >>>>> >>>>> >>>>>> Alexey Petrenko >>>>>> I'm not sure that this is a valid issue to. >>>>>> As far as I understood the issue is that Harmony calls put method >>>>>> >> in >> >>>>> constructor while RI does not. Right? >>>>> >>>>> >>>>>> If so I do not see any issue here. >>>>>> >>>> I can not figure out what RI does. And please refer to JIRA 839, it >>>> reports similar use case. >>>> My point here is >>>> 1. we may not be able to predict how users will use our library. >>>> 2. Users could guess our implementation w/o difficulty, which >>>> contradicts the encapulation priciple. >>>> So I prefer to follow RI on this behavior. >>>> >>>> When changing to UnsupportedOperationException, the use case is more >>>> practical, since it is highly like that put operation is not >>>> >> supported. >> >>>> But it seems not so practical that this sub-hashMap can not be >>>> instantiated. May be one more assertion can convince you that this is >>>> >>> bug. >>> >>>> public class SubMapTest extends TestCase { >>>> public void testSubclass() { >>>> HashMap map = new HashMap(); >>>> map.put("a", "a"); >>>> SubMap map2 = new SubMap(map); >>>> assertEquals(1, map2.size()); >>>> } >>>> } >>>> >>>> class SubMap extends HashMap { >>>> public SubMap(Map m) { >>>> super(m); >>>> } >>>> >>>> public V put(K key, V value) { >>>> throw new RuntimeException(); >>>> } >>>> } >>>> >>>> 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 >>>> >>>> >>>> >>> -- >>> Alexey A. Petrenko >>> Intel Middleware Products Division >>> >>> >> >> -- >> Andrew Zhang >> 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