Skip to content

Commit

Permalink
Annotate the parameter of List.sort as @Nullable.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpovirk committed Jun 8, 2023
1 parent e073c00 commit 9a0ce39
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/util/ArrayList.java
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,7 @@ private void replaceAllRange(UnaryOperator<E> operator, int i, int end) {

@Override
@SuppressWarnings("unchecked")
public void sort(Comparator<? super E> c) {
public void sort(@Nullable Comparator<? super E> c) {
final int expectedModCount = modCount;
Arrays.sort((E[]) elementData, 0, size, c);
if (modCount != expectedModCount)
Expand Down
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/util/List.java
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ default void replaceAll(UnaryOperator<E> operator) {
* @since 1.8
*/
@SuppressWarnings({"unchecked", "rawtypes"})
default void sort(Comparator<? super E> c) {
default void sort(@Nullable Comparator<? super E> c) {
Object[] a = this.toArray();
Arrays.sort(a, (Comparator) c);
ListIterator<E> i = this.listIterator();
Expand Down
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/util/Vector.java
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ public synchronized void replaceAll(UnaryOperator<E> operator) {

@SuppressWarnings("unchecked")
@Override
public synchronized void sort(Comparator<? super E> c) {
public synchronized void sort(@Nullable Comparator<? super E> c) {
final int expectedModCount = modCount;
Arrays.sort((E[]) elementData, 0, elementCount, c);
if (modCount != expectedModCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ void replaceAllRange(UnaryOperator<E> operator, int i, int end) {
setArray(es);
}

public void sort(Comparator<? super E> c) {
public void sort(@Nullable Comparator<? super E> c) {
synchronized (lock) {
sortRange(c, 0, getArray().length);
}
Expand Down

0 comments on commit 9a0ce39

Please sign in to comment.