8053938: Collections.checkedList(empty list).replaceAll((UnaryOperator)null) doesn't throw NPE after JDK-8047795
Reviewed-by: rriggs, mduigou
--- a/jdk/src/share/classes/java/util/Collections.java Wed Jul 30 15:28:09 2014 +0800
+++ b/jdk/src/share/classes/java/util/Collections.java Wed Jul 30 17:42:18 2014 +0100
@@ -3486,6 +3486,7 @@
*/
@Override
public void replaceAll(UnaryOperator<E> operator) {
+ Objects.requireNonNull(operator);
list.replaceAll(e -> typeCheck(operator.apply(e)));
}
--- a/jdk/test/java/util/Collections/CheckedListReplaceAll.java Wed Jul 30 15:28:09 2014 +0800
+++ b/jdk/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!");
+ }
}
}