harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r418844 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/HashMap.java test/java/tests/api/java/util/HashMapTest.java
Date Mon, 03 Jul 2006 20:47:39 GMT
Author: ndbeyer
Date: Mon Jul  3 13:47:39 2006
New Revision: 418844

URL: http://svn.apache.org/viewvc?rev=418844&view=rev
Log:
Apply patch and additional fixes for HARMONY-403: HashMap hashcode ignores values in entries

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

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java?rev=418844&r1=418843&r2=418844&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java
Mon Jul  3 13:47:39 2006
@@ -47,7 +47,8 @@
 
         Entry(K theKey, V theValue) {
             super(theKey, theValue);
-            this.hash = (theKey == null) ? 0 : theKey.hashCode();
+            this.hash = (theKey == null ? 0 : theKey.hashCode())
+                    ^ (theValue == null ? 0 : theValue.hashCode());
         }
 
         @Override
@@ -523,8 +524,11 @@
                 index = key == null ? 0 : (key.hashCode() & 0x7FFFFFFF)
                         % elementData.length;
             }
-            entry = createEntry(key, index, null);
+            entry = createEntry(key, index, value);
+            //new entry, so nothing is replaced
+            return null;
         }
+        
         V result = entry.value;
         entry.value = value;
         return result;

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/HashMapTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/HashMapTest.java?rev=418844&r1=418843&r2=418844&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/HashMapTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/HashMapTest.java
Mon Jul  3 13:47:39 2006
@@ -409,6 +409,20 @@
 			return key == ((ReusableKey) o).key;
 		}
 	}
+    
+    public void test_hashCode() {
+        HashMap map = new HashMap(10);
+        Integer key = new Integer(1);
+        Integer val = new Integer(2);
+        map.put(key, val);
+        int expected = key.hashCode() ^ val.hashCode();
+        assertEquals(expected, map.hashCode());
+        key = new Integer(4);
+        val = new Integer(8);
+        map.put(key, val);
+        expected += key.hashCode() ^ val.hashCode();
+        assertEquals(expected, map.hashCode());
+    } 
 	
 	/**
 	 * Sets up the fixture, for example, open a network connection. This method



Mime
View raw message