提交 b0e203ea 编写于 作者: P psandoz

8023367: Collections.emptyList().sort((Comparator)null) throws NPE

Reviewed-by: alanb, mduigou
上级 6d3d58b0
......@@ -4508,7 +4508,6 @@ public class Collections {
}
@Override
public void sort(Comparator<? super E> c) {
Objects.requireNonNull(c);
}
// Override default methods in Collection
......
......@@ -49,6 +49,7 @@ import java.util.function.Predicate;
/**
* @test
* @bug 8023367
* @library testlibrary
* @build CollectionAsserts CollectionSupplier
* @run testng ListDefaults
......@@ -100,6 +101,7 @@ public class ListDefaults {
@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 @@ public class ListDefaults {
list.removeIf(null);
fail("expected NPE not thrown");
} catch (NullPointerException npe) {}
try {
list.sort(null);
} catch (Throwable t) {
fail("Exception not expected: " + t);
}
}
@Test
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册