harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r447357 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/ test/java/tests/api/java/util/
Date Mon, 18 Sep 2006 10:24:15 GMT
Author: pyang
Date: Mon Sep 18 03:24:14 2006
New Revision: 447357

URL: http://svn.apache.org/viewvc?view=rev&rev=447357
Log:
Patch applied for HARMONY-839 ([classlib][util]WeakHashMap(Map arg) throws NPE if arg.entrySet()
returns null)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/IdentityHashMap.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/WeakHashMap.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/HashMapTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/IdentityHashMapTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/WeakHashMapTest.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=447357&r1=447356&r2=447357
==============================================================================
--- 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 Sep 18 03:24:14 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -267,7 +267,7 @@
      */
     public HashMap(Map<? extends K, ? extends V> map) {
         this(map.size() < 6 ? 11 : map.size() * 2);
-        putAll(map);
+        super.putAll(map);
     }
 
     /**
@@ -537,14 +537,20 @@
     }
 
     /**
-     * Copies every mapping in the specified Map to this HashMap.
+     * Copies all the mappings in the given map to this map. These mappings will
+     * replace all mappings that this map had for any of the keys currently in
+     * the given map.
      * 
      * @param map
      *            the Map to copy mappings from
+     * @throws NullPointerException
+     *             if the given map is null
      */
     @Override
     public void putAll(Map<? extends K, ? extends V> map) {
-        super.putAll(map);
+        if (map.entrySet() != null) {
+            super.putAll(map);
+        }
     }
 
     void rehash() {
@@ -692,4 +698,5 @@
             createEntry(key, index, (V)stream.readObject());
         }
     }
+    
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/IdentityHashMap.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/IdentityHashMap.java?view=diff&rev=447357&r1=447356&r2=447357
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/IdentityHashMap.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/IdentityHashMap.java
Mon Sep 18 03:24:14 2006
@@ -285,7 +285,7 @@
      */
     public IdentityHashMap(Map<? extends K, ? extends V> map) {
         this(map.size() < 6 ? 11 : map.size() * 2);
-        putAll(map);
+        putAllImpl(map);
     }
 
     @SuppressWarnings("unchecked")
@@ -474,6 +474,21 @@
 
         return massageValue(result);
     }
+    
+    /**
+     * Copies all the mappings in the given map to this map. These mappings will
+     * replace all mappings that this map had for any of the keys currently in
+     * the given map.
+     * 
+     * @param map
+     *            the Map to copy mappings from
+     * @throws NullPointerException
+     *             if the given map is null
+     */
+    @Override
+    public void putAll(Map<? extends K, ? extends V> map) {
+        putAllImpl(map);
+    }
 
     private void rehash() {
         int newlength = elementData.length << 1;
@@ -772,5 +787,11 @@
             put(key, (V) stream.readObject());
         }
         size = savedSize;
