Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 80237 invoked from network); 19 Jun 2009 05:53:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 19 Jun 2009 05:53:19 -0000 Received: (qmail 91473 invoked by uid 500); 19 Jun 2009 05:53:30 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 91402 invoked by uid 500); 19 Jun 2009 05:53:30 -0000 Mailing-List: contact commits-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 commits@harmony.apache.org Received: (qmail 91393 invoked by uid 99); 19 Jun 2009 05:53:30 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Jun 2009 05:53:30 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Jun 2009 05:53:27 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 82E39234C044 for ; Thu, 18 Jun 2009 22:53:07 -0700 (PDT) Message-ID: <1068419787.1245390787521.JavaMail.jira@brutus> Date: Thu, 18 Jun 2009 22:53:07 -0700 (PDT) From: "Jim Yu (JIRA)" To: commits@harmony.apache.org Subject: [jira] Commented: (HARMONY-6237) [classlib][luni] HashMap doesn't support proxy object as keys In-Reply-To: <397479170.1245306010540.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/HARMONY-6237?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12721664#action_12721664 ] Jim Yu commented on HARMONY-6237: --------------------------------- Thanks, Regis. Verified at r786379. > [classlib][luni] HashMap doesn't support proxy object as keys > ------------------------------------------------------------- > > Key: HARMONY-6237 > URL: https://issues.apache.org/jira/browse/HARMONY-6237 > Project: Harmony > Issue Type: Bug > Components: Classlib > Affects Versions: 5.0M10 > Reporter: Jim Yu > Assignee: Regis Xu > Fix For: 5.0M11 > > Attachments: HARMONY-6237.diff > > Original Estimate: 48h > Remaining Estimate: 48h > > There is an interesting edge case in HashMap. If we use a proxy object as the key to put something into HashMap, we will fail to retrieve the value by using that key. But RI works well for this case. Here is a test case below to present the problem. I found the root cause of the failure for Harmony HashMap is that proxyInstance.equals(proxyInstance) returns false which sounds strange but appears work correctly as both Harmony and RI behave so. I suspect RI has made some special approaches to match the key when the key is a proxy object. So I would be inclined to follow RI's behavior in this case. > public interface MockInterface { > public String mockMethod(); > } > public class MockClass implements MockInterface { > public String mockMethod() { > return "This is a mock class."; > } > } > import java.lang.reflect.InvocationHandler; > import java.lang.reflect.Method; > import java.lang.reflect.Proxy; > import java.util.HashMap; > import java.util.Map; > public class TestProxy implements InvocationHandler { > Object obj; > public TestProxy(Object o) { > obj = o; > } > public Object invoke(Object proxy, Method m, Object[] args) > throws Throwable { > Object result = null; > try { > result = m.invoke(obj, args); > } catch (Exception e) { > e.printStackTrace(); > } finally { > } > return result; > } > public static void main(String[] argv) throws Exception { > MockInterface proxyInstance = (MockInterface) Proxy.newProxyInstance( > MockInterface.class.getClassLoader(), > new Class[] { MockInterface.class }, new TestProxy( > new MockClass())); > Map hm = new HashMap(); > hm.put(proxyInstance, "Value"); > Object o = hm.get(proxyInstance); > System.out.println("Value got for proxy object key:" + o); > System.out.println(proxyInstance.equals(proxyInstance)); > } > } > Output > Harmony: > Value got for proxy object key:null > false > RI: > Value got for proxy object key:Value > false -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.