harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From regi...@apache.org
Subject svn commit: r786015 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/HashMap.java test/api/common/org/apache/harmony/luni/tests/java/util/HashMapTest.java
Date Thu, 18 Jun 2009 11:01:37 GMT
Author: regisxu
Date: Thu Jun 18 11:01:36 2009
New Revision: 786015

URL: http://svn.apache.org/viewvc?rev=786015&view=rev
Log:
Apply patch for HARMONY-6237: [classlib][luni] HashMap doesn't support proxy object as keys

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/HashMapTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java?rev=786015&r1=786014&r2=786015&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java Thu
Jun 18 11:01:36 2009
@@ -21,6 +21,7 @@
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
+import java.lang.reflect.Proxy;
 
 /**
  * HashMap is an implementation of Map. All optional operations (adding and
@@ -480,8 +481,16 @@
 
     final Entry<K,V> findNonNullKeyEntry(Object key, int index, int keyHash) {
         Entry<K,V> m = elementData[index];
-        while (m != null && (m.origKeyHash != keyHash || !areEqualKeys(key, m.key)))
{
-            m = m.next;
+        // To support proxy instance as keys
+        if (Proxy.isProxyClass(key.getClass())) {
+            while (m != null && (m.origKeyHash != keyHash || key != m.key)) {
+                m = m.next;
+            }
+        } else {
+            while (m != null
+                    && (m.origKeyHash != keyHash || !key.equals(m.key))) {
+                m = m.next;
+            }
         }
         return m;
     }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/HashMapTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/HashMapTest.java?rev=786015&r1=786014&r2=786015&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/HashMapTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/HashMapTest.java
Thu Jun 18 11:01:36 2009
@@ -17,6 +17,9 @@
 
 package org.apache.harmony.luni.tests.java.util;
 
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
 import java.util.AbstractMap;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -53,6 +56,44 @@
         }
     }
     
+    interface MockInterface {
+        public String mockMethod();
+    }
+
+    class MockClass implements MockInterface {
+        public String mockMethod() {
+            return "This is a MockClass";
+        }
+    }
+
+    class MockHandler implements InvocationHandler {
+
+        Object obj;
+
+        public MockHandler(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;
+        }
+
+    }
+
+
 	HashMap hm;
 
 	final static int hmSize = 1000;
@@ -296,6 +337,17 @@
 
 		k.setKey(17);
 		assertNull(map.get(k));
+
+        // Regression for HARMONY-6237
+        MockInterface proxyInstance = (MockInterface) Proxy.newProxyInstance(
+                MockInterface.class.getClassLoader(),
+                new Class[] { MockInterface.class }, new MockHandler(
+                        new MockClass()));
+
+        hm.put(proxyInstance, "value2");
+
+        assertEquals("Failed with proxy object key", "value2", hm
+                .get(proxyInstance));
 	}
 
 	/**



Mime
View raw message