changeset 19445:713cf2a92531

8023367: Collections.emptyList().sort((Comparator)null) throws NPE Reviewed-by: alanb, mduigou
author psandoz
date Tue, 20 Aug 2013 17:36:15 +0200
parents 5c9b942f2235
children 8e08c96b0808
files jdk/src/share/classes/java/util/Collections.java jdk/test/java/util/Collection/ListDefaults.java
diffstat 2 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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