this) {
* This implementation repeatedly invokes {@link #poll poll} until it
* returns {@code null}.
*/
- public void clear(@GuardSatisfied AbstractQueue this) {
+ public void clear(@GuardSatisfied @Shrinkable AbstractQueue this) {
while (poll() != null)
;
}
diff --git a/src/java.base/share/classes/java/util/AbstractSequentialList.java b/src/java.base/share/classes/java/util/AbstractSequentialList.java
index ce06ac0cdae..dfa76cdf439 100644
--- a/src/java.base/share/classes/java/util/AbstractSequentialList.java
+++ b/src/java.base/share/classes/java/util/AbstractSequentialList.java
@@ -25,7 +25,10 @@
package java.util;
+import org.checkerframework.checker.index.qual.PolyGrowShrink;
+import org.checkerframework.checker.index.qual.Shrinkable;
import org.checkerframework.checker.lock.qual.GuardSatisfied;
+import org.checkerframework.checker.nonempty.qual.PolyNonEmpty;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.dataflow.qual.SideEffectFree;
import org.checkerframework.framework.qual.AnnotatedFor;
@@ -177,7 +180,7 @@ public void add(@GuardSatisfied AbstractSequentialList this, int index, E ele
* @throws UnsupportedOperationException {@inheritDoc}
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
- public E remove(@GuardSatisfied AbstractSequentialList this, int index) {
+ public E remove(@GuardSatisfied @Shrinkable AbstractSequentialList this, int index) {
try {
ListIterator e = listIterator(index);
E outCast = e.next();
@@ -246,7 +249,7 @@ public boolean addAll(@GuardSatisfied AbstractSequentialList this, int index,
* @return an iterator over the elements in this list (in proper sequence)
*/
@SideEffectFree
- public Iterator iterator() {
+ public @PolyGrowShrink @PolyNonEmpty Iterator iterator(@PolyGrowShrink @PolyNonEmpty AbstractSequentialList this) {
return listIterator();
}
@@ -260,5 +263,5 @@ public Iterator iterator() {
* sequence)
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
- public abstract ListIterator listIterator(int index);
+ public abstract @PolyGrowShrink ListIterator listIterator(@PolyGrowShrink AbstractSequentialList this, int index);
}
diff --git a/src/java.base/share/classes/java/util/ArrayDeque.java b/src/java.base/share/classes/java/util/ArrayDeque.java
index 40a6a0deba2..fd4351a35ef 100644
--- a/src/java.base/share/classes/java/util/ArrayDeque.java
+++ b/src/java.base/share/classes/java/util/ArrayDeque.java
@@ -35,6 +35,8 @@
package java.util;
import org.checkerframework.checker.index.qual.NonNegative;
+import org.checkerframework.checker.index.qual.PolyGrowShrink;
+import org.checkerframework.checker.index.qual.Shrinkable;
import org.checkerframework.checker.lock.qual.GuardSatisfied;
import org.checkerframework.checker.nonempty.qual.EnsuresNonEmpty;
import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf;
@@ -48,7 +50,6 @@
import org.checkerframework.checker.signedness.qual.UnknownSignedness;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.dataflow.qual.SideEffectFree;
-import org.checkerframework.dataflow.qual.SideEffectsOnly;
import org.checkerframework.framework.qual.AnnotatedFor;
import java.io.Serializable;
@@ -374,7 +375,7 @@ public boolean offerLast(E e) {
/**
* @throws NoSuchElementException {@inheritDoc}
*/
- public E removeFirst(@GuardSatisfied @NonEmpty ArrayDeque this) {
+ public E removeFirst(@GuardSatisfied @NonEmpty @Shrinkable ArrayDeque this) {
E e = pollFirst();
if (e == null)
throw new NoSuchElementException();
@@ -384,14 +385,14 @@ public E removeFirst(@GuardSatisfied @NonEmpty ArrayDeque this) {
/**
* @throws NoSuchElementException {@inheritDoc}
*/
- public E removeLast(@GuardSatisfied @NonEmpty ArrayDeque this) {
+ public E removeLast(@GuardSatisfied @NonEmpty @Shrinkable ArrayDeque this) {
E e = pollLast();
if (e == null)
throw new NoSuchElementException();
return e;
}
- public @Nullable E pollFirst(@GuardSatisfied ArrayDeque this) {
+ public @Nullable E pollFirst(@GuardSatisfied @Shrinkable ArrayDeque this) {
final Object[] es;
final int h;
E e = elementAt(es = elements, h = head);
@@ -402,7 +403,7 @@ public E removeLast(@GuardSatisfied @NonEmpty ArrayDeque this) {
return e;
}
- public @Nullable E pollLast(@GuardSatisfied ArrayDeque this) {
+ public @Nullable E pollLast(@GuardSatisfied @Shrinkable ArrayDeque this) {
final Object[] es;
final int t;
E e = elementAt(es = elements, t = dec(tail, es.length));
@@ -455,7 +456,7 @@ public E getLast(@GuardSatisfied @NonEmpty ArrayDeque this) {
* @param o element to be removed from this deque, if present
* @return {@code true} if the deque contained the specified element
*/
- public boolean removeFirstOccurrence(@GuardSatisfied ArrayDeque this, @Nullable Object o) {
+ public boolean removeFirstOccurrence(@GuardSatisfied @Shrinkable ArrayDeque this, @GuardSatisfied @Nullable @UnknownSignedness Object o) {
if (o != null) {
final Object[] es = elements;
for (int i = head, end = tail, to = (i <= end) ? end : es.length;
@@ -483,7 +484,7 @@ public boolean removeFirstOccurrence(@GuardSatisfied ArrayDeque this, @Nullab
* @param o element to be removed from this deque, if present
* @return {@code true} if the deque contained the specified element
*/
- public boolean removeLastOccurrence(@GuardSatisfied ArrayDeque this, @Nullable Object o) {
+ public boolean removeLastOccurrence(@GuardSatisfied @Shrinkable ArrayDeque this, @GuardSatisfied @Nullable @UnknownSignedness Object o) {
if (o != null) {
final Object[] es = elements;
for (int i = tail, end = head, to = (i >= end) ? end : 0;
@@ -540,7 +541,7 @@ public boolean offer(@GuardSatisfied ArrayDeque this, E e) {
* @return the head of the queue represented by this deque
* @throws NoSuchElementException {@inheritDoc}
*/
- public E remove(@GuardSatisfied @NonEmpty ArrayDeque this) {
+ public E remove(@GuardSatisfied @NonEmpty @Shrinkable ArrayDeque this) {
return removeFirst();
}
@@ -554,7 +555,7 @@ public E remove(@GuardSatisfied @NonEmpty ArrayDeque this) {
* @return the head of the queue represented by this deque, or
* {@code null} if this deque is empty
*/
- public @Nullable E poll(@GuardSatisfied ArrayDeque this) {
+ public @Nullable E poll(@GuardSatisfied @Shrinkable ArrayDeque this) {
return pollFirst();
}
@@ -611,7 +612,7 @@ public void push(@GuardSatisfied ArrayDeque this, E e) {
* of the stack represented by this deque)
* @throws NoSuchElementException {@inheritDoc}
*/
- public E pop(@GuardSatisfied @NonEmpty ArrayDeque this) {
+ public E pop(@GuardSatisfied @NonEmpty @Shrinkable ArrayDeque this) {
return removeFirst();
}
@@ -693,11 +694,11 @@ public boolean isEmpty(@GuardSatisfied ArrayDeque this) {
* @return an iterator over the elements in this deque
*/
@SideEffectFree
- public @PolyNonEmpty Iterator iterator(@PolyNonEmpty ArrayDeque this) {
+ public @PolyGrowShrink @PolyNonEmpty Iterator iterator(@PolyGrowShrink @PolyNonEmpty ArrayDeque this) {
return new DeqIterator();
}
- public @PolyNonEmpty Iterator descendingIterator(@PolyNonEmpty ArrayDeque this) {
+ public @PolyGrowShrink @PolyNonEmpty Iterator descendingIterator(@PolyGrowShrink @PolyNonEmpty ArrayDeque this) {
return new DescendingIterator();
}
@@ -722,7 +723,6 @@ public final boolean hasNext() {
return remaining > 0;
}
- @SideEffectsOnly("this")
public E next(@NonEmpty DeqIterator this) {
if (remaining <= 0)
throw new NoSuchElementException();
@@ -926,7 +926,7 @@ public void forEach(Consumer super E> action) {
/**
* @throws NullPointerException {@inheritDoc}
*/
- public boolean removeIf(Predicate super E> filter) {
+ public boolean removeIf(@Shrinkable ArrayDeque this, Predicate super E> filter) {
Objects.requireNonNull(filter);
return bulkRemove(filter);
}
@@ -934,7 +934,7 @@ public boolean removeIf(Predicate super E> filter) {
/**
* @throws NullPointerException {@inheritDoc}
*/
- public boolean removeAll(Collection extends @UnknownSignedness Object> c) {
+ public boolean removeAll(@Shrinkable ArrayDeque this, Collection extends @UnknownSignedness Object> c) {
Objects.requireNonNull(c);
return bulkRemove(e -> c.contains(e));
}
@@ -942,7 +942,7 @@ public boolean removeAll(Collection extends @UnknownSignedness Object> c) {
/**
* @throws NullPointerException {@inheritDoc}
*/
- public boolean retainAll(Collection extends @UnknownSignedness Object> c) {
+ public boolean retainAll(@GuardSatisfied @Shrinkable ArrayDeque this, Collection extends @UnknownSignedness Object> c) {
Objects.requireNonNull(c);
return bulkRemove(e -> !c.contains(e));
}
@@ -1058,7 +1058,7 @@ public boolean contains(@GuardSatisfied ArrayDeque this, @GuardSatisfied @Nul
* @param o element to be removed from this deque, if present
* @return {@code true} if this deque contained the specified element
*/
- public boolean remove(@GuardSatisfied ArrayDeque this, @GuardSatisfied @Nullable @UnknownSignedness Object o) {
+ public boolean remove(@GuardSatisfied @Shrinkable ArrayDeque this, @GuardSatisfied @Nullable @UnknownSignedness Object o) {
return removeFirstOccurrence(o);
}
@@ -1066,7 +1066,7 @@ public boolean remove(@GuardSatisfied ArrayDeque this, @GuardSatisfied @Nulla
* Removes all of the elements from this deque.
* The deque will be empty after this call returns.
*/
- public void clear(@GuardSatisfied ArrayDeque this) {
+ public void clear(@GuardSatisfied @Shrinkable ArrayDeque this) {
circularClear(elements, head, tail);
head = tail = 0;
}
diff --git a/src/java.base/share/classes/java/util/ArrayList.java b/src/java.base/share/classes/java/util/ArrayList.java
index 39962efeb08..eab7ee3ccd5 100644
--- a/src/java.base/share/classes/java/util/ArrayList.java
+++ b/src/java.base/share/classes/java/util/ArrayList.java
@@ -27,6 +27,8 @@
import org.checkerframework.checker.index.qual.GTENegativeOne;
import org.checkerframework.checker.index.qual.NonNegative;
+import org.checkerframework.checker.index.qual.PolyGrowShrink;
+import org.checkerframework.checker.index.qual.Shrinkable;
import org.checkerframework.checker.lock.qual.GuardSatisfied;
import org.checkerframework.checker.nonempty.qual.EnsuresNonEmpty;
import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf;
@@ -40,7 +42,6 @@
import org.checkerframework.checker.signedness.qual.UnknownSignedness;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.dataflow.qual.SideEffectFree;
-import org.checkerframework.dataflow.qual.SideEffectsOnly;
import org.checkerframework.framework.qual.AnnotatedFor;
import org.checkerframework.framework.qual.CFComment;
@@ -501,7 +502,6 @@ public E getLast() {
* @return the element previously at the specified position
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
- @SideEffectsOnly("this")
public E set(@GuardSatisfied ArrayList this, @NonNegative int index, E element) {
Objects.checkIndex(index, size);
E oldValue = elementData(index);
@@ -514,7 +514,6 @@ public E set(@GuardSatisfied ArrayList this, @NonNegative int index, E elemen
* bytecode size under 35 (the -XX:MaxInlineSize default value),
* which helps when add(E) is called in a C1-compiled loop.
*/
- @SideEffectsOnly("this")
private void add(E e, Object[] elementData, int s) {
if (s == elementData.length)
elementData = grow();
@@ -528,7 +527,6 @@ private void add(E e, Object[] elementData, int s) {
* @param e element to be appended to this list
* @return {@code true} (as specified by {@link Collection#add})
*/
- @SideEffectsOnly("this")
@EnsuresNonEmpty("this")
public boolean add(@GuardSatisfied ArrayList this, E e) {
modCount++;
@@ -545,7 +543,6 @@ public boolean add(@GuardSatisfied ArrayList this, E e) {
* @param element element to be inserted
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
- @SideEffectsOnly("this")
public void add(@GuardSatisfied ArrayList this, @NonNegative int index, E element) {
rangeCheckForAdd(index);
modCount++;
@@ -587,7 +584,7 @@ public void addLast(E element) {
* @return the element that was removed from the list
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
- public E remove(@GuardSatisfied ArrayList this, @NonNegative int index) {
+ public E remove(@GuardSatisfied @Shrinkable ArrayList this, @NonNegative int index) {
Objects.checkIndex(index, size);
final Object[] es = elementData;
@@ -734,7 +731,7 @@ int hashCodeRange(int from, int to) {
* @param o element to be removed from this list, if present
* @return {@code true} if this list contained the specified element
*/
- public boolean remove(@GuardSatisfied ArrayList this, @GuardSatisfied @Nullable @UnknownSignedness Object o) {
+ public boolean remove(@GuardSatisfied @Shrinkable ArrayList this, @GuardSatisfied @Nullable @UnknownSignedness Object o) {
final Object[] es = elementData;
final int size = this.size;
int i = 0;
@@ -770,7 +767,7 @@ private void fastRemove(Object[] es, int i) {
* Removes all of the elements from this list. The list will
* be empty after this call returns.
*/
- public void clear(@GuardSatisfied ArrayList this) {
+ public void clear(@GuardSatisfied @Shrinkable ArrayList this) {
modCount++;
final Object[] es = elementData;
for (int to = size, i = size = 0; i < to; i++)
@@ -790,7 +787,6 @@ public void clear(@GuardSatisfied ArrayList this) {
* @return {@code true} if this list changed as a result of the call
* @throws NullPointerException if the specified collection is null
*/
- @SideEffectsOnly("this")
public boolean addAll(@GuardSatisfied ArrayList this, Collection extends E> c) {
Object[] a = c.toArray();
modCount++;
@@ -821,7 +817,6 @@ public boolean addAll(@GuardSatisfied ArrayList this, Collection extends E>
* @throws IndexOutOfBoundsException {@inheritDoc}
* @throws NullPointerException if the specified collection is null
*/
- @SideEffectsOnly("this")
public boolean addAll(@GuardSatisfied ArrayList this, @NonNegative int index, Collection extends E> c) {
rangeCheckForAdd(index);
@@ -858,7 +853,7 @@ public boolean addAll(@GuardSatisfied ArrayList this, @NonNegative int index,
* toIndex > size() ||
* toIndex < fromIndex})
*/
- protected void removeRange(int fromIndex, int toIndex) {
+ protected void removeRange(@GuardSatisfied @Shrinkable ArrayList this, int fromIndex, int toIndex) {
if (fromIndex > toIndex) {
throw new IndexOutOfBoundsException(
outOfBoundsMsg(fromIndex, toIndex));
@@ -913,7 +908,7 @@ private static String outOfBoundsMsg(int fromIndex, int toIndex) {
* or if the specified collection is null
* @see Collection#contains(Object)
*/
- public boolean removeAll(Collection extends @UnknownSignedness Object> c) {
+ public boolean removeAll(@Shrinkable ArrayList this, Collection extends @UnknownSignedness Object> c) {
return batchRemove(c, false, 0, size);
}
@@ -933,7 +928,7 @@ public boolean removeAll(Collection extends @UnknownSignedness Object> c) {
* or if the specified collection is null
* @see Collection#contains(Object)
*/
- public boolean retainAll(Collection extends @UnknownSignedness Object> c) {
+ public boolean retainAll(@GuardSatisfied @Shrinkable ArrayList this, Collection extends @UnknownSignedness Object> c) {
return batchRemove(c, true, 0, size);
}
@@ -1045,7 +1040,7 @@ private void readObject(java.io.ObjectInputStream s)
*
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
- public ListIterator listIterator(@NonNegative int index) {
+ public @PolyGrowShrink ListIterator listIterator(@PolyGrowShrink ArrayList this, @NonNegative int index) {
rangeCheckForAdd(index);
return new ListItr(index);
}
@@ -1058,7 +1053,7 @@ public ListIterator listIterator(@NonNegative int index) {
*
* @see #listIterator(int)
*/
- public ListIterator listIterator() {
+ public @PolyGrowShrink @PolyNonEmpty ListIterator listIterator(@PolyGrowShrink @PolyNonEmpty ArrayList this) {
return new ListItr(0);
}
@@ -1070,7 +1065,7 @@ public ListIterator listIterator() {
* @return an iterator over the elements in this list in proper sequence
*/
@SideEffectFree
- public Iterator iterator() {
+ public @PolyGrowShrink @PolyNonEmpty Iterator iterator(@PolyGrowShrink @PolyNonEmpty ArrayList this) {
return new Itr();
}
@@ -1092,7 +1087,6 @@ public boolean hasNext() {
}
@SuppressWarnings("unchecked")
- @SideEffectsOnly("this")
public E next(@NonEmpty Itr this) {
checkForComodification();
int i = cursor;
@@ -1235,7 +1229,7 @@ public void add(E e) {
* @throws IndexOutOfBoundsException {@inheritDoc}
* @throws IllegalArgumentException {@inheritDoc}
*/
- public List subList(@NonNegative int fromIndex, @NonNegative int toIndex) {
+ public @PolyGrowShrink List subList(@GuardSatisfied @PolyGrowShrink ArrayList this, @NonNegative int fromIndex, @NonNegative int toIndex) {
subListRangeCheck(fromIndex, toIndex, size);
return new SubList<>(this, fromIndex, toIndex);
}
@@ -1430,7 +1424,6 @@ public boolean hasNext() {
}
@SuppressWarnings("unchecked")
- @SideEffectsOnly("this")
public E next(/*@NonEmpty ListIterator this*/) {
checkForComodification();
int i = cursor;
@@ -1796,7 +1789,7 @@ private static boolean isClear(long[] bits, int i) {
* @throws NullPointerException {@inheritDoc}
*/
@Override
- public boolean removeIf(Predicate super E> filter) {
+ public boolean removeIf(@Shrinkable ArrayList this, Predicate super E> filter) {
return removeIf(filter, 0, size);
}
@@ -1804,7 +1797,7 @@ public boolean removeIf(Predicate super E> filter) {
* Removes all elements satisfying the given predicate, from index
* i (inclusive) to index end (exclusive).
*/
- boolean removeIf(Predicate super E> filter, int i, final int end) {
+ boolean removeIf(@Shrinkable ArrayList this, Predicate super E> filter, int i, final int end) {
Objects.requireNonNull(filter);
int expectedModCount = modCount;
final Object[] es = elementData;
diff --git a/src/java.base/share/classes/java/util/Arrays.java b/src/java.base/share/classes/java/util/Arrays.java
index ee3c1a016e9..3e24f799a08 100644
--- a/src/java.base/share/classes/java/util/Arrays.java
+++ b/src/java.base/share/classes/java/util/Arrays.java
@@ -44,7 +44,6 @@
import org.checkerframework.common.value.qual.MinLen;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.dataflow.qual.SideEffectFree;
-import org.checkerframework.dataflow.qual.SideEffectsOnly;
import org.checkerframework.framework.qual.AnnotatedFor;
import org.checkerframework.framework.qual.CFComment;
@@ -3522,6 +3521,8 @@ public static void fill(@PolyInterned @PolyNull @PolySigned Object[] a, @IndexOr
*/
@SideEffectFree
@SuppressWarnings("unchecked")
+ @CFComment("The return type is refined when safe. See " +
+ "https://github.com/eisop/checker-framework/blob/17991582bc3a35509f15065b051d8e4c45c3e9ae/checker/src/main/java/org/checkerframework/checker/nullness/NullnessNoInitAnnotatedTypeFactory.java#L756")
public static @Nullable T[] copyOf(T[] original, @NonNegative int newLength) {
return (T[]) copyOf(original, newLength, original.getClass());
}
@@ -3552,6 +3553,8 @@ public static void fill(@PolyInterned @PolyNull @PolySigned Object[] a, @IndexOr
*/
@SideEffectFree
@IntrinsicCandidate
+ @CFComment("The return type is refined when safe. See " +
+ "https://github.com/eisop/checker-framework/blob/17991582bc3a35509f15065b051d8e4c45c3e9ae/checker/src/main/java/org/checkerframework/checker/nullness/NullnessNoInitAnnotatedTypeFactory.java#L756")
public static @Nullable T[] copyOf(U[] original, @NonNegative int newLength, Class extends T[]> newType) {
@SuppressWarnings("unchecked")
T[] copy = ((Object)newType == (Object)Object[].class)
@@ -4413,7 +4416,6 @@ public boolean hasNext() {
}
@Override
- @SideEffectsOnly("this")
public E next(@NonEmpty ArrayItr this) {
int i = cursor;
if (i >= a.length) {
@@ -4672,7 +4674,7 @@ public static int hashCode(double @Nullable [] a) {
* @since 1.5
*/
@Pure
- public static int hashCode(@PolyInterned @PolyNull @PolySigned Object @GuardSatisfied @Nullable [] a) {
+ public static int hashCode(@PolyInterned @PolyNull @PolySigned Object @GuardSatisfied @Nullable [] a) {
if (a == null)
return 0;
@@ -4714,7 +4716,7 @@ public static int hashCode(@PolyInterned @PolyNull @PolySigned Object @GuardSati
* @since 1.5
*/
@Pure
- public static int deepHashCode(@PolyInterned @PolyNull @PolySigned Object @GuardSatisfied @Nullable [] a) {
+ public static int deepHashCode(@PolyInterned @PolyNull @PolySigned Object @GuardSatisfied @Nullable [] a) {
if (a == null)
return 0;
diff --git a/src/java.base/share/classes/java/util/Collection.java b/src/java.base/share/classes/java/util/Collection.java
index f0eb976ca4a..c8f14803210 100644
--- a/src/java.base/share/classes/java/util/Collection.java
+++ b/src/java.base/share/classes/java/util/Collection.java
@@ -26,6 +26,8 @@
package java.util;
import org.checkerframework.checker.index.qual.NonNegative;
+import org.checkerframework.checker.index.qual.PolyGrowShrink;
+import org.checkerframework.checker.index.qual.Shrinkable;
import org.checkerframework.checker.lock.qual.GuardSatisfied;
import org.checkerframework.checker.nonempty.qual.EnsuresNonEmpty;
import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf;
@@ -326,7 +328,7 @@ public interface Collection extends Iterable {
* @return an {@code Iterator} over the elements in this collection
*/
@SideEffectFree
- @PolyNonEmpty Iterator iterator(@PolyNonEmpty Collection this);
+ @PolyGrowShrink @PolyNonEmpty Iterator iterator(@PolyGrowShrink @PolyNonEmpty Collection this);
/**
* Returns an array containing all of the elements in this collection.
@@ -508,7 +510,7 @@ default T[] toArray(IntFunction generator) {
* @throws UnsupportedOperationException if the {@code remove} operation
* is not supported by this collection
*/
- boolean remove(@GuardSatisfied Collection this, @UnknownSignedness Object o);
+ boolean remove(@GuardSatisfied @Shrinkable Collection this, @UnknownSignedness Object o);
// Bulk Operations
@@ -585,7 +587,7 @@ default T[] toArray(IntFunction generator) {
* @see #remove(Object)
* @see #contains(Object)
*/
- boolean removeAll(@GuardSatisfied Collection this, Collection extends @UnknownSignedness Object> c);
+ boolean removeAll(@GuardSatisfied @Shrinkable Collection this, Collection extends @UnknownSignedness Object> c);
/**
* Removes all of the elements of this collection that satisfy the given
@@ -609,7 +611,7 @@ default T[] toArray(IntFunction generator) {
* supported.
* @since 1.8
*/
- default boolean removeIf(Predicate super E> filter) {
+ default boolean removeIf(@Shrinkable Collection this, Predicate super E> filter) {
Objects.requireNonNull(filter);
boolean removed = false;
final Iterator each = iterator();
@@ -644,7 +646,7 @@ default boolean removeIf(Predicate super E> filter) {
* @see #remove(Object)
* @see #contains(Object)
*/
- boolean retainAll(@GuardSatisfied Collection this, Collection extends @UnknownSignedness Object> c);
+ boolean retainAll(@GuardSatisfied @Shrinkable Collection this, Collection extends @UnknownSignedness Object> c);
/**
* Removes all of the elements from this collection (optional operation).
@@ -653,7 +655,7 @@ default boolean removeIf(Predicate super E> filter) {
* @throws UnsupportedOperationException if the {@code clear} operation
* is not supported by this collection
*/
- void clear(@GuardSatisfied Collection this);
+ void clear(@GuardSatisfied @Shrinkable Collection this);
// Comparison and hashing
diff --git a/src/java.base/share/classes/java/util/Collections.java b/src/java.base/share/classes/java/util/Collections.java
index 5c9713dd80b..1e5565cf647 100644
--- a/src/java.base/share/classes/java/util/Collections.java
+++ b/src/java.base/share/classes/java/util/Collections.java
@@ -27,6 +27,7 @@
import org.checkerframework.checker.index.qual.GTENegativeOne;
import org.checkerframework.checker.index.qual.NonNegative;
+import org.checkerframework.checker.index.qual.PolyGrowShrink;
import org.checkerframework.checker.lock.qual.GuardSatisfied;
import org.checkerframework.checker.nonempty.qual.EnsuresNonEmpty;
import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf;
@@ -44,7 +45,6 @@
import org.checkerframework.common.value.qual.StaticallyExecutable;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.dataflow.qual.SideEffectFree;
-import org.checkerframework.dataflow.qual.SideEffectsOnly;
import org.checkerframework.framework.qual.AnnotatedFor;
import org.checkerframework.framework.qual.CFComment;
@@ -198,6 +198,7 @@ public static > void sort(List list) {
* found to violate the {@link Comparator} contract
* @see List#sort(Comparator)
*/
+ @SuppressWarnings({"unchecked", "rawtypes"})
public static void sort(List list, @Nullable Comparator super T> c) {
list.sort(c);
}
@@ -681,7 +682,7 @@ public static > T min(Collection exte
* @throws NoSuchElementException if the collection is empty.
* @see Comparable
*/
- @SuppressWarnings({"unchecked"})
+ @SuppressWarnings({"unchecked", "rawtypes"})
@Pure
@StaticallyExecutable
public static T min(Collection extends T> coll, @Nullable Comparator super T> comp) {
@@ -758,7 +759,7 @@ public static > T max(Collection exte
* @throws NoSuchElementException if the collection is empty.
* @see Comparable
*/
- @SuppressWarnings({"unchecked"})
+ @SuppressWarnings({"unchecked", "rawtypes"})
@Pure
@StaticallyExecutable
public static T max(Collection extends T> coll, @Nullable Comparator super T> comp) {
@@ -1074,7 +1075,7 @@ public static boolean replaceAll(List list, @Nullable T oldVal, T newVal)
*/
@SuppressWarnings("unchecked")
@SideEffectFree
- public static @PolyNonEmpty Collection unmodifiableCollection(@PolyNonEmpty Collection extends T> c) {
+ public static @PolyGrowShrink @PolyNonEmpty Collection unmodifiableCollection(@PolyGrowShrink @PolyNonEmpty Collection extends T> c) {
if (c.getClass() == UnmodifiableCollection.class) {
return (Collection) c;
}
@@ -1113,14 +1114,13 @@ static class UnmodifiableCollection implements Collection, Serializable {
public String toString() {return c.toString();}
@SideEffectFree
- public @PolyNonEmpty Iterator iterator(@PolyNonEmpty UnmodifiableCollection this) {
+ public @PolyGrowShrink @PolyNonEmpty Iterator iterator(@PolyGrowShrink @PolyNonEmpty UnmodifiableCollection this) {
return new Iterator<>() {
private final Iterator extends E> i = c.iterator();
@Pure
@EnsuresNonEmptyIf(result = true, expression = "this")
public boolean hasNext() {return i.hasNext();}
- @SideEffectsOnly("this")
public E next(/*@NonEmpty Iterator this*/) {return i.next();}
public void remove() {
throw new UnsupportedOperationException();
@@ -1520,7 +1520,7 @@ public NavigableSet tailSet(E fromElement, boolean inclusive) {
* @return an unmodifiable view of the specified list.
*/
@SuppressWarnings("unchecked")
- public static @PolyNonEmpty List unmodifiableList(@PolyNonEmpty List extends T> list) {
+ public static @PolyGrowShrink @PolyNonEmpty List unmodifiableList(@PolyGrowShrink @PolyNonEmpty List extends T> list) {
if (list.getClass() == UnmodifiableList.class || list.getClass() == UnmodifiableRandomAccessList.class) {
return (List