Skip to content

Commit 4690577

Browse files
authored
@Shrinkable annotations
1 parent 71e71e4 commit 4690577

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+512
-296
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ jar tf checker-qual.jar | grep '\.java$' | sed 's/\/[^/]*\.java/;/' | sed 's/\//
133133
The result of the command will be a list of export lines.
134134
Replace the existing export lines present in
135135
`src/java.base/share/classes/module-info.java` with the newly-generated list of
136-
exports. If no new packages were added, then there are likely going to be no
137-
changes to the `module-info.java` file.
136+
exports. If no new packages were added, then likely no changes are needed
137+
in the `module-info.java` file.
138138

139139
Commit the changes, including the new `checker.jar` file and any new `.java`
140140
files in a `qual/` directory. (Both are used, by different parts of the build.)

checker-qual.jar

3.54 KB
Binary file not shown.

src/java.base/share/classes/java/lang/Iterable.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
package java.lang;
2626

27+
import org.checkerframework.checker.index.qual.PolyGrowShrink;
2728
import org.checkerframework.checker.nonempty.qual.PolyNonEmpty;
2829
import org.checkerframework.common.aliasing.qual.NonLeaked;
2930
import org.checkerframework.framework.qual.AnnotatedFor;
@@ -50,7 +51,7 @@ public interface Iterable<T> {
5051
*
5152
* @return an Iterator.
5253
*/
53-
@PolyNonEmpty Iterator<T> iterator(@PolyNonEmpty Iterable<T> this);
54+
@PolyGrowShrink @PolyNonEmpty Iterator<T> iterator(@PolyGrowShrink @PolyNonEmpty Iterable<T> this);
5455

5556
/**
5657
* Performs the given action for each element of the {@code Iterable}

src/java.base/share/classes/java/util/AbstractCollection.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
package java.util;
2727

2828
import org.checkerframework.checker.index.qual.NonNegative;
29+
import org.checkerframework.checker.index.qual.PolyGrowShrink;
30+
import org.checkerframework.checker.index.qual.Shrinkable;
2931
import org.checkerframework.checker.lock.qual.GuardSatisfied;
3032
import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf;
3133
import org.checkerframework.checker.nonempty.qual.PolyNonEmpty;
@@ -92,7 +94,7 @@ protected AbstractCollection() {
9294
* @return an iterator over the elements contained in this collection
9395
*/
9496
@SideEffectFree
95-
public abstract @PolyNonEmpty Iterator<E> iterator(@PolyNonEmpty AbstractCollection<E> this);
97+
public abstract @PolyGrowShrink @PolyNonEmpty Iterator<E> iterator(@PolyGrowShrink @PolyNonEmpty AbstractCollection<E> this);
9698

9799
@Pure
98100
public abstract @NonNegative int size(@GuardSatisfied AbstractCollection<E> this);
@@ -292,7 +294,7 @@ public boolean add(@GuardSatisfied AbstractCollection<E> this, E e) {
292294
* @throws ClassCastException {@inheritDoc}
293295
* @throws NullPointerException {@inheritDoc}
294296
*/
295-
public boolean remove(@GuardSatisfied AbstractCollection<E> this, @GuardSatisfied @UnknownSignedness Object o) {
297+
public boolean remove(@GuardSatisfied @Shrinkable AbstractCollection<E> this, @GuardSatisfied @UnknownSignedness Object o) {
296298
Iterator<E> it = iterator();
297299
if (o==null) {
298300
while (it.hasNext()) {
@@ -385,7 +387,7 @@ public boolean addAll(@GuardSatisfied AbstractCollection<E> this, Collection<? e
385387
* @see #remove(Object)
386388
* @see #contains(Object)
387389
*/
388-
public boolean removeAll(@GuardSatisfied AbstractCollection<E> this, Collection<? extends @UnknownSignedness Object> c) {
390+
public boolean removeAll(@GuardSatisfied @Shrinkable AbstractCollection<E> this, Collection<? extends @UnknownSignedness Object> c) {
389391
Objects.requireNonNull(c);
390392
boolean modified = false;
391393
Iterator<?> it = iterator();
@@ -420,7 +422,7 @@ public boolean removeAll(@GuardSatisfied AbstractCollection<E> this, Collection<
420422
* @see #remove(Object)
421423
* @see #contains(Object)
422424
*/
423-
public boolean retainAll(@GuardSatisfied AbstractCollection<E> this, Collection<? extends @UnknownSignedness Object> c) {
425+
public boolean retainAll(@GuardSatisfied @Shrinkable AbstractCollection<E> this, Collection<? extends @UnknownSignedness Object> c) {
424426
Objects.requireNonNull(c);
425427
boolean modified = false;
426428
Iterator<E> it = iterator();
@@ -449,7 +451,7 @@ public boolean retainAll(@GuardSatisfied AbstractCollection<E> this, Collection<
449451
*
450452
* @throws UnsupportedOperationException {@inheritDoc}
451453
*/
452-
public void clear(@GuardSatisfied AbstractCollection<E> this) {
454+
public void clear(@GuardSatisfied @Shrinkable AbstractCollection<E> this) {
453455
Iterator<E> it = iterator();
454456
while (it.hasNext()) {
455457
it.next();

src/java.base/share/classes/java/util/AbstractList.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@
2828
import org.checkerframework.checker.index.qual.GTENegativeOne;
2929
import org.checkerframework.checker.index.qual.IndexFor;
3030
import org.checkerframework.checker.index.qual.IndexOrHigh;
31+
import org.checkerframework.checker.index.qual.PolyGrowShrink;
32+
import org.checkerframework.checker.index.qual.Shrinkable;
3133
import org.checkerframework.checker.lock.qual.GuardSatisfied;
3234
import org.checkerframework.checker.nonempty.qual.EnsuresNonEmpty;
3335
import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf;
3436
import org.checkerframework.checker.nonempty.qual.NonEmpty;
37+
import org.checkerframework.checker.nonempty.qual.PolyNonEmpty;
3538
import org.checkerframework.checker.nullness.qual.Nullable;
3639
import org.checkerframework.checker.signedness.qual.UnknownSignedness;
3740
import org.checkerframework.dataflow.qual.Pure;
@@ -183,7 +186,7 @@ public void add(@GuardSatisfied AbstractList<E> this, @IndexOrHigh({"this"}) int
183186
* @throws UnsupportedOperationException {@inheritDoc}
184187
* @throws IndexOutOfBoundsException {@inheritDoc}
185188
*/
186-
public E remove(@GuardSatisfied AbstractList<E> this, @IndexFor({"this"}) int index) {
189+
public E remove(@GuardSatisfied @Shrinkable AbstractList<E> this, @IndexFor({"this"}) int index) {
187190
throw new UnsupportedOperationException();
188191
}
189192

@@ -261,7 +264,7 @@ public E remove(@GuardSatisfied AbstractList<E> this, @IndexFor({"this"}) int in
261264
* @throws UnsupportedOperationException if the {@code clear} operation
262265
* is not supported by this list
263266
*/
264-
public void clear(@GuardSatisfied AbstractList<E> this) {
267+
public void clear(@GuardSatisfied @Shrinkable AbstractList<E> this) {
265268
removeRange(0, size());
266269
}
267270

@@ -318,7 +321,7 @@ public boolean addAll(@GuardSatisfied AbstractList<E> this, @IndexOrHigh({"this"
318321
* @return an iterator over the elements in this list in proper sequence
319322
*/
320323
@SideEffectFree
321-
public Iterator<E> iterator() {
324+
public @PolyGrowShrink @PolyNonEmpty Iterator<E> iterator(@PolyGrowShrink @PolyNonEmpty AbstractList<E> this) {
322325
return new Itr();
323326
}
324327

@@ -330,7 +333,7 @@ public Iterator<E> iterator() {
330333
*
331334
* @see #listIterator(int)
332335
*/
333-
public ListIterator<E> listIterator() {
336+
public @PolyGrowShrink @PolyNonEmpty ListIterator<E> listIterator(@PolyGrowShrink @PolyNonEmpty AbstractList<E> this) {
334337
return listIterator(0);
335338
}
336339

@@ -357,7 +360,7 @@ public ListIterator<E> listIterator() {
357360
*
358361
* @throws IndexOutOfBoundsException {@inheritDoc}
359362
*/
360-
public ListIterator<E> listIterator(final @IndexOrHigh({"this"}) int index) {
363+
public @PolyGrowShrink ListIterator<E> listIterator(@PolyGrowShrink AbstractList<E> this, final @IndexOrHigh({"this"}) int index) {
361364
rangeCheckForAdd(index);
362365

363366
return new ListItr(index);
@@ -520,7 +523,7 @@ public void add(E e) {
520523
* {@code (fromIndex > toIndex)}
521524
*/
522525
@SideEffectFree
523-
public List<E> subList(@GuardSatisfied AbstractList<E> this, @IndexOrHigh({"this"}) int fromIndex, @IndexOrHigh({"this"}) int toIndex) {
526+
public @PolyGrowShrink List<E> subList(@GuardSatisfied @PolyGrowShrink AbstractList<E> this, @IndexOrHigh({"this"}) int fromIndex, @IndexOrHigh({"this"}) int toIndex) {
524527
subListRangeCheck(fromIndex, toIndex, size());
525528
return (this instanceof RandomAccess ?
526529
new RandomAccessSubList<>(this, fromIndex, toIndex) :
@@ -620,7 +623,7 @@ public int hashCode(@GuardSatisfied AbstractList<E> this) {
620623
* @param fromIndex index of first element to be removed
621624
* @param toIndex index after last element to be removed
622625
*/
623-
protected void removeRange(@IndexOrHigh({"this"}) int fromIndex, @IndexOrHigh({"this"}) int toIndex) {
626+
protected void removeRange(@GuardSatisfied @Shrinkable AbstractList<E> this, @IndexOrHigh({"this"}) int fromIndex, @IndexOrHigh({"this"}) int toIndex) {
624627
ListIterator<E> it = listIterator(fromIndex);
625628
for (int i=0, n=toIndex-fromIndex; i<n; i++) {
626629
it.next();

src/java.base/share/classes/java/util/AbstractQueue.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
package java.util;
3737

38+
import org.checkerframework.checker.index.qual.Shrinkable;
3839
import org.checkerframework.checker.lock.qual.GuardSatisfied;
3940
import org.checkerframework.checker.nonempty.qual.EnsuresNonEmpty;
4041
import org.checkerframework.checker.nonempty.qual.NonEmpty;
@@ -116,7 +117,7 @@ public boolean add(@GuardSatisfied AbstractQueue<E> this, E e) {
116117
* @return the head of this queue
117118
* @throws NoSuchElementException if this queue is empty
118119
*/
119-
public E remove(@GuardSatisfied @NonEmpty AbstractQueue<E> this) {
120+
public E remove(@GuardSatisfied @NonEmpty @Shrinkable AbstractQueue<E> this) {
120121
E x = poll();
121122
if (x != null)
122123
return x;
@@ -150,7 +151,7 @@ public E element(@GuardSatisfied @NonEmpty AbstractQueue<E> this) {
150151
* <p>This implementation repeatedly invokes {@link #poll poll} until it
151152
* returns {@code null}.
152153
*/
153-
public void clear(@GuardSatisfied AbstractQueue<E> this) {
154+
public void clear(@GuardSatisfied @Shrinkable AbstractQueue<E> this) {
154155
while (poll() != null)
155156
;
156157
}

src/java.base/share/classes/java/util/AbstractSequentialList.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525

2626
package java.util;
2727

28+
import org.checkerframework.checker.index.qual.PolyGrowShrink;
29+
import org.checkerframework.checker.index.qual.Shrinkable;
2830
import org.checkerframework.checker.lock.qual.GuardSatisfied;
31+
import org.checkerframework.checker.nonempty.qual.PolyNonEmpty;
2932
import org.checkerframework.dataflow.qual.Pure;
3033
import org.checkerframework.dataflow.qual.SideEffectFree;
3134
import org.checkerframework.framework.qual.AnnotatedFor;
@@ -175,7 +178,7 @@ public void add(@GuardSatisfied AbstractSequentialList<E> this, int index, E ele
175178
* @throws UnsupportedOperationException {@inheritDoc}
176179
* @throws IndexOutOfBoundsException {@inheritDoc}
177180
*/
178-
public E remove(@GuardSatisfied AbstractSequentialList<E> this, int index) {
181+
public E remove(@GuardSatisfied @Shrinkable AbstractSequentialList<E> this, int index) {
179182
try {
180183
ListIterator<E> e = listIterator(index);
181184
E outCast = e.next();
@@ -244,7 +247,7 @@ public boolean addAll(@GuardSatisfied AbstractSequentialList<E> this, int index,
244247
* @return an iterator over the elements in this list (in proper sequence)
245248
*/
246249
@SideEffectFree
247-
public Iterator<E> iterator() {
250+
public @PolyGrowShrink @PolyNonEmpty Iterator<E> iterator(@PolyGrowShrink @PolyNonEmpty AbstractSequentialList<E> this) {
248251
return listIterator();
249252
}
250253

@@ -258,5 +261,5 @@ public Iterator<E> iterator() {
258261
* sequence)
259262
* @throws IndexOutOfBoundsException {@inheritDoc}
260263
*/
261-
public abstract ListIterator<E> listIterator(int index);
264+
public abstract @PolyGrowShrink ListIterator<E> listIterator(@PolyGrowShrink AbstractSequentialList<E> this, int index);
262265
}

src/java.base/share/classes/java/util/ArrayDeque.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
package java.util;
3636

3737
import org.checkerframework.checker.index.qual.NonNegative;
38+
import org.checkerframework.checker.index.qual.PolyGrowShrink;
39+
import org.checkerframework.checker.index.qual.Shrinkable;
3840
import org.checkerframework.checker.lock.qual.GuardSatisfied;
3941
import org.checkerframework.checker.nonempty.qual.EnsuresNonEmpty;
4042
import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf;
@@ -375,7 +377,7 @@ public boolean offerLast(E e) {
375377
/**
376378
* @throws NoSuchElementException {@inheritDoc}
377379
*/
378-
public E removeFirst(@GuardSatisfied @NonEmpty ArrayDeque<E> this) {
380+
public E removeFirst(@GuardSatisfied @NonEmpty @Shrinkable ArrayDeque<E> this) {
379381
E e = pollFirst();
380382
if (e == null)
381383
throw new NoSuchElementException();
@@ -385,14 +387,14 @@ public E removeFirst(@GuardSatisfied @NonEmpty ArrayDeque<E> this) {
385387
/**
386388
* @throws NoSuchElementException {@inheritDoc}
387389
*/
388-
public E removeLast(@GuardSatisfied @NonEmpty ArrayDeque<E> this) {
390+
public E removeLast(@GuardSatisfied @NonEmpty @Shrinkable ArrayDeque<E> this) {
389391
E e = pollLast();
390392
if (e == null)
391393
throw new NoSuchElementException();
392394
return e;
393395
}
394396

395-
public @Nullable E pollFirst(@GuardSatisfied ArrayDeque<E> this) {
397+
public @Nullable E pollFirst(@GuardSatisfied @Shrinkable ArrayDeque<E> this) {
396398
final Object[] es;
397399
final int h;
398400
E e = elementAt(es = elements, h = head);
@@ -403,7 +405,7 @@ public E removeLast(@GuardSatisfied @NonEmpty ArrayDeque<E> this) {
403405
return e;
404406
}
405407

406-
public @Nullable E pollLast(@GuardSatisfied ArrayDeque<E> this) {
408+
public @Nullable E pollLast(@GuardSatisfied @Shrinkable ArrayDeque<E> this) {
407409
final Object[] es;
408410
final int t;
409411
E e = elementAt(es = elements, t = dec(tail, es.length));
@@ -456,7 +458,7 @@ public E getLast(@GuardSatisfied @NonEmpty ArrayDeque<E> this) {
456458
* @param o element to be removed from this deque, if present
457459
* @return {@code true} if the deque contained the specified element
458460
*/
459-
public boolean removeFirstOccurrence(@GuardSatisfied ArrayDeque<E> this, @Nullable Object o) {
461+
public boolean removeFirstOccurrence(@GuardSatisfied @Shrinkable ArrayDeque<E> this, @GuardSatisfied @Nullable @UnknownSignedness Object o) {
460462
if (o != null) {
461463
final Object[] es = elements;
462464
for (int i = head, end = tail, to = (i <= end) ? end : es.length;
@@ -484,7 +486,7 @@ public boolean removeFirstOccurrence(@GuardSatisfied ArrayDeque<E> this, @Nullab
484486
* @param o element to be removed from this deque, if present
485487
* @return {@code true} if the deque contained the specified element
486488
*/
487-
public boolean removeLastOccurrence(@GuardSatisfied ArrayDeque<E> this, @Nullable Object o) {
489+
public boolean removeLastOccurrence(@GuardSatisfied @Shrinkable ArrayDeque<E> this, @GuardSatisfied @Nullable @UnknownSignedness Object o) {
488490
if (o != null) {
489491
final Object[] es = elements;
490492
for (int i = tail, end = head, to = (i >= end) ? end : 0;
@@ -541,7 +543,7 @@ public boolean offer(@GuardSatisfied ArrayDeque<E> this, E e) {
541543
* @return the head of the queue represented by this deque
542544
* @throws NoSuchElementException {@inheritDoc}
543545
*/
544-
public E remove(@GuardSatisfied @NonEmpty ArrayDeque<E> this) {
546+
public E remove(@GuardSatisfied @NonEmpty @Shrinkable ArrayDeque<E> this) {
545547
return removeFirst();
546548
}
547549

@@ -555,7 +557,7 @@ public E remove(@GuardSatisfied @NonEmpty ArrayDeque<E> this) {
555557
* @return the head of the queue represented by this deque, or
556558
* {@code null} if this deque is empty
557559
*/
558-
public @Nullable E poll(@GuardSatisfied ArrayDeque<E> this) {
560+
public @Nullable E poll(@GuardSatisfied @Shrinkable ArrayDeque<E> this) {
559561
return pollFirst();
560562
}
561563

@@ -612,7 +614,7 @@ public void push(@GuardSatisfied ArrayDeque<E> this, E e) {
612614
* of the stack represented by this deque)
613615
* @throws NoSuchElementException {@inheritDoc}
614616
*/
615-
public E pop(@GuardSatisfied @NonEmpty ArrayDeque<E> this) {
617+
public E pop(@GuardSatisfied @NonEmpty @Shrinkable ArrayDeque<E> this) {
616618
return removeFirst();
617619
}
618620

@@ -694,11 +696,11 @@ public boolean isEmpty(@GuardSatisfied ArrayDeque<E> this) {
694696
* @return an iterator over the elements in this deque
695697
*/
696698
@SideEffectFree
697-
public @PolyNonEmpty Iterator<E> iterator(@PolyNonEmpty ArrayDeque<E> this) {
699+
public @PolyGrowShrink @PolyNonEmpty Iterator<E> iterator(@PolyGrowShrink @PolyNonEmpty ArrayDeque<E> this) {
698700
return new DeqIterator();
699701
}
700702

701-
public @PolyNonEmpty Iterator<E> descendingIterator(@PolyNonEmpty ArrayDeque<E> this) {
703+
public @PolyGrowShrink @PolyNonEmpty Iterator<E> descendingIterator(@PolyGrowShrink @PolyNonEmpty ArrayDeque<E> this) {
702704
return new DescendingIterator();
703705
}
704706

@@ -927,23 +929,23 @@ public void forEach(Consumer<? super E> action) {
927929
/**
928930
* @throws NullPointerException {@inheritDoc}
929931
*/
930-
public boolean removeIf(Predicate<? super E> filter) {
932+
public boolean removeIf(@Shrinkable ArrayDeque<E> this, Predicate<? super E> filter) {
931933
Objects.requireNonNull(filter);
932934
return bulkRemove(filter);
933935
}
934936

935937
/**
936938
* @throws NullPointerException {@inheritDoc}
937939
*/
938-
public boolean removeAll(Collection<? extends @UnknownSignedness Object> c) {
940+
public boolean removeAll(@Shrinkable ArrayDeque<E> this, Collection<? extends @UnknownSignedness Object> c) {
939941
Objects.requireNonNull(c);
940942
return bulkRemove(e -> c.contains(e));
941943
}
942944

943945
/**
944946
* @throws NullPointerException {@inheritDoc}
945947
*/
946-
public boolean retainAll(Collection<? extends @UnknownSignedness Object> c) {
948+
public boolean retainAll(@GuardSatisfied @Shrinkable ArrayDeque<E> this, Collection<? extends @UnknownSignedness Object> c) {
947949
Objects.requireNonNull(c);
948950
return bulkRemove(e -> !c.contains(e));
949951
}
@@ -1059,15 +1061,15 @@ public boolean contains(@GuardSatisfied ArrayDeque<E> this, @GuardSatisfied @Nul
10591061
* @param o element to be removed from this deque, if present
10601062
* @return {@code true} if this deque contained the specified element
10611063
*/
1062-
public boolean remove(@GuardSatisfied ArrayDeque<E> this, @GuardSatisfied @Nullable @UnknownSignedness Object o) {
1064+
public boolean remove(@GuardSatisfied @Shrinkable ArrayDeque<E> this, @GuardSatisfied @Nullable @UnknownSignedness Object o) {
10631065
return removeFirstOccurrence(o);
10641066
}
10651067

10661068
/**
10671069
* Removes all of the elements from this deque.
10681070
* The deque will be empty after this call returns.
10691071
*/
1070-
public void clear(@GuardSatisfied ArrayDeque<E> this) {
1072+
public void clear(@GuardSatisfied @Shrinkable ArrayDeque<E> this) {
10711073
circularClear(elements, head, tail);
10721074
head = tail = 0;
10731075
}

0 commit comments

Comments
 (0)