Return-Path: Delivered-To: apmail-incubator-harmony-dev-archive@www.apache.org Received: (qmail 84787 invoked from network); 15 Mar 2006 09:12:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 15 Mar 2006 09:12:53 -0000 Received: (qmail 94937 invoked by uid 500); 15 Mar 2006 09:12:45 -0000 Delivered-To: apmail-incubator-harmony-dev-archive@incubator.apache.org Received: (qmail 94476 invoked by uid 500); 15 Mar 2006 09:12:43 -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 94465 invoked by uid 99); 15 Mar 2006 09:12:43 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Mar 2006 01:12:43 -0800 X-ASF-Spam-Status: No, hits=1.4 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (asf.osuosl.org: 32.97.182.145 is neither permitted nor denied by domain of paulex.yang@gmail.com) Received: from [32.97.182.145] (HELO e5.ny.us.ibm.com) (32.97.182.145) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Mar 2006 01:12:43 -0800 Received: from sd0208e0.au.ibm.com (d23rh904.au.ibm.com [9.190.250.241]) by e5.ny.us.ibm.com (8.12.11/8.12.11) with ESMTP id k2F9CJKc006398 for ; Wed, 15 Mar 2006 04:12:20 -0500 Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.250.244]) by sd0208e0.au.ibm.com (8.12.10/NCO/VER6.8) with ESMTP id k2F9FRC0234816 for ; Wed, 15 Mar 2006 20:15:38 +1100 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.12.11/8.13.3) with ESMTP id k2F9C89r023968 for ; Wed, 15 Mar 2006 20:12:08 +1100 Received: from d23m0011.cn.ibm.com (d23m0011.cn.ibm.com [9.181.32.74]) by d23av03.au.ibm.com (8.12.11/8.12.11) with ESMTP id k2F9C8Sd023952 for ; Wed, 15 Mar 2006 20:12:08 +1100 Received: from [127.0.0.1] ([9.181.106.208]) by d23m0011.cn.ibm.com (Lotus Domino Release 6.53HF294) with ESMTP id 2006031517120037-16818 ; Wed, 15 Mar 2006 17:12:00 +0800 Message-ID: <4417DA0F.40607@gmail.com> Date: Wed, 15 Mar 2006 17:10:39 +0800 From: Paulex Yang User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 To: harmony-dev@incubator.apache.org Subject: [classlib]bug-to-bug compatibility: HashMap X-MIMETrack: Itemize by SMTP Server on D23M0011/23/M/IBM(Release 6.53HF294 | January 28, 2005) at 15/03/2006 17:12:00, Serialize by Router on D23M0011/23/M/IBM(Release 6.53HF294 | January 28, 2005) at 15/03/2006 17:12:08, Serialize complete at 15/03/2006 17:12:08 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=GB18030; format=flowed X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Pls. try the test case on HashMap below. On RI, it print out: null null On Harmony, it print out null value1 it is definitely bad practice to reuse a object as hash key by modify its hashcode, but I DID see some similar cases before, after all, you cannot force but only can *suggest* developers what to do. So, what should we do? Try to replicate RI's behavior? public class HashMapTest { public static void main(String[] args) { ReusableKey k = new ReusableKey(); HashMap map = new HashMap(); k.setKey(1); map.put(k, "value1"); k.setKey(18); //both RI and Harmony get null here System.out.println(map.get(k)); k.setKey(17); //RI get null //Harmony get "value1" //the number of 17 is *magic* because the default length of HashMap is 16. System.out.println(map.get(k)); } } class ReusableKey{ private int key = 0; public void setKey(int key){ this.key = key; } public int hashCode(){ return key; } public boolean equals(Object o){ if(o == this){ return true; } if(!(o instanceof ReusableKey)){ return false; } return key == ((ReusableKey)o).key; } } -- Paulex Yang China Software Development Lab IBM