Return-Path: Delivered-To: apmail-harmony-dev-archive@www.apache.org Received: (qmail 76106 invoked from network); 9 Oct 2009 07:48:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 9 Oct 2009 07:48:11 -0000 Received: (qmail 87944 invoked by uid 500); 9 Oct 2009 07:48:11 -0000 Delivered-To: apmail-harmony-dev-archive@harmony.apache.org Received: (qmail 87872 invoked by uid 500); 9 Oct 2009 07:48:10 -0000 Mailing-List: contact dev-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list dev@harmony.apache.org Received: (qmail 87852 invoked by uid 99); 9 Oct 2009 07:48:10 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Oct 2009 07:48:10 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of t.p.ellison@gmail.com designates 72.14.220.159 as permitted sender) Received: from [72.14.220.159] (HELO fg-out-1718.google.com) (72.14.220.159) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Oct 2009 07:47:59 +0000 Received: by fg-out-1718.google.com with SMTP id e12so2103187fga.0 for ; Fri, 09 Oct 2009 00:47:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :x-enigmail-version:content-type:content-transfer-encoding; bh=+v3Qkww3J8GCq1aAHDw0n5Y1eZLDru+6AVYb0DyGDfY=; b=RU2JxXQjnSQCQ1VqHk58khH89OQFcjKTnw2X2nRgUyZxTuIGWNnh3yyO5KsytFTfv1 dDS8vfpI+rA+0ErqWKSYOb/kxlVrQd8hhySOuGjmQl7k0d3A3dLPPOvjIJsV+5XNzxaT xZQgGo/ibXsoVgPwoQ3Ofsb4TibvCf74Lzivs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; b=Phq7rU468l/u0yrD2Jzo3usFbMU7eIkSdRfjBWixf9ino9/CgOpjZmxnMq4GtQ01tD 6H/UkvfjUbPS2WkyUqGgaFk4UiWAki+10pDjTpYaeoyH82Qa4HOwKLePVDyrV0RQcXGE vpcLUsn7WTPwQNFf1Z4ywszUEuStbc1C1FVrg= Received: by 10.86.230.30 with SMTP id c30mr2094919fgh.68.1255074459658; Fri, 09 Oct 2009 00:47:39 -0700 (PDT) Received: from ?9.20.183.187? (blueice4n2.uk.ibm.com [195.212.29.92]) by mx.google.com with ESMTPS id 3sm1686890fge.26.2009.10.09.00.47.38 (version=SSLv3 cipher=RC4-MD5); Fri, 09 Oct 2009 00:47:38 -0700 (PDT) Message-ID: <4ACEEA99.4040704@gmail.com> Date: Fri, 09 Oct 2009 08:47:37 +0100 From: Tim Ellison User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 To: dev@harmony.apache.org Subject: Re: svn commit: r823222 - /harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/PrivateCredentialPermission.java References: <4acec9f1.47c1f10a.129c.764b@mx.google.com> In-Reply-To: <4acec9f1.47c1f10a.129c.764b@mx.google.com> X-Enigmail-Version: 0.96.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org On 09/Oct/2009 06:28, Ramana Polavarapu wrote: > It appears that Bloch suggests that we should have the following first: > if (!(object instanceof CredOwner)) return false; > Then, we can skip this check: > if (object instanceof CredOwner) That is pretty much what Jesse wrote. Ok you inverted the instance check...but it is equivalent in performance and behavior @Override public boolean equals(Object object) { if (object == this) { return true; } if (!(object instanceof CredOwner)) { return false; } CredOwner that = (CredOwner) object; return principalClass.equals(that.principalClass) && principalName.equals(that.principalName); } Regards, Tim > -----Original Message----- > From: Jesse Wilson [mailto:jessewilson@google.com] > Sent: Friday, October 09, 2009 9:00 AM > To: dev@harmony.apache.org > Subject: Re: svn commit: r823222 - > /harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/sec > urity/auth/PrivateCredentialPermission.java > > On Thu, Oct 8, 2009 at 9:31 AM, wrote: > >> Add null check to equals() method. > > > > // Checks two CredOwner objects for equality. >> @Override >> public boolean equals(Object obj) { >> + if (obj == null) { >> + return false; >> + } >> return principalClass.equals(((CredOwner) obj).principalClass) >> && principalName.equals(((CredOwner) >> obj).principalName); >> } >> > > > Does Harmony have a standard idiom for equals methods? I don't think the > equals() method above is particularly awesome. It can throw > ClassCastExceptions and performs extra casts. > > As a straw man suggestion, I propose the following control flow as our > standard idiom: > > @Override public boolean equals(Object object) { > if (object == this) { > return true; > } > if (object instanceof CredOwner) { > CredOwner that = (CredOwner) object; > return principalClass.equals(that.principalClass) > && principalName.equals(that.principalName); > } > return false; > } > > > It seems like a natural performance, correctness and consistency win to > figure out a good way to implement equals() and hashCode(), and then to do > that everywhere in the project. > > Of course, we would first prefer to be consistent with the RI, such as > implementing equals to spec when it is specified (as in Set.java) or not at > all for reference types like AtomicInteger. > > Comments? > >