+    }
+    
+    private void putAllImpl(Map<? extends K, ? extends V> map) {
+        if (map.entrySet() != null) {
+            super.putAll(map);
+        }
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/WeakHashMap.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/WeakHashMap.java?view=diff&rev=447357&r1=447356&r2=447357
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/WeakHashMap.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/WeakHashMap.java
Mon Sep 18 03:24:14 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -239,15 +239,15 @@
      */
     public WeakHashMap(Map<? extends K, ? extends V> map) {
         this(map.size() < 6 ? 11 : map.size() * 2);
-        putAll(map);
+        putAllImpl(map);
     }
 
     /**
-     * Removes all mappings from this WeakHashMap, leaving it empty.
-     * 
-     * @see #isEmpty
-     * @see #size
-     */
+	 * Removes all mappings from this WeakHashMap, leaving it empty.
+	 * 
+	 * @see #isEmpty
+	 * @see #size
+	 */
     @Override
     public void clear() {
         if (elementCount > 0) {
@@ -621,6 +621,21 @@
         elementData = newData;
         computeMaxSize();
     }
+    
+    /**
+     * Copies all the mappings in the given map to this map. These mappings will
+     * replace all mappings that this map had for any of the keys currently in
+     * the given map.
+     * 
+     * @param map
+     *            the Map to copy mappings from
+     * @throws NullPointerException
+     *             if the given map is null
+     */
+    @Override
+    public void putAll(Map<? extends K, ? extends V> map) {
+        putAllImpl(map);
+    }
 
     /**
      * Removes a mapping with the specified key from this WeakHashMap.
@@ -671,5 +686,11 @@
     public int size() {
         poll();
         return elementCount;
+    }
+    
+    private void putAllImpl(Map<? extends K, ? extends V> map) {
+        if (map.entrySet() != null) {
+            super.putAll(map);
+        }
     }
 }

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=447357&r1=447356&r2=447357
==============================================================================
--- 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 Sep 18 03:24:14 2006
@@ -29,7 +29,15 @@
 import tests.support.Support_UnmodifiableCollectionTest;
 
 public class HashMapTest extends junit.framework.TestCase {
-
+    class MockMap extends AbstractMap {
+        public Set entrySet() {
+            return null;
+        }
+        public int size(){
+            return 0;
+        }
+    }
+    
 	HashMap hm;
 
 	final static int hmSize = 1000;
@@ -111,6 +119,14 @@
 		for (int counter = 0; counter < hmSize; counter++)
 			assertTrue("Failed to construct correct HashMap", hm
 					.get(objArray2[counter]) == hm2.get(objArray2[counter]));
+        
+        try {
+            Map mockMap = new MockMap();
+            hm = new HashMap(mockMap);
+            fail("Should throw NullPointerException");
+        } catch (NullPointerException e) {
+            //empty
+        }
 	}
 
 	/**
@@ -123,7 +139,7 @@
 		for (int i = 0; i < hmSize; i++)
 			assertNull("Failed to clear all elements",
 					hm.get(objArray2[i]));
-
+        
 	}
 
 	/**
@@ -329,6 +345,11 @@
 		for (int i = 0; i < 1000; i++)
 			assertTrue("Failed to clear all elements", hm2.get(
 					new Integer(i).toString()).equals((new Integer(i))));
+        
+        Map mockMap = new MockMap();
+        hm2 = new HashMap();
+        hm2.putAll(mockMap);
+        assertEquals("Size should be 0", 0, hm2.size());
 	}
 
 	/**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/IdentityHashMapTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/IdentityHashMapTest.java?view=diff&rev=447357&r1=447356&r2=447357
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/IdentityHashMapTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/IdentityHashMapTest.java
Mon Sep 18 03:24:14 2006
@@ -1,4 +1,4 @@
-/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2005, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -29,7 +29,14 @@
 import tests.support.Support_MapTest2;
 
 public class IdentityHashMapTest extends junit.framework.TestCase {
-
+	class MockMap extends AbstractMap {
+		public Set entrySet() {
+			return null;
+		}
+		public int size(){
+			return 0;
+		}
+	}
 	/*
 	 * TODO: change all the statements testing the keys and values with equals()
 	 * method to check for reference equality instead
@@ -95,6 +102,10 @@
 		for (int counter = 0; counter < hmSize; counter++)
 			assertTrue("Failed to construct correct IdentityHashMap", hm
 					.get(objArray2[counter]) == hm2.get(objArray2[counter]));
+		
+        Map mockMap = new MockMap();
+        hm2 = new IdentityHashMap(mockMap);
+        assertEquals("Size should be 0", 0, hm2.size());
 	}
 
 	/**
@@ -307,6 +318,11 @@
 		for (int i = 0; i < 1000; i++)
 			assertTrue("Failed to clear all elements", hm2.get(objArray2[i])
 					.equals((new Integer(i))));
+        
+        hm2 = new IdentityHashMap();
+        Map mockMap = new MockMap();
+        hm2.putAll(mockMap);
+        assertEquals("Size should be 0", 0, hm2.size());
 	}
 
 	/**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/WeakHashMapTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/WeakHashMapTest.java?view=diff&rev=447357&r1=447356&r2=447357
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/WeakHashMapTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/WeakHashMapTest.java
Mon Sep 18 03:24:14 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
 
 package tests.api.java.util;
 
+import java.util.AbstractMap;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Iterator;
@@ -26,6 +27,14 @@
 import tests.support.Support_MapTest2;
 
 public class WeakHashMapTest extends junit.framework.TestCase {
+	class MockMap extends AbstractMap {
+		public Set entrySet() {
+			return null;
+		}
+		public int size(){
+			return 0;
+		}
+	}
 
 	Object[] keyArray = new Object[100];
 
@@ -84,6 +93,15 @@
 		empty.put("something", "here");
 		assertTrue("cannot get element", empty.get("something") == "here");
 	}
+	
+	/**
+	 * @tests java.util.WeakHashMap#WeakHashMap(java.util.Map)
+	 */
+	public void test_ConstructorLjava_util_Map() {
+        Map mockMap = new MockMap();
+        WeakHashMap map = new WeakHashMap(mockMap);
+        assertEquals("Size should be 0", 0, map.size());
+	}
 
 	/**
 	 * @tests java.util.WeakHashMap#clear()
@@ -205,6 +223,16 @@
 		map.remove("nothing"); // Cause objects in queue to be removed
 		assertEquals("null key was removed", 1, map.size());
 	}
+    
+    /**
+     * @tests java.util.WeakHashMap#putAll(java.util.Map)
+     */
+    public void test_putAllLjava_util_Map() {
+        Map mockMap=new MockMap();
+        WeakHashMap map = new WeakHashMap();
+        map.putAll(mockMap);
+        assertEquals("Size should be 0", 0, map.size());
+    }
 
 	/**
 	 * @tests java.util.WeakHashMap#remove(java.lang.Object)



Mime
View raw message