8023367: Collections.emptyList().sort((Comparator)null) throws NPE
Reviewed-by: alanb, mduigou
--- a/jdk/src/share/classes/java/util/Collections.java Tue Aug 20 16:53:27 2013 +0200
+++ b/jdk/src/share/classes/java/util/Collections.java Tue Aug 20 17:36:15 2013 +0200
@@ -4508,7 +4508,6 @@
}
@Override
public void sort(Comparator<? super E> c) {
- Objects.requireNonNull(c);
}
// Override default methods in Collection
--- a/jdk/test/java/util/Collection/ListDefaults.java Tue Aug 20 16:53:27 2013 +0200
+++ b/jdk/test/java/util/Collection/ListDefaults.java Tue Aug 20 17:36:15 2013 +0200
@@ -49,6 +49,7 @@
/**
* @test
+ * @bug 8023367
* @library testlibrary
* @build CollectionAsserts CollectionSupplier
* @run testng ListDefaults
@@ -100,6 +101,7 @@
@DataProvider(name="listProvider", parallel=true)
public static Object[][] listCases() {
final List<Object[]> cases = new LinkedList<>();
+ cases.add(new Object[] { Collections.emptyList() });
cases.add(new Object[] { new ArrayList<>() });
cases.add(new Object[] { new LinkedList<>() });
cases.add(new Object[] { new Vector<>() });
@@ -128,6 +130,11 @@
list.removeIf(null);
fail("expected NPE not thrown");
} catch (NullPointerException npe) {}
+ try {
+ list.sort(null);
+ } catch (Throwable t) {
+ fail("Exception not expected: " + t);
+ }
}
@Test