提交 b0e203ea 编写于 作者: P psandoz

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

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