Index: modules/luni/src/test/api/java/org/apache/harmony/luni/tests/java/util/CollectionsTest.java =================================================================== --- modules/luni/src/test/api/java/org/apache/harmony/luni/tests/java/util/CollectionsTest.java (revision 421248) +++ modules/luni/src/test/api/java/org/apache/harmony/luni/tests/java/util/CollectionsTest.java (working copy) @@ -368,6 +368,14 @@ c = Collections.checkedCollection(c, String.class); SerializationTester.assertCompabilityEquals(c, "serialization/java/util/Collections_CheckedCollection.golden.ser"); } + + public void test_checkedCollectionNPE() throws Exception { + try { + Collections.checkedCollection(new java.util.Stack(), null); + fail("expected NPE with null as the second argument for checkedCollection()"); + } catch (NullPointerException e) { + } + } public void test_checkedListRandomAccessSerializationCompatability() throws Exception { List c = new ArrayList(); @@ -396,6 +404,19 @@ c = Collections.checkedMap(c, String.class, String.class); SerializationTester.assertCompabilityEquals(c, "serialization/java/util/Collections_CheckedMap.golden.ser"); } + + public void test_checkedMapNPE() throws Exception { + try { + Collections.checkedMap(new TreeMap(), null, Float.TYPE); + fail("expected NPE with null as the second argument for checkedMap()"); + } catch (NullPointerException e) { + } + try { + Collections.checkedMap(new TreeMap(), Float.TYPE, null); + fail("expected NPE with null as the third argument for checkedMap()"); + } catch (NullPointerException e) { + } + } public void test_checkedSortedSetSerializationCompatability() throws Exception { SortedSet c = new TreeSet(); @@ -408,4 +429,17 @@ c = Collections.checkedSortedMap(c, String.class, String.class); SerializationTester.assertCompabilityEquals(c, "serialization/java/util/Collections_CheckedSortedMap.golden.ser"); } + + public void test_checkedSortedMapNPE() throws Exception { + try { + Collections.checkedSortedMap(new TreeMap(), null, Short.TYPE); + fail("expected NPE with null as the second argument for checkedSortedMap()"); + } catch (NullPointerException e) { + } + try { + Collections.checkedSortedMap(new TreeMap(), Float.TYPE, null); + fail("expected NPE with null as the third argument for checkedSortedMap()"); + } catch (NullPointerException e) { + } + } } Index: modules/luni/src/main/java/java/util/Collections.java =================================================================== --- modules/luni/src/main/java/java/util/Collections.java (revision 421248) +++ modules/luni/src/main/java/java/util/Collections.java (working copy) @@ -2508,7 +2508,7 @@ * constructed. */ public CheckedCollection(Collection c, Class type) { - if (c == null) { + if (c == null || type == null) { throw new NullPointerException(); } this.c = c; @@ -2906,7 +2906,7 @@ * constructed. */ private CheckedMap(Map m, Class keyType, Class valueType) { - if (m == null) { + if (m == null || keyType == null || valueType == null) { throw new NullPointerException(); } this.m = m;