changeset 9917:6c7c3a54777f

8053938: Collections.checkedList(empty list).replaceAll((UnaryOperator)null) doesn't throw NPE after JDK-8047795 Reviewed-by: rriggs, mduigou
author chegar
date Wed, 30 Jul 2014 17:42:18 +0100
parents 41903ff88ae8
children c7077bc04f1e
files src/share/classes/java/util/Collections.java test/java/util/Collections/CheckedListReplaceAll.java
diffstat 2 files changed, 13 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/Collections.java	Wed Jul 23 20:14:02 2014 +0100
+++ b/src/share/classes/java/util/Collections.java	Wed Jul 30 17:42:18 2014 +0100
@@ -3497,6 +3497,7 @@
          */
         @Override
         public void replaceAll(UnaryOperator<E> operator) {
+            Objects.requireNonNull(operator);
             list.replaceAll(e -> typeCheck(operator.apply(e)));
         }
 
--- a/test/java/util/Collections/CheckedListReplaceAll.java	Wed Jul 23 20:14:02 2014 +0100
+++ b/test/java/util/Collections/CheckedListReplaceAll.java	Wed Jul 30 17:42:18 2014 +0100
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug     8047795
+ * @bug     8047795 8053938
  * @summary Ensure that replaceAll operator cannot add bad elements
  * @author  Mike Duigou
  */
@@ -46,5 +46,16 @@
             thwarted.printStackTrace(System.out);
             System.out.println("Curses! Foiled again!");
         }
+
+        unwrapped = Arrays.asList(new Object[]{});  // Empty list
+        wrapped = Collections.checkedList(unwrapped, Integer.class);
+        try {
+            wrapped.replaceAll((UnaryOperator)null);
+            System.out.printf("Bwahaha! I have defeated you! %s\n", wrapped);
+            throw new RuntimeException("NPE not thrown when passed a null operator");
+        } catch (NullPointerException thwarted) {
+            thwarted.printStackTrace(System.out);
+            System.out.println("Curses! Foiled again!");
+        }
     }
 }