From c41478466b65b185ece03038d50742f53e506742 Mon Sep 17 00:00:00 2001 From: Chris Povirk Date: Fri, 9 Jun 2023 06:29:29 -0400 Subject: [PATCH] Annotate the parameter of `List.sort` as `@Nullable`. (#40) --- src/java.base/share/classes/java/util/ArrayList.java | 2 +- src/java.base/share/classes/java/util/List.java | 2 +- src/java.base/share/classes/java/util/Vector.java | 2 +- .../classes/java/util/concurrent/CopyOnWriteArrayList.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/java.base/share/classes/java/util/ArrayList.java b/src/java.base/share/classes/java/util/ArrayList.java index 14aca859e0c..fa750301acd 100644 --- a/src/java.base/share/classes/java/util/ArrayList.java +++ b/src/java.base/share/classes/java/util/ArrayList.java @@ -1753,7 +1753,7 @@ private void replaceAllRange(UnaryOperator operator, int i, int end) { @Override @SuppressWarnings("unchecked") - public void sort(Comparator c) { + public void sort(@Nullable Comparator c) { final int expectedModCount = modCount; Arrays.sort((E[]) elementData, 0, size, c); if (modCount != expectedModCount) diff --git a/src/java.base/share/classes/java/util/List.java b/src/java.base/share/classes/java/util/List.java index e414723de35..a70e0d14112 100644 --- a/src/java.base/share/classes/java/util/List.java +++ b/src/java.base/share/classes/java/util/List.java @@ -529,7 +529,7 @@ default void replaceAll(UnaryOperator operator) { * @since 1.8 */ @SuppressWarnings({"unchecked", "rawtypes"}) - default void sort(Comparator c) { + default void sort(@Nullable Comparator c) { Object[] a = this.toArray(); Arrays.sort(a, (Comparator) c); ListIterator i = this.listIterator(); diff --git a/src/java.base/share/classes/java/util/Vector.java b/src/java.base/share/classes/java/util/Vector.java index 869ea5dd463..b49701d72d7 100644 --- a/src/java.base/share/classes/java/util/Vector.java +++ b/src/java.base/share/classes/java/util/Vector.java @@ -1413,7 +1413,7 @@ public synchronized void replaceAll(UnaryOperator operator) { @SuppressWarnings("unchecked") @Override - public synchronized void sort(Comparator c) { + public synchronized void sort(@Nullable Comparator c) { final int expectedModCount = modCount; Arrays.sort((E[]) elementData, 0, elementCount, c); if (modCount != expectedModCount) diff --git a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java index 59a06554032..4f9be8b86a6 100644 --- a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java +++ b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java @@ -897,7 +897,7 @@ void replaceAllRange(UnaryOperator operator, int i, int end) { setArray(es); } - public void sort(Comparator c) { + public void sort(@Nullable Comparator c) { synchronized (lock) { sortRange(c, 0, getArray().length); }