You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Regis Xu (JIRA)" <ji...@apache.org> on 2009/06/18 13:05:07 UTC
[jira] Resolved: (HARMONY-6237) [classlib][luni] HashMap doesn't
support proxy object as keys
[ https://issues.apache.org/jira/browse/HARMONY-6237?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Regis Xu resolved HARMONY-6237.
-------------------------------
Resolution: Fixed
Thanks Jim.
Patch applied at r786015, please verify.
> [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.