Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotate the parameter of List.sort as @Nullable. #40

Merged
merged 1 commit into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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