harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r774711 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/IdentityHashMap.java test/api/common/org/apache/harmony/luni/tests/java/util/IdentityHashMapTest.java
Date Thu, 14 May 2009 09:56:38 GMT
Author: sjanuary
Date: Thu May 14 09:56:38 2009
New Revision: 774711

URL: http://svn.apache.org/viewvc?rev=774711&view=rev
Log:
Apply patch for HARMONY-6205 ([classlib][luni] java.util.IdentityHashMap.clone() should return
a shallow copy of this identity hash map)

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

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/IdentityHashMap.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/IdentityHashMap.java?rev=774711&r1=774710&r2=774711&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/IdentityHashMap.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/IdentityHashMap.java
Thu May 14 09:56:38 2009
@@ -748,7 +748,12 @@
     @Override
     public Object clone() {
         try {
-            return super.clone();
+            IdentityHashMap<K, V> cloneHashMap = (IdentityHashMap<K, V>) super
+                    .clone();
+            cloneHashMap.elementData = newElementArray(elementData.length);
+            System.arraycopy(elementData, 0, cloneHashMap.elementData, 0,
+                    elementData.length);
+            return cloneHashMap;
         } catch (CloneNotSupportedException e) {
             return null;
         }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/IdentityHashMapTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/IdentityHashMapTest.java?rev=774711&r1=774710&r2=774711&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/IdentityHashMapTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/IdentityHashMapTest.java
Thu May 14 09:56:38 2009
@@ -357,6 +357,59 @@
 				.equals(newset));
 	}
 
+    public void test_clone_scenario1() {
+        IdentityHashMap hashMap = new IdentityHashMap();
+        assertEquals(0, hashMap.hashCode());
+        Object cloneHashMap = hashMap.clone();
+        ((IdentityHashMap) cloneHashMap).put("key", "value");
+        assertEquals(0, hashMap.hashCode());
+        assertTrue(0 != cloneHashMap.hashCode());
+    }
+
+    public void test_clone_scenario2() {
+        IdentityHashMap hashMap = new IdentityHashMap();
+        assertEquals(0, hashMap.hashCode());
+        Object cloneHashMap = hashMap.clone();
+        hashMap.put("key", "value");
+        assertEquals(1, hashMap.size());
+        assertEquals(0, ((IdentityHashMap) cloneHashMap).size());
+        assertEquals("value", hashMap.get("key"));
+        assertNull(((IdentityHashMap) cloneHashMap).get("key"));
+        assertTrue(0 != hashMap.hashCode());
+        assertEquals(0, cloneHashMap.hashCode());
+    }
+
+    public void test_clone_scenario3() {
+        IdentityHashMap hashMap = new IdentityHashMap();
+        assertEquals(0, hashMap.hashCode());
+        hashMap.put("key", "value");
+        Object cloneHashMap = hashMap.clone();
+        assertEquals(1, hashMap.size());
+        assertEquals(1, ((IdentityHashMap) cloneHashMap).size());
+        assertEquals("value", hashMap.get("key"));
+        assertEquals("value", ((IdentityHashMap) cloneHashMap).get("key"));
+        assertEquals(hashMap.hashCode(), cloneHashMap.hashCode());
+    }
+
+    public void test_clone_scenario4() {
+        IdentityHashMap hashMap = new IdentityHashMap();
+        Object cloneHashMap = hashMap.clone();
+        assertNull(((IdentityHashMap) cloneHashMap).get((Object) null));
+        hashMap.put((Object) null, cloneHashMap);
+        assertNull(((IdentityHashMap) cloneHashMap).get((Object) null));
+        assertEquals(cloneHashMap, hashMap.get((Object) null));
+    }
+
+    public void test_clone_scenario5() throws Exception {
+        IdentityHashMap hashMap = new IdentityHashMap();
+        Object cloneHashMap = hashMap.clone();
+        assertNull(hashMap.remove((Object) null));
+        ((IdentityHashMap) cloneHashMap).put((Object) null, cloneHashMap);
+        assertNull(hashMap.remove((Object) null));
+        assertEquals(cloneHashMap, ((IdentityHashMap) cloneHashMap)
+                .get((Object) null));
+    }
+
     // comparator for IdentityHashMap objects
     private static final SerializableAssert COMPARATOR = new SerializableAssert() {
         public void assertDeserialized(Serializable initial,



Mime
View raw message