harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r448131 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/HashMap.java test/java/tests/api/java/util/HashMapTest.java
Date Wed, 20 Sep 2006 09:12:11 GMT
Author: pyang
Date: Wed Sep 20 02:12:11 2006
New Revision: 448131

URL: http://svn.apache.org/viewvc?view=rev&rev=448131
Log:
Apply patch for HARMONY-1498 ([classlib][luni][HashMap]It is not appropriate to use entrySet
as judgement in HashMap.putAll())

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?view=diff&rev=448131&r1=448130&r2=448131
==============================================================================
--- 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
Wed Sep 20 02:12:11 2006
@@ -548,7 +548,7 @@
      */
     @Override
     public void putAll(Map<? extends K, ? extends V> map) {
-        if (map.entrySet() != null) {
+        if (!map.isEmpty()) {
             int capacity = elementCount + map.size();
             if (capacity > threshold) {
                 rehash(capacity);

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?view=diff&rev=448131&r1=448130&r2=448131
==============================================================================
--- 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
Wed Sep 20 02:12:11 2006
@@ -38,6 +38,16 @@
         }
     }
     
+    private static class MockMapNull extends AbstractMap {
+        public Set entrySet() {
+            return null;
+        }
+
+        public int size() {
+            return 10;
+        }
+    }
+    
 	HashMap hm;
 
 	final static int hmSize = 1000;
@@ -351,6 +361,26 @@
         hm2.putAll(mockMap);
         assertEquals("Size should be 0", 0, hm2.size());
 	}
+    
+    /**
+     * @tests java.util.HashMap#putAll(java.util.Map)
+     */
+    public void test_putAllLjava_util_Map_Null() {
+        HashMap hashMap = new HashMap();
+        try {
+            hashMap.putAll(new MockMapNull());
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected.
+        }
+
+        try {
+            hashMap = new HashMap(new MockMapNull());
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected.
+        }
+    } 
 
 	/**
 	 * @tests java.util.HashMap#remove(java.lang.Object)



Mime
View raw message