-
Notifications
You must be signed in to change notification settings - Fork 32
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
Finish annotating some classes for nullness. #71
base: master
Are you sure you want to change the base?
Changes from all commits
f7f2607
0d42c9a
760559b
b68ae06
2f6f0e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,8 @@ | |
import org.checkerframework.checker.nullness.qual.Nullable; | ||
import org.checkerframework.checker.nullness.qual.PolyNull; | ||
import org.checkerframework.dataflow.qual.Pure; | ||
import org.checkerframework.framework.qual.AnnotatedFor; | ||
import org.checkerframework.framework.qual.CFComment; | ||
|
||
import java.lang.ref.WeakReference; | ||
import java.util.AbstractQueue; | ||
|
@@ -88,7 +90,8 @@ | |
* @author Doug Lea | ||
* @param <E> the type of elements held in this queue | ||
*/ | ||
public class ArrayBlockingQueue<E> extends AbstractQueue<E> | ||
@AnnotatedFor({"nullness"}) | ||
public class ArrayBlockingQueue<E extends Object> extends AbstractQueue<E> | ||
implements BlockingQueue<E>, java.io.Serializable { | ||
|
||
/* | ||
|
@@ -510,7 +513,8 @@ public int remainingCapacity() { | |
* @param o element to be removed from this queue, if present | ||
* @return {@code true} if this queue changed as a result of the call | ||
*/ | ||
public boolean remove(@Nullable Object o) { | ||
@CFComment("probably accepts null in practice, but docs at best imply this") | ||
public boolean remove(Object o) { | ||
if (o == null) return false; | ||
final ReentrantLock lock = this.lock; | ||
lock.lock(); | ||
|
@@ -542,7 +546,8 @@ public boolean remove(@Nullable Object o) { | |
* @param o object to be checked for containment in this queue | ||
* @return {@code true} if this queue contains the specified element | ||
*/ | ||
public boolean contains(@Nullable Object o) { | ||
@CFComment("probably accepts null in practice, but docs at best imply this") | ||
public boolean contains(Object o) { | ||
if (o == null) return false; | ||
final ReentrantLock lock = this.lock; | ||
lock.lock(); | ||
|
@@ -1479,15 +1484,15 @@ public boolean removeIf(Predicate<? super E> filter) { | |
/** | ||
* @throws NullPointerException {@inheritDoc} | ||
*/ | ||
public boolean removeAll(Collection<? extends @NonNull Object> c) { | ||
public boolean removeAll(Collection<?> c) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This takes us back to typetools/checker-framework#3197
In this case, the latter condition can't hold. So any call is safe. Below is a different case: That collection can contain nulls, so the only provably safe argument is another collection that can contain nulls. |
||
Objects.requireNonNull(c); | ||
return bulkRemove(e -> c.contains(e)); | ||
} | ||
|
||
/** | ||
* @throws NullPointerException {@inheritDoc} | ||
*/ | ||
public boolean retainAll(Collection<? extends @NonNull Object> c) { | ||
public boolean retainAll(Collection<?> c) { | ||
Objects.requireNonNull(c); | ||
return bulkRemove(e -> !c.contains(e)); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ | |
import org.checkerframework.checker.nullness.qual.PolyNull; | ||
import org.checkerframework.dataflow.qual.Pure; | ||
import org.checkerframework.dataflow.qual.SideEffectFree; | ||
import org.checkerframework.framework.qual.AnnotatedFor; | ||
|
||
import java.lang.invoke.VarHandle; | ||
import java.lang.reflect.Field; | ||
|
@@ -97,6 +98,7 @@ | |
* @author Doug Lea | ||
* @param <E> the type of elements held in this list | ||
*/ | ||
@AnnotatedFor({"nullness"}) | ||
public class CopyOnWriteArrayList<E> | ||
implements List<E>, RandomAccess, Cloneable, java.io.Serializable { | ||
private static final long serialVersionUID = 8673264195747942595L; | ||
|
@@ -263,7 +265,7 @@ public int indexOf(@Nullable Object o) { | |
* {@code -1} if the element is not found. | ||
* @throws IndexOutOfBoundsException if the specified index is negative | ||
*/ | ||
public int indexOf(E e, int index) { | ||
public int indexOf(@Nullable E e, int index) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
Object[] es = getArray(); | ||
return indexOfRange(e, es, index, es.length); | ||
} | ||
|
@@ -292,7 +294,7 @@ public int lastIndexOf(@Nullable Object o) { | |
* @throws IndexOutOfBoundsException if the specified index is greater | ||
* than or equal to the current size of this list | ||
*/ | ||
public int lastIndexOf(E e, int index) { | ||
public int lastIndexOf(@Nullable E e, int index) { | ||
Object[] es = getArray(); | ||
return lastIndexOfRange(e, es, 0, index + 1); | ||
} | ||
|
@@ -659,7 +661,7 @@ public boolean containsAll(Collection<?> c) { | |
* or if the specified collection is null | ||
* @see #remove(Object) | ||
*/ | ||
public boolean removeAll(Collection<? extends @NonNull Object> c) { | ||
public boolean removeAll(Collection<@Nullable ?> c) { | ||
Objects.requireNonNull(c); | ||
return bulkRemove(e -> c.contains(e)); | ||
} | ||
|
@@ -680,7 +682,7 @@ public boolean removeAll(Collection<? extends @NonNull Object> c) { | |
* or if the specified collection is null | ||
* @see #remove(Object) | ||
*/ | ||
public boolean retainAll(Collection<? extends @NonNull Object> c) { | ||
public boolean retainAll(Collection<@Nullable ?> c) { | ||
Objects.requireNonNull(c); | ||
return bulkRemove(e -> !c.contains(e)); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like typetools/checker-framework#3063 didn't touch this file. (That is, this annotation was there before that PR.) I'm not sure if that means that you hadn't looked at it at the time or that you found some reason to justify omitting
@Nullable
here.Likewise for the other queues/deques in this PR.