From a99276175a93a1895a29e4bd0e15de5a58f03bf9 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Mon, 18 May 2026 17:58:52 -0700 Subject: [PATCH 01/15] Add `@DoesNotUnrefineReceiver("modifiability")` annotations --- .../classes/java/util/AbstractCollection.java | 7 +++ .../share/classes/java/util/AbstractList.java | 8 +++ .../share/classes/java/util/AbstractMap.java | 15 +++++ .../classes/java/util/AbstractQueue.java | 5 ++ .../share/classes/java/util/AbstractSet.java | 2 + .../share/classes/java/util/ArrayDeque.java | 24 ++++++++ .../share/classes/java/util/ArrayList.java | 33 +++++++++++ .../share/classes/java/util/Collection.java | 10 ++++ .../share/classes/java/util/Collections.java | 36 ++++++++++++ .../share/classes/java/util/Deque.java | 25 ++++++++ .../share/classes/java/util/EnumSet.java | 5 ++ .../share/classes/java/util/HashMap.java | 27 +++++++++ .../share/classes/java/util/HashSet.java | 2 + .../share/classes/java/util/Hashtable.java | 23 ++++++++ .../classes/java/util/IdentityHashMap.java | 16 +++++ .../share/classes/java/util/Iterator.java | 4 ++ .../share/classes/java/util/JumboEnumSet.java | 4 ++ .../classes/java/util/LinkedHashMap.java | 37 ++++++++++++ .../classes/java/util/LinkedHashSet.java | 12 ++++ .../share/classes/java/util/LinkedList.java | 57 ++++++++++++++++++ .../share/classes/java/util/List.java | 2 + .../share/classes/java/util/ListIterator.java | 6 ++ .../share/classes/java/util/Map.java | 16 +++++ .../share/classes/java/util/NavigableMap.java | 3 + .../share/classes/java/util/NavigableSet.java | 8 +++ .../classes/java/util/PrimitiveIterator.java | 14 +++++ .../share/classes/java/util/Properties.java | 20 +++++++ .../share/classes/java/util/Queue.java | 6 ++ .../classes/java/util/RegularEnumSet.java | 12 ++++ .../java/util/SequencedCollection.java | 7 +++ .../share/classes/java/util/SequencedMap.java | 10 ++++ .../share/classes/java/util/SequencedSet.java | 3 + .../share/classes/java/util/Set.java | 1 + .../share/classes/java/util/SortedMap.java | 4 ++ .../share/classes/java/util/SortedSet.java | 7 +++ .../share/classes/java/util/Stack.java | 3 + .../share/classes/java/util/TreeMap.java | 17 ++++++ .../share/classes/java/util/TreeSet.java | 12 ++++ .../share/classes/java/util/Vector.java | 25 ++++++++ .../share/classes/java/util/WeakHashMap.java | 14 +++++ .../util/concurrent/ArrayBlockingQueue.java | 16 +++++ .../util/concurrent/ConcurrentHashMap.java | 32 ++++++++++ .../concurrent/ConcurrentLinkedDeque.java | 24 ++++++++ .../concurrent/ConcurrentLinkedQueue.java | 11 ++++ .../concurrent/ConcurrentSkipListMap.java | 38 ++++++++++++ .../concurrent/ConcurrentSkipListSet.java | 7 +++ .../util/concurrent/CopyOnWriteArrayList.java | 58 +++++++++++++++++++ .../util/concurrent/CopyOnWriteArraySet.java | 8 +++ .../java/util/concurrent/DelayQueue.java | 14 +++++ .../util/concurrent/LinkedBlockingDeque.java | 38 ++++++++++++ .../util/concurrent/LinkedBlockingQueue.java | 15 +++++ .../util/concurrent/LinkedTransferQueue.java | 19 ++++++ .../concurrent/PriorityBlockingQueue.java | 16 +++++ .../util/concurrent/SynchronousQueue.java | 13 +++++ 54 files changed, 851 insertions(+) diff --git a/src/java.base/share/classes/java/util/AbstractCollection.java b/src/java.base/share/classes/java/util/AbstractCollection.java index 7b1300ad87e46..11a4724781b54 100644 --- a/src/java.base/share/classes/java/util/AbstractCollection.java +++ b/src/java.base/share/classes/java/util/AbstractCollection.java @@ -35,6 +35,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; @@ -275,6 +276,7 @@ private static T[] finishToArray(T[] r, Iterator it) { * @throws IllegalArgumentException {@inheritDoc} * @throws IllegalStateException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean add(@GuardSatisfied AbstractCollection this, E e) { throw new UnsupportedOperationException(); } @@ -296,6 +298,7 @@ public boolean add(@GuardSatisfied AbstractCollection this, E e) { * @throws ClassCastException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @CanShrink AbstractCollection this, @GuardSatisfied @UnknownSignedness Object o) { Iterator it = iterator(); if (o==null) { @@ -359,6 +362,7 @@ public boolean containsAll(@GuardSatisfied AbstractCollection this, @GuardSat * * @see #add(Object) */ + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@GuardSatisfied AbstractCollection this, Collection c) { boolean modified = false; for (E e : c) @@ -389,6 +393,7 @@ public boolean addAll(@GuardSatisfied AbstractCollection this, Collection this, Collection c) { Objects.requireNonNull(c); boolean modified = false; @@ -424,6 +429,7 @@ public boolean removeAll(@GuardSatisfied @CanShrink AbstractCollection this, * @see #remove(Object) * @see #contains(Object) */ + @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(@GuardSatisfied @CanShrink AbstractCollection this, Collection c) { Objects.requireNonNull(c); boolean modified = false; @@ -453,6 +459,7 @@ public boolean retainAll(@GuardSatisfied @CanShrink AbstractCollection this, * * @throws UnsupportedOperationException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink AbstractCollection this) { Iterator it = iterator(); while (it.hasNext()) { diff --git a/src/java.base/share/classes/java/util/AbstractList.java b/src/java.base/share/classes/java/util/AbstractList.java index cb72fccb35f75..552ac7bdd81ab 100644 --- a/src/java.base/share/classes/java/util/AbstractList.java +++ b/src/java.base/share/classes/java/util/AbstractList.java @@ -37,6 +37,7 @@ import org.checkerframework.checker.nonempty.qual.PolyNonEmpty; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; @@ -131,6 +132,7 @@ protected AbstractList() { * prevents it from being added to this list */ @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") public boolean add(@GuardSatisfied AbstractList this, E e) { add(size(), e); return true; @@ -157,6 +159,7 @@ public boolean add(@GuardSatisfied AbstractList this, E e) { * @throws IllegalArgumentException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public E set(@GuardSatisfied AbstractList this, @IndexFor({"this"}) int index, E element) { throw new UnsupportedOperationException(); } @@ -174,6 +177,7 @@ public E set(@GuardSatisfied AbstractList this, @IndexFor({"this"}) int index * @throws IllegalArgumentException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public void add(@GuardSatisfied AbstractList this, @IndexOrHigh({"this"}) int index, E element) { throw new UnsupportedOperationException(); } @@ -188,6 +192,7 @@ public void add(@GuardSatisfied AbstractList this, @IndexOrHigh({"this"}) int * @throws UnsupportedOperationException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @CanShrink AbstractList this, @IndexFor({"this"}) int index) { throw new UnsupportedOperationException(); } @@ -266,6 +271,7 @@ public E remove(@GuardSatisfied @CanShrink AbstractList this, @IndexFor({"thi * @throws UnsupportedOperationException if the {@code clear} operation * is not supported by this list */ + @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink AbstractList this) { removeRange(0, size()); } @@ -290,6 +296,7 @@ public void clear(@GuardSatisfied @CanShrink AbstractList this) { * @throws IllegalArgumentException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@GuardSatisfied AbstractList this, @IndexOrHigh({"this"}) int index, Collection c) { rangeCheckForAdd(index); boolean modified = false; @@ -625,6 +632,7 @@ public int hashCode(@GuardSatisfied AbstractList this) { * @param fromIndex index of first element to be removed * @param toIndex index after last element to be removed */ + @DoesNotUnrefineReceiver("modifiability") protected void removeRange(@GuardSatisfied @CanShrink AbstractList this, @IndexOrHigh({"this"}) int fromIndex, @IndexOrHigh({"this"}) int toIndex) { ListIterator it = listIterator(fromIndex); for (int i=0, n=toIndex-fromIndex; i this, @GuardSatisfi */ @ReleasesNoLocks @EnsuresKeyFor(value={"#1"}, map={"this"}) + @DoesNotUnrefineReceiver("modifiability") public @Nullable V put(@GuardSatisfied AbstractMap this, K key, V value) { throw new UnsupportedOperationException(); } @@ -263,6 +265,7 @@ public boolean containsKey(@GuardSatisfied AbstractMap this, @GuardSatisfi * @throws ClassCastException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public @Nullable V remove(@GuardSatisfied AbstractMap this, @GuardSatisfied @UnknownSignedness Object key) { Iterator> i = entrySet().iterator(); Entry correctEntry = null; @@ -308,6 +311,7 @@ public boolean containsKey(@GuardSatisfied AbstractMap this, @GuardSatisfi * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public void putAll(@GuardSatisfied AbstractMap this, Map m) { for (Map.Entry e : m.entrySet()) put(e.getKey(), e.getValue()); @@ -325,6 +329,7 @@ public void putAll(@GuardSatisfied AbstractMap this, Map this) { entrySet().clear(); } @@ -395,6 +400,7 @@ public K next(/*@NonEmpty Iterator this*/) { return i.next().getKey(); } + @DoesNotUnrefineReceiver("modifiability") public void remove() { i.remove(); } @@ -412,6 +418,7 @@ public boolean isEmpty() { return AbstractMap.this.isEmpty(); } + @DoesNotUnrefineReceiver("modifiability") public void clear() { AbstractMap.this.clear(); } @@ -462,6 +469,7 @@ public V next(/*@NonEmpty Iterator this*/) { return i.next().getValue(); } + @DoesNotUnrefineReceiver("modifiability") public void remove() { i.remove(); } @@ -479,6 +487,7 @@ public boolean isEmpty() { return AbstractMap.this.isEmpty(); } + @DoesNotUnrefineReceiver("modifiability") public void clear() { AbstractMap.this.clear(); } @@ -718,6 +727,7 @@ public V getValue(AbstractMap.@GuardSatisfied SimpleEntry this) { * @param value new value to be stored in this entry * @return the old value corresponding to the entry */ + @DoesNotUnrefineReceiver("modifiability") public V setValue(AbstractMap.@GuardSatisfied SimpleEntry this, V value) { V oldValue = this.value; this.value = value; @@ -963,6 +973,7 @@ public String toString(AbstractMap.@GuardSatisfied SimpleImmutableEntry th public boolean add(E t) { throw uoe(); } public boolean addAll(Collection c) { throw uoe(); } + @DoesNotUnrefineReceiver("modifiability") public void clear() { view().clear(); } public boolean contains(Object o) { return view().contains(o); } public boolean containsAll(Collection c) { return view().containsAll(c); } @@ -970,9 +981,13 @@ public String toString(AbstractMap.@GuardSatisfied SimpleImmutableEntry th public boolean isEmpty() { return view().isEmpty(); } public Iterator iterator() { return view().iterator(); } public Stream parallelStream() { return view().parallelStream(); } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(Object o) { return view().remove(o); } + @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { return view().removeAll(c); } + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { return view().removeIf(filter); } + @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { return view().retainAll(c); } public int size() { return view().size(); } public Spliterator spliterator() { return view().spliterator(); } diff --git a/src/java.base/share/classes/java/util/AbstractQueue.java b/src/java.base/share/classes/java/util/AbstractQueue.java index 0bd11fc96d0f9..8870a514949cc 100644 --- a/src/java.base/share/classes/java/util/AbstractQueue.java +++ b/src/java.base/share/classes/java/util/AbstractQueue.java @@ -39,6 +39,7 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nonempty.qual.EnsuresNonEmpty; import org.checkerframework.checker.nonempty.qual.NonEmpty; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.framework.qual.AnnotatedFor; /** @@ -99,6 +100,7 @@ protected AbstractQueue() { * prevents it from being added to this queue */ @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") public boolean add(@GuardSatisfied AbstractQueue this, E e) { if (offer(e)) return true; @@ -117,6 +119,7 @@ public boolean add(@GuardSatisfied AbstractQueue this, E e) { * @return the head of this queue * @throws NoSuchElementException if this queue is empty */ + @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @NonEmpty @CanShrink AbstractQueue this) { E x = poll(); if (x != null) @@ -151,6 +154,7 @@ public E element(@GuardSatisfied @NonEmpty AbstractQueue this) { *

This implementation repeatedly invokes {@link #poll poll} until it * returns {@code null}. */ + @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink AbstractQueue this) { while (poll() != null) ; @@ -185,6 +189,7 @@ public void clear(@GuardSatisfied @CanShrink AbstractQueue this) { * this time due to insertion restrictions * @see #add(Object) */ + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@GuardSatisfied AbstractQueue this, Collection c) { if (c == null) throw new NullPointerException(); diff --git a/src/java.base/share/classes/java/util/AbstractSet.java b/src/java.base/share/classes/java/util/AbstractSet.java index a18723fbaca86..5ba0ab38ee047 100644 --- a/src/java.base/share/classes/java/util/AbstractSet.java +++ b/src/java.base/share/classes/java/util/AbstractSet.java @@ -28,6 +28,7 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; @@ -174,6 +175,7 @@ public int hashCode(@GuardSatisfied AbstractSet this) { * @see #remove(Object) * @see #contains(Object) */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(@GuardSatisfied AbstractSet this, Collection c) { Objects.requireNonNull(c); boolean modified = false; diff --git a/src/java.base/share/classes/java/util/ArrayDeque.java b/src/java.base/share/classes/java/util/ArrayDeque.java index bb84f5911550c..ed41a5775dd00 100644 --- a/src/java.base/share/classes/java/util/ArrayDeque.java +++ b/src/java.base/share/classes/java/util/ArrayDeque.java @@ -48,6 +48,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; @@ -301,6 +302,7 @@ static final E nonNullElementAt(@PolyNull @PolySigned Object[] es, int i) { * @param e the element to add * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public void addFirst(@GuardSatisfied ArrayDeque this, E e) { if (e == null) throw new NullPointerException(); @@ -318,6 +320,7 @@ public void addFirst(@GuardSatisfied ArrayDeque this, E e) { * @param e the element to add * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public void addLast(@GuardSatisfied ArrayDeque this, E e) { if (e == null) throw new NullPointerException(); @@ -337,6 +340,7 @@ public void addLast(@GuardSatisfied ArrayDeque this, E e) { * @throws NullPointerException if the specified collection or any * of its elements are null */ + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { final int s, needed; if ((needed = (s = size()) + c.size() + 1 - elements.length) > 0) @@ -356,6 +360,7 @@ private void copyElements(Collection c) { * @return {@code true} (as specified by {@link Deque#offerFirst}) * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean offerFirst(E e) { addFirst(e); return true; @@ -368,6 +373,7 @@ public boolean offerFirst(E e) { * @return {@code true} (as specified by {@link Deque#offerLast}) * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean offerLast(E e) { addLast(e); return true; @@ -376,6 +382,7 @@ public boolean offerLast(E e) { /** * @throws NoSuchElementException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public E removeFirst(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { E e = pollFirst(); if (e == null) @@ -386,6 +393,7 @@ public E removeFirst(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { /** * @throws NoSuchElementException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public E removeLast(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { E e = pollLast(); if (e == null) @@ -393,6 +401,7 @@ public E removeLast(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { return e; } + @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollFirst(@GuardSatisfied @CanShrink ArrayDeque this) { final Object[] es; final int h; @@ -404,6 +413,7 @@ public E removeLast(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { return e; } + @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollLast(@GuardSatisfied @CanShrink ArrayDeque this) { final Object[] es; final int t; @@ -457,6 +467,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 */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeFirstOccurrence(@GuardSatisfied @CanShrink ArrayDeque this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { if (o != null) { final Object[] es = elements; @@ -485,6 +496,7 @@ public boolean removeFirstOccurrence(@GuardSatisfied @CanShrink ArrayDeque th * @param o element to be removed from this deque, if present * @return {@code true} if the deque contained the specified element */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeLastOccurrence(@GuardSatisfied @CanShrink ArrayDeque this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { if (o != null) { final Object[] es = elements; @@ -513,6 +525,7 @@ public boolean removeLastOccurrence(@GuardSatisfied @CanShrink ArrayDeque thi * @throws NullPointerException if the specified element is null */ @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") public boolean add(@GuardSatisfied ArrayDeque this, E e) { addLast(e); return true; @@ -527,6 +540,7 @@ public boolean add(@GuardSatisfied ArrayDeque this, E e) { * @return {@code true} (as specified by {@link Queue#offer}) * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean offer(@GuardSatisfied ArrayDeque this, E e) { return offerLast(e); } @@ -542,6 +556,7 @@ public boolean offer(@GuardSatisfied ArrayDeque this, E e) { * @return the head of the queue represented by this deque * @throws NoSuchElementException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { return removeFirst(); } @@ -556,6 +571,7 @@ public E remove(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { * @return the head of the queue represented by this deque, or * {@code null} if this deque is empty */ + @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink ArrayDeque this) { return pollFirst(); } @@ -599,6 +615,7 @@ public E element(@GuardSatisfied @NonEmpty ArrayDeque this) { * @param e the element to push * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public void push(@GuardSatisfied ArrayDeque this, E e) { addFirst(e); } @@ -613,6 +630,7 @@ public void push(@GuardSatisfied ArrayDeque this, E e) { * of the stack represented by this deque) * @throws NoSuchElementException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public E pop(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { return removeFirst(); } @@ -740,6 +758,7 @@ void postDelete(boolean leftShifted) { cursor = dec(cursor, elements.length); } + @DoesNotUnrefineReceiver("modifiability") public final void remove() { if (lastRet < 0) throw new IllegalStateException(); @@ -928,6 +947,7 @@ public void forEach(Consumer action) { /** * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink ArrayDeque this, Predicate filter) { Objects.requireNonNull(filter); return bulkRemove(filter); @@ -936,6 +956,7 @@ public boolean removeIf(@CanShrink ArrayDeque this, Predicate filt /** * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(@CanShrink ArrayDeque this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> c.contains(e)); @@ -944,6 +965,7 @@ public boolean removeAll(@CanShrink ArrayDeque this, Collection this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> !c.contains(e)); @@ -1060,6 +1082,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 */ + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @CanShrink ArrayDeque this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { return removeFirstOccurrence(o); } @@ -1068,6 +1091,7 @@ public boolean remove(@GuardSatisfied @CanShrink ArrayDeque this, @GuardSatis * Removes all of the elements from this deque. * The deque will be empty after this call returns. */ + @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink 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 7b5ae4f761d8d..5e70be7c83155 100644 --- a/src/java.base/share/classes/java/util/ArrayList.java +++ b/src/java.base/share/classes/java/util/ArrayList.java @@ -40,6 +40,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; @@ -504,6 +505,7 @@ public E getLast() { * @throws IndexOutOfBoundsException {@inheritDoc} */ @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E set(@GuardSatisfied ArrayList this, @NonNegative int index, E element) { Objects.checkIndex(index, size); E oldValue = elementData(index); @@ -567,6 +569,7 @@ public void add(@GuardSatisfied ArrayList this, @NonNegative int index, E ele * * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") public void addFirst(E element) { add(0, element); } @@ -576,6 +579,7 @@ public void addFirst(E element) { * * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") public void addLast(E element) { add(element); } @@ -589,6 +593,7 @@ public void addLast(E element) { * @return the element that was removed from the list * @throws IndexOutOfBoundsException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @CanShrink ArrayList this, @NonNegative int index) { Objects.checkIndex(index, size); final Object[] es = elementData; @@ -605,6 +610,7 @@ public E remove(@GuardSatisfied @CanShrink ArrayList this, @NonNegative int i * @throws NoSuchElementException {@inheritDoc} * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") public E removeFirst() { if (size == 0) { throw new NoSuchElementException(); @@ -622,6 +628,7 @@ public E removeFirst() { * @throws NoSuchElementException {@inheritDoc} * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") public E removeLast() { int last = size - 1; if (last < 0) { @@ -736,6 +743,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 */ + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @CanShrink ArrayList this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { final Object[] es = elementData; final int size = this.size; @@ -772,6 +780,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. */ + @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink ArrayList this) { modCount++; final Object[] es = elementData; @@ -915,6 +924,7 @@ private static String outOfBoundsMsg(int fromIndex, int toIndex) { * or if the specified collection is null * @see Collection#contains(Object) */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(@CanShrink ArrayList this, Collection c) { return batchRemove(c, false, 0, size); } @@ -935,6 +945,7 @@ public boolean removeAll(@CanShrink ArrayList this, Collection this, Collection c) { return batchRemove(c, true, 0, size); } @@ -1095,6 +1106,7 @@ public boolean hasNext() { @SuppressWarnings("unchecked") @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty Itr this) { checkForComodification(); int i = cursor; @@ -1107,6 +1119,7 @@ public E next(@NonEmpty Itr this) { return (E) elementData[lastRet = i]; } + @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastRet < 0) throw new IllegalStateException(); @@ -1160,15 +1173,18 @@ public boolean hasPrevious() { return cursor != 0; } + @DoesNotUnrefineReceiver("modifiability") public int nextIndex() { return cursor; } + @DoesNotUnrefineReceiver("modifiability") public int previousIndex() { return cursor - 1; } @SuppressWarnings("unchecked") + @DoesNotUnrefineReceiver("modifiability") public E previous() { checkForComodification(); int i = cursor - 1; @@ -1181,6 +1197,7 @@ public E previous() { return (E) elementData[lastRet = i]; } + @DoesNotUnrefineReceiver("modifiability") public void set(E e) { if (lastRet < 0) throw new IllegalStateException(); @@ -1193,6 +1210,7 @@ public void set(E e) { } } + @DoesNotUnrefineReceiver("modifiability") public void add(E e) { checkForComodification(); @@ -1237,6 +1255,7 @@ public void add(E e) { * @throws IndexOutOfBoundsException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public @PolyGrowShrink List subList(@GuardSatisfied @PolyGrowShrink ArrayList this, @NonNegative int fromIndex, @NonNegative int toIndex) { subListRangeCheck(fromIndex, toIndex, size); return new SubList<>(this, fromIndex, toIndex); @@ -1270,6 +1289,7 @@ private SubList(SubList parent, int fromIndex, int toIndex) { this.modCount = parent.modCount; } + @DoesNotUnrefineReceiver("modifiability") public E set(@NonNegative int index, E element) { Objects.checkIndex(index, size); checkForComodification(); @@ -1290,6 +1310,7 @@ public E get(@NonNegative int index) { return size; } + @DoesNotUnrefineReceiver("modifiability") public void add(@NonNegative int index, E element) { rangeCheckForAdd(index); checkForComodification(); @@ -1297,6 +1318,7 @@ public void add(@NonNegative int index, E element) { updateSizeAndModCount(1); } + @DoesNotUnrefineReceiver("modifiability") public E remove(@NonNegative int index) { Objects.checkIndex(index, size); checkForComodification(); @@ -1305,16 +1327,19 @@ public E remove(@NonNegative int index) { return result; } + @DoesNotUnrefineReceiver("modifiability") protected void removeRange(int fromIndex, int toIndex) { checkForComodification(); root.removeRange(offset + fromIndex, offset + toIndex); updateSizeAndModCount(fromIndex - toIndex); } + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { return addAll(this.size, c); } + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@NonNegative int index, Collection c) { rangeCheckForAdd(index); int cSize = c.size(); @@ -1326,14 +1351,17 @@ public boolean addAll(@NonNegative int index, Collection c) { return true; } + @DoesNotUnrefineReceiver("modifiability") public void replaceAll(UnaryOperator operator) { root.replaceAllRange(operator, offset, offset + size); } + @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { return batchRemove(c, false); } + @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { return batchRemove(c, true); } @@ -1348,6 +1376,7 @@ private boolean batchRemove(Collection c, boolean complement) { return modified; } + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { checkForComodification(); int oldSize = root.size; @@ -1642,6 +1671,7 @@ public int characteristics() { * @throws NullPointerException {@inheritDoc} */ @Override + @DoesNotUnrefineReceiver("modifiability") public void forEach(Consumer action) { Objects.requireNonNull(action); final int expectedModCount = modCount; @@ -1797,6 +1827,7 @@ private static boolean isClear(long[] bits, int i) { * @throws NullPointerException {@inheritDoc} */ @Override + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink ArrayList this, Predicate filter) { return removeIf(filter, 0, size); } @@ -1840,6 +1871,7 @@ boolean removeIf(@CanShrink ArrayList this, Predicate filter, int @SuppressWarnings({"unchecked"}) @Override + @DoesNotUnrefineReceiver("modifiability") public void replaceAll(UnaryOperator operator) { replaceAllRange(operator, 0, size); // TODO(8203662): remove increment of modCount from ... @@ -1858,6 +1890,7 @@ private void replaceAllRange(UnaryOperator operator, int i, int end) { @Override @SuppressWarnings("unchecked") + @DoesNotUnrefineReceiver("modifiability") public void sort(Comparator c) { final int expectedModCount = modCount; Arrays.sort((E[]) elementData, 0, size, c); diff --git a/src/java.base/share/classes/java/util/Collection.java b/src/java.base/share/classes/java/util/Collection.java index 01d2cd4416b1a..d9bd2148d82e2 100644 --- a/src/java.base/share/classes/java/util/Collection.java +++ b/src/java.base/share/classes/java/util/Collection.java @@ -37,6 +37,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; @@ -488,6 +489,7 @@ default T[] toArray(IntFunction generator) { * time due to insertion restrictions */ @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") boolean add(@GuardSatisfied Collection this, E e); /** @@ -510,6 +512,7 @@ default T[] toArray(IntFunction generator) { * @throws UnsupportedOperationException if the {@code remove} operation * is not supported by this collection */ + @DoesNotUnrefineReceiver("modifiability") boolean remove(@GuardSatisfied @CanShrink Collection this, @UnknownSignedness Object o); @@ -562,6 +565,7 @@ default T[] toArray(IntFunction generator) { * this time due to insertion restrictions * @see #add(Object) */ + @DoesNotUnrefineReceiver("modifiability") boolean addAll(@GuardSatisfied Collection this, Collection c); /** @@ -587,6 +591,7 @@ default T[] toArray(IntFunction generator) { * @see #remove(Object) * @see #contains(Object) */ + @DoesNotUnrefineReceiver("modifiability") boolean removeAll(@GuardSatisfied @CanShrink Collection this, Collection c); /** @@ -611,6 +616,7 @@ default T[] toArray(IntFunction generator) { * supported. * @since 1.8 */ + @DoesNotUnrefineReceiver("modifiability") default boolean removeIf(@CanShrink Collection this, Predicate filter) { Objects.requireNonNull(filter); boolean removed = false; @@ -646,6 +652,7 @@ default boolean removeIf(@CanShrink Collection this, Predicate fil * @see #remove(Object) * @see #contains(Object) */ + @DoesNotUnrefineReceiver("modifiability") boolean retainAll(@GuardSatisfied @CanShrink Collection this, Collection c); /** @@ -655,6 +662,7 @@ default boolean removeIf(@CanShrink Collection this, Predicate fil * @throws UnsupportedOperationException if the {@code clear} operation * is not supported by this collection */ + @DoesNotUnrefineReceiver("modifiability") void clear(@GuardSatisfied @CanShrink Collection this); @@ -785,6 +793,7 @@ default Spliterator spliterator() { * @return a sequential {@code Stream} over the elements in this collection * @since 1.8 */ + @DoesNotUnrefineReceiver("modifiability") default @PolyNonEmpty Stream stream(@PolyNonEmpty Collection this) { return StreamSupport.stream(spliterator(), false); } @@ -806,6 +815,7 @@ default Spliterator spliterator() { * collection * @since 1.8 */ + @DoesNotUnrefineReceiver("modifiability") default Stream parallelStream() { return StreamSupport.stream(spliterator(), true); } diff --git a/src/java.base/share/classes/java/util/Collections.java b/src/java.base/share/classes/java/util/Collections.java index f0342432129cf..cd71f55ed133a 100644 --- a/src/java.base/share/classes/java/util/Collections.java +++ b/src/java.base/share/classes/java/util/Collections.java @@ -43,6 +43,7 @@ import org.checkerframework.common.value.qual.ArrayLen; import org.checkerframework.common.value.qual.MinLen; import org.checkerframework.common.value.qual.StaticallyExecutable; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; @@ -1124,10 +1125,12 @@ static class UnmodifiableCollection implements Collection, Serializable { public boolean hasNext() {return i.hasNext();} @SideEffectsOnly("this") public E next(/*@NonEmpty Iterator this*/) {return i.next();} + @DoesNotUnrefineReceiver("modifiability") public void remove() { throw new UnsupportedOperationException(); } @Override + @DoesNotUnrefineReceiver("modifiability") public void forEachRemaining(Consumer action) { // Use backing collection version i.forEachRemaining(action); @@ -1135,10 +1138,12 @@ public void forEachRemaining(Consumer action) { }; } + @DoesNotUnrefineReceiver("modifiability") @EnsuresNonEmpty("this") public boolean add(E e) { throw new UnsupportedOperationException(); } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { throw new UnsupportedOperationException(); } @@ -1147,25 +1152,31 @@ public boolean remove(@UnknownSignedness Object o) { public boolean containsAll(Collection coll) { return c.containsAll(coll); } + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection coll) { throw new UnsupportedOperationException(); } + @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection coll) { throw new UnsupportedOperationException(); } + @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection coll) { throw new UnsupportedOperationException(); } + @DoesNotUnrefineReceiver("modifiability") public void clear() { throw new UnsupportedOperationException(); } // Override default methods in Collection @Override + @DoesNotUnrefineReceiver("modifiability") public void forEach(Consumer action) { c.forEach(action); } @Override + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { throw new UnsupportedOperationException(); } @@ -1177,11 +1188,13 @@ public Spliterator spliterator() { } @SuppressWarnings("unchecked") @Override + @DoesNotUnrefineReceiver("modifiability") public Stream stream() { return (Stream)c.stream(); } @SuppressWarnings("unchecked") @Override + @DoesNotUnrefineReceiver("modifiability") public Stream parallelStream() { return (Stream)c.parallelStream(); } @@ -1239,14 +1252,17 @@ private SequencedCollection sc() { // Even though this wrapper class is serializable, the reversed view is effectively // not serializable because it points to the reversed collection view, which usually isn't // serializable. + @DoesNotUnrefineReceiver("modifiability") public SequencedCollection reversed() { return new UnmodifiableSequencedCollection<>(sc().reversed()); } + @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { throw new UnsupportedOperationException(); } + @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { throw new UnsupportedOperationException(); } @@ -1259,10 +1275,12 @@ public E getLast() { return sc().getLast(); } + @DoesNotUnrefineReceiver("modifiability") public E removeFirst() { throw new UnsupportedOperationException(); } + @DoesNotUnrefineReceiver("modifiability") public E removeLast() { throw new UnsupportedOperationException(); } @@ -1350,6 +1368,7 @@ private SequencedSet ss() { // Even though this wrapper class is serializable, the reversed view is effectively // not serializable because it points to the reversed set view, which usually isn't // serializable. + @DoesNotUnrefineReceiver("modifiability") public SequencedSet reversed() { return new UnmodifiableSequencedSet<>(ss().reversed()); } @@ -1395,12 +1414,15 @@ static class UnmodifiableSortedSet public Comparator comparator() {return ss.comparator();} + @DoesNotUnrefineReceiver("modifiability") public SortedSet subSet(E fromElement, E toElement) { return new UnmodifiableSortedSet<>(ss.subSet(fromElement,toElement)); } + @DoesNotUnrefineReceiver("modifiability") public SortedSet headSet(E toElement) { return new UnmodifiableSortedSet<>(ss.headSet(toElement)); } + @DoesNotUnrefineReceiver("modifiability") public SortedSet tailSet(E fromElement) { return new UnmodifiableSortedSet<>(ss.tailSet(fromElement)); } @@ -1482,23 +1504,30 @@ public EmptyNavigableSet() { public E floor(E e) { return ns.floor(e); } public E ceiling(E e) { return ns.ceiling(e); } public E higher(E e) { return ns.higher(e); } + @DoesNotUnrefineReceiver("modifiability") public E pollFirst() { throw new UnsupportedOperationException(); } + @DoesNotUnrefineReceiver("modifiability") public E pollLast() { throw new UnsupportedOperationException(); } + @DoesNotUnrefineReceiver("modifiability") public NavigableSet descendingSet() { return new UnmodifiableNavigableSet<>(ns.descendingSet()); } + @DoesNotUnrefineReceiver("modifiability") public Iterator descendingIterator() { return descendingSet().iterator(); } + @DoesNotUnrefineReceiver("modifiability") public NavigableSet subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive) { return new UnmodifiableNavigableSet<>( ns.subSet(fromElement, fromInclusive, toElement, toInclusive)); } + @DoesNotUnrefineReceiver("modifiability") public NavigableSet headSet(E toElement, boolean inclusive) { return new UnmodifiableNavigableSet<>( ns.headSet(toElement, inclusive)); } + @DoesNotUnrefineReceiver("modifiability") public NavigableSet tailSet(E fromElement, boolean inclusive) { return new UnmodifiableNavigableSet<>( ns.tailSet(fromElement, inclusive)); @@ -1552,32 +1581,39 @@ static class UnmodifiableList extends UnmodifiableCollection public int hashCode() {return list.hashCode();} public E get(int index) {return list.get(index);} + @DoesNotUnrefineReceiver("modifiability") public E set(int index, E element) { throw new UnsupportedOperationException(); } + @DoesNotUnrefineReceiver("modifiability") public void add(int index, E element) { throw new UnsupportedOperationException(); } + @DoesNotUnrefineReceiver("modifiability") public E remove(int index) { throw new UnsupportedOperationException(); } public int indexOf(Object o) {return list.indexOf(o);} public int lastIndexOf(Object o) {return list.lastIndexOf(o);} + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(int index, Collection c) { throw new UnsupportedOperationException(); } @Override + @DoesNotUnrefineReceiver("modifiability") public void replaceAll(UnaryOperator operator) { throw new UnsupportedOperationException(); } @Override + @DoesNotUnrefineReceiver("modifiability") public void sort(Comparator c) { throw new UnsupportedOperationException(); } public @PolyGrowShrink @PolyNonEmpty ListIterator listIterator(@PolyGrowShrink @PolyNonEmpty UnmodifiableList this) {return listIterator(0);} + @DoesNotUnrefineReceiver("modifiability") public ListIterator listIterator(final int index) { return new ListIterator<>() { private final ListIterator i diff --git a/src/java.base/share/classes/java/util/Deque.java b/src/java.base/share/classes/java/util/Deque.java index 84f03ced15c9f..3873b8414a903 100644 --- a/src/java.base/share/classes/java/util/Deque.java +++ b/src/java.base/share/classes/java/util/Deque.java @@ -45,6 +45,7 @@ import org.checkerframework.checker.nonempty.qual.PolyNonEmpty; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; @@ -237,6 +238,7 @@ public interface Deque extends Queue, SequencedCollection { * element prevents it from being added to this deque */ @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") void addFirst(@GuardSatisfied Deque this, E e); /** @@ -259,6 +261,7 @@ public interface Deque extends Queue, SequencedCollection { * element prevents it from being added to this deque */ @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") void addLast(@GuardSatisfied Deque this, E e); /** @@ -277,6 +280,7 @@ public interface Deque extends Queue, SequencedCollection { * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ + @DoesNotUnrefineReceiver("modifiability") boolean offerFirst(E e); /** @@ -295,6 +299,7 @@ public interface Deque extends Queue, SequencedCollection { * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ + @DoesNotUnrefineReceiver("modifiability") boolean offerLast(E e); /** @@ -305,6 +310,7 @@ public interface Deque extends Queue, SequencedCollection { * @return the head of this deque * @throws NoSuchElementException if this deque is empty */ + @DoesNotUnrefineReceiver("modifiability") E removeFirst(@GuardSatisfied @NonEmpty @CanShrink Deque this); /** @@ -315,6 +321,7 @@ public interface Deque extends Queue, SequencedCollection { * @return the tail of this deque * @throws NoSuchElementException if this deque is empty */ + @DoesNotUnrefineReceiver("modifiability") E removeLast(@GuardSatisfied @NonEmpty @CanShrink Deque this); /** @@ -323,6 +330,7 @@ public interface Deque extends Queue, SequencedCollection { * * @return the head of this deque, or {@code null} if this deque is empty */ + @DoesNotUnrefineReceiver("modifiability") @Nullable E pollFirst(@GuardSatisfied @CanShrink Deque this); /** @@ -331,6 +339,7 @@ public interface Deque extends Queue, SequencedCollection { * * @return the tail of this deque, or {@code null} if this deque is empty */ + @DoesNotUnrefineReceiver("modifiability") @Nullable E pollLast(@GuardSatisfied @CanShrink Deque this); /** @@ -362,6 +371,7 @@ public interface Deque extends Queue, SequencedCollection { * * @return the head of this deque, or {@code null} if this deque is empty */ + @DoesNotUnrefineReceiver("modifiability") @Nullable E peekFirst(); /** @@ -370,6 +380,7 @@ public interface Deque extends Queue, SequencedCollection { * * @return the tail of this deque, or {@code null} if this deque is empty */ + @DoesNotUnrefineReceiver("modifiability") @Nullable E peekLast(); /** @@ -389,6 +400,7 @@ public interface Deque extends Queue, SequencedCollection { * deque does not permit null elements * ({@linkplain Collection##optional-restrictions optional}) */ + @DoesNotUnrefineReceiver("modifiability") boolean removeFirstOccurrence(@GuardSatisfied @CanShrink Deque this, Object o); /** @@ -408,6 +420,7 @@ public interface Deque extends Queue, SequencedCollection { * deque does not permit null elements * ({@linkplain Collection##optional-restrictions optional}) */ + @DoesNotUnrefineReceiver("modifiability") boolean removeLastOccurrence(@GuardSatisfied @CanShrink Deque this, Object o); // *** Queue methods *** @@ -435,6 +448,7 @@ public interface Deque extends Queue, SequencedCollection { * element prevents it from being added to this deque */ @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") boolean add(@GuardSatisfied Deque this, E e); /** @@ -458,6 +472,7 @@ public interface Deque extends Queue, SequencedCollection { * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ + @DoesNotUnrefineReceiver("modifiability") boolean offer(E e); /** @@ -471,6 +486,7 @@ public interface Deque extends Queue, SequencedCollection { * @return the head of the queue represented by this deque * @throws NoSuchElementException if this deque is empty */ + @DoesNotUnrefineReceiver("modifiability") E remove(@GuardSatisfied @NonEmpty @CanShrink Deque this); /** @@ -483,6 +499,7 @@ public interface Deque extends Queue, SequencedCollection { * @return the first element of this deque, or {@code null} if * this deque is empty */ + @DoesNotUnrefineReceiver("modifiability") @Nullable E poll(@GuardSatisfied @CanShrink Deque this); /** @@ -496,6 +513,7 @@ public interface Deque extends Queue, SequencedCollection { * @return the head of the queue represented by this deque * @throws NoSuchElementException if this deque is empty */ + @DoesNotUnrefineReceiver("modifiability") E element(@GuardSatisfied @NonEmpty Deque this); /** @@ -508,6 +526,7 @@ public interface Deque extends Queue, SequencedCollection { * @return the head of the queue represented by this deque, or * {@code null} if this deque is empty */ + @DoesNotUnrefineReceiver("modifiability") @Nullable E peek(); /** @@ -534,6 +553,7 @@ public interface Deque extends Queue, SequencedCollection { * @throws IllegalArgumentException if some property of an element of the * specified collection prevents it from being added to this deque */ + @DoesNotUnrefineReceiver("modifiability") boolean addAll(Collection c); // *** Stack methods *** @@ -556,6 +576,7 @@ public interface Deque extends Queue, SequencedCollection { * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ + @DoesNotUnrefineReceiver("modifiability") void push(@GuardSatisfied Deque this, E e); /** @@ -568,6 +589,7 @@ public interface Deque extends Queue, SequencedCollection { * of the stack represented by this deque) * @throws NoSuchElementException if this deque is empty */ + @DoesNotUnrefineReceiver("modifiability") E pop(@GuardSatisfied @NonEmpty @CanShrink Deque this); @@ -592,6 +614,7 @@ public interface Deque extends Queue, SequencedCollection { * deque does not permit null elements * ({@linkplain Collection##optional-restrictions optional}) */ + @DoesNotUnrefineReceiver("modifiability") boolean remove(@GuardSatisfied @CanShrink Deque this, @UnknownSignedness Object o); /** @@ -637,6 +660,7 @@ public interface Deque extends Queue, SequencedCollection { * @return an iterator over the elements in this deque in reverse * sequence */ + @DoesNotUnrefineReceiver("modifiability") Iterator descendingIterator(); /** @@ -649,6 +673,7 @@ public interface Deque extends Queue, SequencedCollection { * @return a reverse-ordered view of this collection, as a {@code Deque} * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") default Deque reversed() { return ReverseOrderDequeView.of(this); } diff --git a/src/java.base/share/classes/java/util/EnumSet.java b/src/java.base/share/classes/java/util/EnumSet.java index 9a64d87cbe7f9..14c2c2ee396e5 100644 --- a/src/java.base/share/classes/java/util/EnumSet.java +++ b/src/java.base/share/classes/java/util/EnumSet.java @@ -26,6 +26,7 @@ package java.util; import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.framework.qual.AnnotatedFor; import jdk.internal.access.SharedSecrets; @@ -144,6 +145,7 @@ public static > EnumSet allOf(Class elementType) { * Adds all of the elements from the appropriate enum type to this enum * set, which is empty prior to the call. */ + @DoesNotUnrefineReceiver("modifiability") abstract void addAll(); /** @@ -375,6 +377,7 @@ public static > EnumSet range(E from, E to) { * Adds the specified range to this enum set, which is empty prior * to the call. */ + @DoesNotUnrefineReceiver("modifiability") abstract void addRange(E from, E to); /** @@ -383,6 +386,7 @@ public static > EnumSet range(E from, E to) { * @return a copy of this set */ @SuppressWarnings("unchecked") + @DoesNotUnrefineReceiver("modifiability") public EnumSet clone() { try { return (EnumSet) super.clone(); @@ -394,6 +398,7 @@ public EnumSet clone() { /** * Complements the contents of this enum set. */ + @DoesNotUnrefineReceiver("modifiability") abstract void complement(); /** diff --git a/src/java.base/share/classes/java/util/HashMap.java b/src/java.base/share/classes/java/util/HashMap.java index 36f9d1e33bbfa..71646a33cf2d2 100644 --- a/src/java.base/share/classes/java/util/HashMap.java +++ b/src/java.base/share/classes/java/util/HashMap.java @@ -37,6 +37,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; @@ -318,6 +319,7 @@ public final int hashCode() { return Objects.hashCode(key) ^ Objects.hashCode(value); } + @DoesNotUnrefineReceiver("modifiability") public final V setValue(V newValue) { V oldValue = value; value = newValue; @@ -640,6 +642,7 @@ public boolean containsKey(@GuardSatisfied HashMap this, @GuardSatisfied @ * previously associated {@code null} with {@code key}.) */ @EnsuresKeyFor(value={"#1"}, map={"this"}) + @DoesNotUnrefineReceiver("modifiability") public @Nullable V put(@GuardSatisfied HashMap this, K key, V value) { return putVal(hash(key), key, value, false, true); } @@ -814,6 +817,7 @@ else if ((e = tab[index = (n - 1) & hash]) != null) { * @param m mappings to be stored in this map * @throws NullPointerException if the specified map is null */ + @DoesNotUnrefineReceiver("modifiability") public void putAll(@GuardSatisfied HashMap this, Map m) { putMapEntries(m, true); } @@ -827,6 +831,7 @@ public void putAll(@GuardSatisfied HashMap this, Map this, @GuardSatisfied @Nullable @UnknownSignedness Object key) { Node e; return (e = removeNode(hash(key), key, null, false, true)) == null ? @@ -888,6 +893,7 @@ else if (node == p) * Removes all of the mappings from this map. * The map will be empty after this call returns. */ + @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied HashMap this) { Node[] tab; modCount++; @@ -1017,12 +1023,14 @@ T[] valuesToArray(T[] a) { final class KeySet extends AbstractSet { @Pure public final @NonNegative int size() { return size; } + @DoesNotUnrefineReceiver("modifiability") public final void clear() { HashMap.this.clear(); } @SideEffectFree public final Iterator iterator() { return new KeyIterator(); } @Pure @EnsuresNonEmptyIf(result = true, expression = "this") public final boolean contains(@Nullable @UnknownSignedness Object o) { return containsKey(o); } + @DoesNotUnrefineReceiver("modifiability") public final boolean remove(@Nullable @UnknownSignedness Object key) { return removeNode(hash(key), key, null, false, true) != null; } @@ -1039,6 +1047,7 @@ public Object[] toArray() { return keysToArray(prepareArray(a)); } + @DoesNotUnrefineReceiver("modifiability") public final void forEach(Consumer action) { Node[] tab; if (action == null) @@ -1083,6 +1092,7 @@ public Collection values(@GuardSatisfied HashMap this) { final class Values extends AbstractCollection { @Pure public final @NonNegative int size() { return size; } + @DoesNotUnrefineReceiver("modifiability") public final void clear() { HashMap.this.clear(); } @SideEffectFree public final Iterator iterator() { return new ValueIterator(); } @@ -1143,6 +1153,7 @@ public final void forEach(Consumer action) { final class EntrySet extends AbstractSet> { @Pure public final @NonNegative int size() { return size; } + @DoesNotUnrefineReceiver("modifiability") public final void clear() { HashMap.this.clear(); } @SideEffectFree public final Iterator> iterator() { @@ -1157,6 +1168,7 @@ public final boolean contains(@Nullable @UnknownSignedness Object o) { Node candidate = getNode(key); return candidate != null && candidate.equals(e); } + @DoesNotUnrefineReceiver("modifiability") public final boolean remove(@Nullable @UnknownSignedness Object o) { if (o instanceof Map.Entry e) { Object key = e.getKey(); @@ -1169,6 +1181,7 @@ public final boolean remove(@Nullable @UnknownSignedness Object o) { public final Spliterator> spliterator() { return new EntrySpliterator<>(HashMap.this, 0, -1, 0, 0); } + @DoesNotUnrefineReceiver("modifiability") public final void forEach(Consumer> action) { Node[] tab; if (action == null) @@ -1196,16 +1209,19 @@ public V getOrDefault(@GuardSatisfied @Nullable @UnknownSignedness Object key, V @EnsuresKeyFor(value={"#1"}, map={"this"}) @Override + @DoesNotUnrefineReceiver("modifiability") public @Nullable V putIfAbsent(K key, V value) { return putVal(hash(key), key, value, true, true); } @Override + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @Nullable @UnknownSignedness Object key, @GuardSatisfied @Nullable @UnknownSignedness Object value) { return removeNode(hash(key), key, value, true, true) != null; } @Override + @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { Node e; V v; if ((e = getNode(key)) != null && @@ -1218,6 +1234,7 @@ public boolean replace(K key, V oldValue, V newValue) { } @Override + @DoesNotUnrefineReceiver("modifiability") public @Nullable V replace(K key, V value) { Node e; if ((e = getNode(key)) != null) { @@ -1240,6 +1257,7 @@ public boolean replace(K key, V oldValue, V newValue) { * mapping function modified this map */ @Override + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V computeIfAbsent(K key, Function mappingFunction) { if (mappingFunction == null) @@ -1306,6 +1324,7 @@ else if (t != null) * remapping function modified this map */ @Override + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V computeIfPresent(K key, BiFunction remappingFunction) { if (remappingFunction == null) @@ -1340,6 +1359,7 @@ else if (t != null) * remapping function modified this map */ @Override + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V compute(K key, BiFunction remappingFunction) { if (remappingFunction == null) @@ -1405,6 +1425,7 @@ else if (v != null) { * remapping function modified this map */ @Override + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V merge(K key, @NonNull V value, BiFunction remappingFunction) { if (value == null || remappingFunction == null) @@ -1466,6 +1487,7 @@ else if (v != null) { } @Override + @DoesNotUnrefineReceiver("modifiability") public void forEach(BiConsumer action) { Node[] tab; if (action == null) @@ -1482,6 +1504,7 @@ public void forEach(BiConsumer action) { } @Override + @DoesNotUnrefineReceiver("modifiability") public void replaceAll(BiFunction function) { Node[] tab; if (function == null) @@ -1663,6 +1686,7 @@ final Node nextNode(@NonEmpty HashIterator this) { return e; } + @DoesNotUnrefineReceiver("modifiability") public final void remove() { Node p = current; if (p == null) @@ -1677,16 +1701,19 @@ public final void remove() { final class KeyIterator extends HashIterator implements Iterator { + @DoesNotUnrefineReceiver("modifiability") public final K next(@NonEmpty KeyIterator this) { return nextNode().key; } } final class ValueIterator extends HashIterator implements Iterator { + @DoesNotUnrefineReceiver("modifiability") public final V next(@NonEmpty ValueIterator this) { return nextNode().value; } } final class EntryIterator extends HashIterator implements Iterator> { + @DoesNotUnrefineReceiver("modifiability") public final Map.Entry next(@NonEmpty EntryIterator this) { return nextNode(); } } diff --git a/src/java.base/share/classes/java/util/HashSet.java b/src/java.base/share/classes/java/util/HashSet.java index 8cb8c1c1180e1..c87fca402347a 100644 --- a/src/java.base/share/classes/java/util/HashSet.java +++ b/src/java.base/share/classes/java/util/HashSet.java @@ -35,6 +35,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; @@ -394,6 +395,7 @@ private void readObject(java.io.ObjectInputStream s) * @return a {@code Spliterator} over the elements in this set * @since 1.8 */ + @DoesNotUnrefineReceiver("modifiability") public Spliterator spliterator() { return new HashMap.KeySpliterator<>(map, 0, -1, 0, 0); } diff --git a/src/java.base/share/classes/java/util/Hashtable.java b/src/java.base/share/classes/java/util/Hashtable.java index dac8d241449ff..a46dabf6df1b2 100644 --- a/src/java.base/share/classes/java/util/Hashtable.java +++ b/src/java.base/share/classes/java/util/Hashtable.java @@ -37,6 +37,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; @@ -500,6 +501,7 @@ private void addEntry(int hash, K key, V value, int index) { * @see #get(Object) */ @EnsuresKeyFor(value={"#1"}, map={"this"}) + @DoesNotUnrefineReceiver("modifiability") public synchronized @Nullable V put(@GuardSatisfied Hashtable this, K key, V value) { // Make sure the value is not null if (value == null) { @@ -533,6 +535,7 @@ private void addEntry(int hash, K key, V value, int index) { * or {@code null} if the key did not have a mapping * @throws NullPointerException if the key is {@code null} */ + @DoesNotUnrefineReceiver("modifiability") public synchronized @Nullable V remove(@GuardSatisfied Hashtable this, @GuardSatisfied @UnknownSignedness Object key) { Entry tab[] = table; int hash = key.hashCode(); @@ -565,6 +568,7 @@ private void addEntry(int hash, K key, V value, int index) { * @throws NullPointerException if the specified map is null * @since 1.2 */ + @DoesNotUnrefineReceiver("modifiability") public synchronized void putAll(@GuardSatisfied Hashtable this, Map t) { for (Map.Entry e : t.entrySet()) put(e.getKey(), e.getValue()); @@ -573,6 +577,7 @@ public synchronized void putAll(@GuardSatisfied Hashtable this, Map this) { Entry tab[] = table; for (int index = tab.length; --index >= 0; ) @@ -710,9 +715,11 @@ public Iterator iterator() { public boolean contains(@UnknownSignedness Object o) { return containsKey(o); } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { return Hashtable.this.remove(o) != null; } + @DoesNotUnrefineReceiver("modifiability") public void clear() { Hashtable.this.clear(); } @@ -748,6 +755,7 @@ public Iterator> iterator() { } @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") public boolean add(Map.Entry o) { return super.add(o); } @@ -768,6 +776,7 @@ public boolean contains(@UnknownSignedness Object o) { return false; } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { if (!(o instanceof Map.Entry entry)) return false; @@ -799,6 +808,7 @@ public boolean remove(@UnknownSignedness Object o) { return count; } + @DoesNotUnrefineReceiver("modifiability") public void clear() { Hashtable.this.clear(); } @@ -841,6 +851,7 @@ public Iterator iterator() { public boolean contains(@UnknownSignedness Object o) { return containsValue(o); } + @DoesNotUnrefineReceiver("modifiability") public void clear() { Hashtable.this.clear(); } @@ -932,6 +943,7 @@ public synchronized V getOrDefault(@GuardSatisfied @UnknownSignedness Object key @SuppressWarnings("unchecked") @Override + @DoesNotUnrefineReceiver("modifiability") public synchronized void forEach(BiConsumer action) { Objects.requireNonNull(action); // explicit check required in case // table is empty. @@ -952,6 +964,7 @@ public synchronized void forEach(BiConsumer action) { @SuppressWarnings("unchecked") @Override + @DoesNotUnrefineReceiver("modifiability") public synchronized void replaceAll(BiFunction function) { Objects.requireNonNull(function); // explicit check required in case // table is empty. @@ -973,6 +986,7 @@ public synchronized void replaceAll(BiFunction tab[] = table; @@ -1072,6 +1089,7 @@ public synchronized V replace(K key, V value) { * mapping function modified this map */ @Override + @DoesNotUnrefineReceiver("modifiability") public synchronized @PolyNull V computeIfAbsent(K key, Function mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1108,6 +1126,7 @@ public synchronized V replace(K key, V value) { * remapping function modified this map */ @Override + @DoesNotUnrefineReceiver("modifiability") public synchronized @PolyNull V computeIfPresent(K key, BiFunction remappingFunction) { Objects.requireNonNull(remappingFunction); @@ -1150,6 +1169,7 @@ public synchronized V replace(K key, V value) { * remapping function modified this map */ @Override + @DoesNotUnrefineReceiver("modifiability") public synchronized @PolyNull V compute(K key, BiFunction remappingFunction) { Objects.requireNonNull(remappingFunction); @@ -1201,6 +1221,7 @@ public synchronized V replace(K key, V value) { * remapping function modified this map */ @Override + @DoesNotUnrefineReceiver("modifiability") public synchronized @PolyNull V merge(K key, @NonNull V value, BiFunction remappingFunction) { Objects.requireNonNull(remappingFunction); @@ -1445,6 +1466,7 @@ public V getValue() { return value; } + @DoesNotUnrefineReceiver("modifiability") public V setValue(V value) { if (value == null) throw new NullPointerException(); @@ -1555,6 +1577,7 @@ public T next(@NonEmpty Enumerator this) { return nextElement(); } + @DoesNotUnrefineReceiver("modifiability") public void remove() { if (!iterator) throw new UnsupportedOperationException(); diff --git a/src/java.base/share/classes/java/util/IdentityHashMap.java b/src/java.base/share/classes/java/util/IdentityHashMap.java index 6b70ff0619769..c008bcc8bb161 100644 --- a/src/java.base/share/classes/java/util/IdentityHashMap.java +++ b/src/java.base/share/classes/java/util/IdentityHashMap.java @@ -35,6 +35,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; @@ -457,6 +458,7 @@ private boolean containsMapping(@UnknownSignedness @GuardSatisfied @Nullable Obj * @see #containsKey(Object) */ @EnsuresKeyFor(value={"#1"}, map={"this"}) + @DoesNotUnrefineReceiver("modifiability") public @Nullable V put(@GuardSatisfied IdentityHashMap this, K key, V value) { final Object k = maskNull(key); @@ -538,6 +540,7 @@ private boolean resize(int newCapacity) { * @param m mappings to be stored in this map * @throws NullPointerException if the specified map is null */ + @DoesNotUnrefineReceiver("modifiability") public void putAll(@GuardSatisfied IdentityHashMap this, Map m) { int n = m.size(); if (n == 0) @@ -560,6 +563,7 @@ public void putAll(@GuardSatisfied IdentityHashMap this, Map this, @GuardSatisfied @Nullable @UnknownSignedness Object key) { Object k = maskNull(key); Object[] tab = table; @@ -656,6 +660,7 @@ private void closeDeletion(int d) { * Removes all of the mappings from this map. * The map will be empty after this call returns. */ + @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied IdentityHashMap this) { modCount++; Object[] tab = table; @@ -795,6 +800,7 @@ protected int nextIndex(@NonEmpty IdentityHashMapIterator this) { return lastReturnedIndex; } + @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastReturnedIndex == -1) throw new IllegalStateException(); @@ -897,6 +903,7 @@ public Map.Entry next(@NonEmpty EntryIterator this) { return lastReturnedEntry; } + @DoesNotUnrefineReceiver("modifiability") public void remove() { lastReturnedIndex = ((null == lastReturnedEntry) ? -1 : lastReturnedEntry.index); @@ -925,6 +932,7 @@ public V getValue() { } @SuppressWarnings("unchecked") + @DoesNotUnrefineReceiver("modifiability") public V setValue(V value) { checkIndexForEntryUse(); V oldValue = (V) traversalTable[index+1]; @@ -1038,6 +1046,7 @@ public Iterator iterator() { public boolean contains(@Nullable @UnknownSignedness Object o) { return containsKey(o); } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { int oldSize = size; IdentityHashMap.this.remove(o); @@ -1048,6 +1057,7 @@ public boolean remove(@Nullable @UnknownSignedness Object o) { * the former contains an optimization that results in incorrect * behavior when c is a smaller "normal" (non-identity-based) Set. */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { Objects.requireNonNull(c); boolean modified = false; @@ -1059,6 +1069,7 @@ public boolean removeAll(Collection c) { } return modified; } + @DoesNotUnrefineReceiver("modifiability") public void clear() { IdentityHashMap.this.clear(); } @@ -1152,6 +1163,7 @@ public Iterator iterator() { public boolean contains(@Nullable @UnknownSignedness Object o) { return containsValue(o); } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { for (Iterator i = iterator(); i.hasNext(); ) { if (i.next() == o) { @@ -1161,6 +1173,7 @@ public boolean remove(@Nullable @UnknownSignedness Object o) { } return false; } + @DoesNotUnrefineReceiver("modifiability") public void clear() { IdentityHashMap.this.clear(); } @@ -1263,6 +1276,7 @@ public boolean contains(@Nullable @UnknownSignedness Object o) { return o instanceof Entry entry && containsMapping(entry.getKey(), entry.getValue()); } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { return o instanceof Entry entry && removeMapping(entry.getKey(), entry.getValue()); @@ -1271,6 +1285,7 @@ public boolean remove(@Nullable @UnknownSignedness Object o) { public @NonNegative int size() { return size; } + @DoesNotUnrefineReceiver("modifiability") public void clear() { IdentityHashMap.this.clear(); } @@ -1279,6 +1294,7 @@ public void clear() { * the former contains an optimization that results in incorrect * behavior when c is a smaller "normal" (non-identity-based) Set. */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { Objects.requireNonNull(c); boolean modified = false; diff --git a/src/java.base/share/classes/java/util/Iterator.java b/src/java.base/share/classes/java/util/Iterator.java index 192ae2d21d341..37cd9bbda450b 100644 --- a/src/java.base/share/classes/java/util/Iterator.java +++ b/src/java.base/share/classes/java/util/Iterator.java @@ -29,6 +29,7 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf; import org.checkerframework.checker.nonempty.qual.NonEmpty; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; @@ -89,6 +90,7 @@ public interface Iterator { * @throws NoSuchElementException if the iteration has no more elements */ @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") E next(@GuardSatisfied @NonEmpty Iterator this); /** @@ -116,6 +118,7 @@ public interface Iterator { * been called after the last call to the {@code next} * method */ + @DoesNotUnrefineReceiver("modifiability") default void remove(@GuardSatisfied @CanShrink Iterator this) { throw new UnsupportedOperationException("remove"); } @@ -145,6 +148,7 @@ default void remove(@GuardSatisfied @CanShrink Iterator this) { * @throws NullPointerException if the specified action is null * @since 1.8 */ + @DoesNotUnrefineReceiver("modifiability") default void forEachRemaining(Consumer action) { Objects.requireNonNull(action); while (hasNext()) diff --git a/src/java.base/share/classes/java/util/JumboEnumSet.java b/src/java.base/share/classes/java/util/JumboEnumSet.java index 6005a4c5bd0a2..72dc66eb20723 100644 --- a/src/java.base/share/classes/java/util/JumboEnumSet.java +++ b/src/java.base/share/classes/java/util/JumboEnumSet.java @@ -35,6 +35,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; @@ -71,6 +72,7 @@ final class JumboEnumSet> extends EnumSet { elements = new long[(universe.length + 63) >>> 6]; } + @DoesNotUnrefineReceiver("modifiability") void addRange(E from, E to) { int fromIndex = from.ordinal() >>> 6; int toIndex = to.ordinal() >>> 6; @@ -87,6 +89,7 @@ void addRange(E from, E to) { size = to.ordinal() - from.ordinal() + 1; } + @DoesNotUnrefineReceiver("modifiability") void addAll() { for (int i = 0; i < elements.length; i++) elements[i] = -1; @@ -94,6 +97,7 @@ void addAll() { size = universe.length; } + @DoesNotUnrefineReceiver("modifiability") void complement() { for (int i = 0; i < elements.length; i++) elements[i] = ~elements[i]; diff --git a/src/java.base/share/classes/java/util/LinkedHashMap.java b/src/java.base/share/classes/java/util/LinkedHashMap.java index 1c9e2f63b9a89..3175d39c8363a 100644 --- a/src/java.base/share/classes/java/util/LinkedHashMap.java +++ b/src/java.base/share/classes/java/util/LinkedHashMap.java @@ -34,6 +34,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; @@ -404,6 +405,7 @@ void afterNodeAccess(Node e) { * * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") public V putFirst(K k, V v) { try { putMode = PUT_FIRST; @@ -421,6 +423,7 @@ public V putFirst(K k, V v) { * * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") public V putLast(K k, V v) { try { putMode = PUT_LAST; @@ -573,6 +576,7 @@ public V getOrDefault(@Nullable Object key, V defaultValue) { /** * {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied LinkedHashMap this) { super.clear(); head = tail = null; @@ -715,6 +719,7 @@ final class LinkedKeySet extends AbstractSet implements SequencedSet { LinkedKeySet(boolean reversed) { this.reversed = reversed; } @Pure public final int size() { return size; } + @DoesNotUnrefineReceiver("modifiability") public final void clear() { LinkedHashMap.this.clear(); } @SideEffectFree public final Iterator iterator() { @@ -723,6 +728,7 @@ public final Iterator iterator() { @Pure @EnsuresNonEmptyIf(result = true, expression = "this") public final boolean contains(@Nullable @UnknownSignedness Object o) { return containsKey(o); } + @DoesNotUnrefineReceiver("modifiability") public final boolean remove(@Nullable @UnknownSignedness Object key) { return removeNode(hash(key), key, null, false, true) != null; } @@ -741,6 +747,7 @@ public Object[] toArray() { return keysToArray(prepareArray(a), reversed); } + @DoesNotUnrefineReceiver("modifiability") public final void forEach(Consumer action) { if (action == null) throw new NullPointerException(); @@ -759,11 +766,13 @@ public final void forEach(Consumer action) { public final void addLast(K k) { throw new UnsupportedOperationException(); } public final K getFirst() { return nsee(reversed ? tail : head).key; } public final K getLast() { return nsee(reversed ? head : tail).key; } + @DoesNotUnrefineReceiver("modifiability") public final K removeFirst() { var node = nsee(reversed ? tail : head); removeNode(node.hash, node.key, null, false, false); return node.key; } + @DoesNotUnrefineReceiver("modifiability") public final K removeLast() { var node = nsee(reversed ? head : tail); removeNode(node.hash, node.key, null, false, false); @@ -850,6 +859,7 @@ public Object[] toArray() { return valuesToArray(prepareArray(a), reversed); } + @DoesNotUnrefineReceiver("modifiability") public final void forEach(Consumer action) { if (action == null) throw new NullPointerException(); @@ -868,11 +878,13 @@ public final void forEach(Consumer action) { public final void addLast(V v) { throw new UnsupportedOperationException(); } public final V getFirst() { return nsee(reversed ? tail : head).value; } public final V getLast() { return nsee(reversed ? head : tail).value; } + @DoesNotUnrefineReceiver("modifiability") public final V removeFirst() { var node = nsee(reversed ? tail : head); removeNode(node.hash, node.key, null, false, false); return node.value; } + @DoesNotUnrefineReceiver("modifiability") public final V removeLast() { var node = nsee(reversed ? head : tail); removeNode(node.hash, node.key, null, false, false); @@ -954,6 +966,7 @@ public final boolean contains(@Nullable @UnknownSignedness Object o) { Node candidate = getNode(key); return candidate != null && candidate.equals(e); } + @DoesNotUnrefineReceiver("modifiability") public final boolean remove(@Nullable @UnknownSignedness Object o) { if (o instanceof Map.Entry e) { Object key = e.getKey(); @@ -968,6 +981,7 @@ public final Spliterator> spliterator() { Spliterator.ORDERED | Spliterator.DISTINCT); } + @DoesNotUnrefineReceiver("modifiability") public final void forEach(Consumer> action) { if (action == null) throw new NullPointerException(); @@ -992,11 +1006,13 @@ final Node nsee(Node e) { public final void addLast(Map.Entry e) { throw new UnsupportedOperationException(); } public final Map.Entry getFirst() { return nsee(reversed ? tail : head); } public final Map.Entry getLast() { return nsee(reversed ? head : tail); } + @DoesNotUnrefineReceiver("modifiability") public final Map.Entry removeFirst() { var node = nsee(reversed ? tail : head); removeNode(node.hash, node.key, null, false, false); return node; } + @DoesNotUnrefineReceiver("modifiability") public final Map.Entry removeLast() { var node = nsee(reversed ? head : tail); removeNode(node.hash, node.key, null, false, false); @@ -1013,6 +1029,7 @@ public SequencedSet> reversed() { // Map overrides + @DoesNotUnrefineReceiver("modifiability") public void forEach(BiConsumer action) { if (action == null) throw new NullPointerException(); @@ -1023,6 +1040,7 @@ public void forEach(BiConsumer action) { throw new ConcurrentModificationException(); } + @DoesNotUnrefineReceiver("modifiability") public void replaceAll(BiFunction function) { if (function == null) throw new NullPointerException(); @@ -1066,6 +1084,7 @@ final LinkedHashMap.Entry nextNode(@NonEmpty LinkedHashIterator this) { return e; } + @DoesNotUnrefineReceiver("modifiability") public final void remove() { Node p = current; if (p == null) @@ -1173,18 +1192,22 @@ public V get(Object key) { return base.get(key); } + @DoesNotUnrefineReceiver("modifiability") public V put(K key, V value) { return base.put(key, value); } + @DoesNotUnrefineReceiver("modifiability") public V remove(Object key) { return base.remove(key); } + @DoesNotUnrefineReceiver("modifiability") public void putAll(Map m) { base.putAll(m); } + @DoesNotUnrefineReceiver("modifiability") public void clear() { base.clear(); } @@ -1205,6 +1228,7 @@ public V getOrDefault(Object key, V defaultValue) { return base.getOrDefault(key, defaultValue); } + @DoesNotUnrefineReceiver("modifiability") public void forEach(BiConsumer action) { if (action == null) throw new NullPointerException(); @@ -1215,6 +1239,7 @@ public void forEach(BiConsumer action) { throw new ConcurrentModificationException(); } + @DoesNotUnrefineReceiver("modifiability") public void replaceAll(BiFunction function) { if (function == null) throw new NullPointerException(); @@ -1225,34 +1250,42 @@ public void replaceAll(BiFunction function) { throw new ConcurrentModificationException(); } + @DoesNotUnrefineReceiver("modifiability") public V putIfAbsent(K key, V value) { return base.putIfAbsent(key, value); } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(Object key, Object value) { return base.remove(key, value); } + @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { return base.replace(key, oldValue, newValue); } + @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { return base.replace(key, value); } + @DoesNotUnrefineReceiver("modifiability") public V computeIfAbsent(K key, Function mappingFunction) { return base.computeIfAbsent(key, mappingFunction); } + @DoesNotUnrefineReceiver("modifiability") public V computeIfPresent(K key, BiFunction remappingFunction) { return base.computeIfPresent(key, remappingFunction); } + @DoesNotUnrefineReceiver("modifiability") public V compute(K key, BiFunction remappingFunction) { return base.compute(key, remappingFunction); } + @DoesNotUnrefineReceiver("modifiability") public V merge(K key, V value, BiFunction remappingFunction) { return base.merge(key, value, remappingFunction); } @@ -1271,18 +1304,22 @@ public Entry lastEntry() { return base.firstEntry(); } + @DoesNotUnrefineReceiver("modifiability") public Entry pollFirstEntry() { return base.pollLastEntry(); } + @DoesNotUnrefineReceiver("modifiability") public Entry pollLastEntry() { return base.pollFirstEntry(); } + @DoesNotUnrefineReceiver("modifiability") public V putFirst(K k, V v) { return base.putLast(k, v); } + @DoesNotUnrefineReceiver("modifiability") public V putLast(K k, V v) { return base.putFirst(k, v); } diff --git a/src/java.base/share/classes/java/util/LinkedHashSet.java b/src/java.base/share/classes/java/util/LinkedHashSet.java index dc0110b6b67f0..c2e6a9c921681 100644 --- a/src/java.base/share/classes/java/util/LinkedHashSet.java +++ b/src/java.base/share/classes/java/util/LinkedHashSet.java @@ -25,6 +25,9 @@ package java.util; +import org.checkerframework.dataflow.qual.Deterministic; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; @@ -207,6 +210,7 @@ public LinkedHashSet(Collection c) { * @since 1.8 */ @Override + @DoesNotUnrefineReceiver("modifiability") public Spliterator spliterator() { return Spliterators.spliterator(this, Spliterator.DISTINCT | Spliterator.ORDERED); } @@ -231,6 +235,7 @@ public static LinkedHashSet newLinkedHashSet(int numElements) { } @SuppressWarnings("unchecked") + @Deterministic LinkedHashMap map() { return (LinkedHashMap) map; } @@ -243,6 +248,7 @@ LinkedHashMap map() { * * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { map().putFirst(e, PRESENT); } @@ -255,6 +261,7 @@ public void addFirst(E e) { * * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { map().putLast(e, PRESENT); } @@ -265,6 +272,7 @@ public void addLast(E e) { * @throws NoSuchElementException {@inheritDoc} * @since 21 */ + @Pure public E getFirst() { return map().sequencedKeySet().getFirst(); } @@ -275,6 +283,7 @@ public E getFirst() { * @throws NoSuchElementException {@inheritDoc} * @since 21 */ + @Pure public E getLast() { return map().sequencedKeySet().getLast(); } @@ -285,6 +294,7 @@ public E getLast() { * @throws NoSuchElementException {@inheritDoc} * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") public E removeFirst() { return map().sequencedKeySet().removeFirst(); } @@ -295,6 +305,7 @@ public E removeFirst() { * @throws NoSuchElementException {@inheritDoc} * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") public E removeLast() { return map().sequencedKeySet().removeLast(); } @@ -308,6 +319,7 @@ public E removeLast() { * @return {@inheritDoc} * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") public SequencedSet reversed() { class ReverseLinkedHashSetView extends AbstractSet implements SequencedSet { public int size() { return LinkedHashSet.this.size(); } diff --git a/src/java.base/share/classes/java/util/LinkedList.java b/src/java.base/share/classes/java/util/LinkedList.java index b86c45c789d4d..8aa098df3e0e5 100644 --- a/src/java.base/share/classes/java/util/LinkedList.java +++ b/src/java.base/share/classes/java/util/LinkedList.java @@ -39,6 +39,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; @@ -297,6 +298,7 @@ public E getLast(@GuardSatisfied @NonEmpty LinkedList this) { * @return the first element from this list * @throws NoSuchElementException if this list is empty */ + @DoesNotUnrefineReceiver("modifiability") public E removeFirst(@GuardSatisfied @NonEmpty @CanShrink LinkedList this) { final Node f = first; if (f == null) @@ -310,6 +312,7 @@ public E removeFirst(@GuardSatisfied @NonEmpty @CanShrink LinkedList this) { * @return the last element from this list * @throws NoSuchElementException if this list is empty */ + @DoesNotUnrefineReceiver("modifiability") public E removeLast(@GuardSatisfied @NonEmpty @CanShrink LinkedList this) { final Node l = last; if (l == null) @@ -322,6 +325,7 @@ public E removeLast(@GuardSatisfied @NonEmpty @CanShrink LinkedList this) { * * @param e the element to add */ + @DoesNotUnrefineReceiver("modifiability") public void addFirst(@GuardSatisfied LinkedList this, E e) { linkFirst(e); } @@ -333,6 +337,7 @@ public void addFirst(@GuardSatisfied LinkedList this, E e) { * * @param e the element to add */ + @DoesNotUnrefineReceiver("modifiability") public void addLast(@GuardSatisfied LinkedList this, E e) { linkLast(e); } @@ -372,6 +377,7 @@ public boolean contains(@GuardSatisfied LinkedList this, @GuardSatisfied @Nul */ @ReleasesNoLocks @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") public boolean add(@GuardSatisfied LinkedList this, E e) { linkLast(e); return true; @@ -391,6 +397,7 @@ public boolean add(@GuardSatisfied LinkedList this, E e) { * @return {@code true} if this list contained the specified element */ @ReleasesNoLocks + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @CanShrink LinkedList this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { if (o == null) { for (Node x = first; x != null; x = x.next) { @@ -422,6 +429,7 @@ public boolean remove(@GuardSatisfied @CanShrink LinkedList this, @GuardSatis * @return {@code true} if this list changed as a result of the call * @throws NullPointerException if the specified collection is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@GuardSatisfied LinkedList this, Collection c) { return addAll(size, c); } @@ -441,6 +449,7 @@ public boolean addAll(@GuardSatisfied LinkedList this, Collection this, @NonNegative int index, Collection c) { checkPositionIndex(index); @@ -484,6 +493,7 @@ public boolean addAll(@GuardSatisfied LinkedList this, @NonNegative int index * Removes all of the elements from this list. * The list will be empty after this call returns. */ + @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink LinkedList this) { // Clearing all of the links between nodes is "unnecessary", but: // - helps a generational GC if the discarded nodes inhabit @@ -526,6 +536,7 @@ public E get(@GuardSatisfied LinkedList this, @NonNegative int index) { * @return the element previously at the specified position * @throws IndexOutOfBoundsException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public E set(@GuardSatisfied LinkedList this, @NonNegative int index, E element) { checkElementIndex(index); Node x = node(index); @@ -543,6 +554,7 @@ public E set(@GuardSatisfied LinkedList this, @NonNegative int index, E eleme * @param element element to be inserted * @throws IndexOutOfBoundsException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public void add(@GuardSatisfied LinkedList this, @NonNegative int index, E element) { checkPositionIndex(index); @@ -561,6 +573,7 @@ public void add(@GuardSatisfied LinkedList this, @NonNegative int index, E el * @return the element previously at the specified position * @throws IndexOutOfBoundsException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @CanShrink LinkedList this, @NonNegative int index) { checkElementIndex(index); return unlink(node(index)); @@ -712,6 +725,7 @@ public E element(@GuardSatisfied @NonEmpty LinkedList this) { * @return the head of this list, or {@code null} if this list is empty * @since 1.5 */ + @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink LinkedList this) { final Node f = first; return (f == null) ? null : unlinkFirst(f); @@ -724,6 +738,7 @@ public E element(@GuardSatisfied @NonEmpty LinkedList this) { * @throws NoSuchElementException if this list is empty * @since 1.5 */ + @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @NonEmpty @CanShrink LinkedList this) { return removeFirst(); } @@ -735,6 +750,7 @@ public E remove(@GuardSatisfied @NonEmpty @CanShrink LinkedList this) { * @return {@code true} (as specified by {@link Queue#offer}) * @since 1.5 */ + @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { return add(e); } @@ -747,6 +763,7 @@ public boolean offer(E e) { * @return {@code true} (as specified by {@link Deque#offerFirst}) * @since 1.6 */ + @DoesNotUnrefineReceiver("modifiability") public boolean offerFirst(E e) { addFirst(e); return true; @@ -759,6 +776,7 @@ public boolean offerFirst(E e) { * @return {@code true} (as specified by {@link Deque#offerLast}) * @since 1.6 */ + @DoesNotUnrefineReceiver("modifiability") public boolean offerLast(E e) { addLast(e); return true; @@ -800,6 +818,7 @@ public boolean offerLast(E e) { * this list is empty * @since 1.6 */ + @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollFirst(@GuardSatisfied @CanShrink LinkedList this) { final Node f = first; return (f == null) ? null : unlinkFirst(f); @@ -813,6 +832,7 @@ public boolean offerLast(E e) { * this list is empty * @since 1.6 */ + @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollLast(@GuardSatisfied @CanShrink LinkedList this) { final Node l = last; return (l == null) ? null : unlinkLast(l); @@ -827,6 +847,7 @@ public boolean offerLast(E e) { * @param e the element to push * @since 1.6 */ + @DoesNotUnrefineReceiver("modifiability") public void push(@GuardSatisfied LinkedList this, E e) { addFirst(e); } @@ -842,6 +863,7 @@ public void push(@GuardSatisfied LinkedList this, E e) { * @throws NoSuchElementException if this list is empty * @since 1.6 */ + @DoesNotUnrefineReceiver("modifiability") public E pop(@GuardSatisfied @NonEmpty @CanShrink LinkedList this) { return removeFirst(); } @@ -855,6 +877,7 @@ public E pop(@GuardSatisfied @NonEmpty @CanShrink LinkedList this) { * @return {@code true} if the list contained the specified element * @since 1.6 */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeFirstOccurrence(@GuardSatisfied @CanShrink LinkedList this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { return remove(o); } @@ -868,6 +891,7 @@ public boolean removeFirstOccurrence(@GuardSatisfied @CanShrink LinkedList th * @return {@code true} if the list contained the specified element * @since 1.6 */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeLastOccurrence(@GuardSatisfied @CanShrink LinkedList this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { if (o == null) { for (Node x = last; x != null; x = x.prev) { @@ -947,6 +971,7 @@ public boolean hasPrevious() { return nextIndex > 0; } + @DoesNotUnrefineReceiver("modifiability") public E previous() { checkForComodification(); if (!hasPrevious()) @@ -965,6 +990,7 @@ public int previousIndex() { return nextIndex - 1; } + @DoesNotUnrefineReceiver("modifiability") public void remove() { checkForComodification(); if (lastReturned == null) @@ -980,6 +1006,7 @@ public void remove() { expectedModCount++; } + @DoesNotUnrefineReceiver("modifiability") public void set(E e) { if (lastReturned == null) throw new IllegalStateException(); @@ -987,6 +1014,7 @@ public void set(E e) { lastReturned.item = e; } + @DoesNotUnrefineReceiver("modifiability") public void add(E e) { checkForComodification(); lastReturned = null; @@ -1048,6 +1076,7 @@ public boolean hasNext() { public E next(@NonEmpty DescendingIterator this) { return itr.previous(); } + @DoesNotUnrefineReceiver("modifiability") public void remove() { itr.remove(); } @@ -1348,10 +1377,12 @@ public String toString() { return rlist.toString(); } + @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { return rlist.retainAll(c); } + @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { return rlist.removeAll(c); } @@ -1372,6 +1403,7 @@ public Stream stream() { return rlist.stream(); } + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { return rlist.removeIf(filter); } @@ -1404,10 +1436,12 @@ public ListIterator listIterator() { return rlist.listIterator(); } + @DoesNotUnrefineReceiver("modifiability") public void sort(Comparator c) { rlist.sort(c); } + @DoesNotUnrefineReceiver("modifiability") public void replaceAll(UnaryOperator operator) { rlist.replaceAll(operator); } @@ -1436,26 +1470,32 @@ public ListIterator listIterator(int index) { return rlist.listIterator(index); } + @DoesNotUnrefineReceiver("modifiability") public boolean removeLastOccurrence(Object o) { return rdeque.removeLastOccurrence(o); } + @DoesNotUnrefineReceiver("modifiability") public boolean removeFirstOccurrence(Object o) { return rdeque.removeFirstOccurrence(o); } + @DoesNotUnrefineReceiver("modifiability") public E pop() { return rdeque.pop(); } + @DoesNotUnrefineReceiver("modifiability") public void push(E e) { rdeque.push(e); } + @DoesNotUnrefineReceiver("modifiability") public E pollLast() { return rdeque.pollLast(); } + @DoesNotUnrefineReceiver("modifiability") public E pollFirst() { return rdeque.pollFirst(); } @@ -1468,22 +1508,27 @@ public E peekFirst() { return rdeque.peekFirst(); } + @DoesNotUnrefineReceiver("modifiability") public boolean offerLast(E e) { return rdeque.offerLast(e); } + @DoesNotUnrefineReceiver("modifiability") public boolean offerFirst(E e) { return rdeque.offerFirst(e); } + @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { return rdeque.offer(e); } + @DoesNotUnrefineReceiver("modifiability") public E remove() { return rdeque.remove(); } + @DoesNotUnrefineReceiver("modifiability") public E poll() { return rdeque.poll(); } @@ -1504,14 +1549,17 @@ public int indexOf(Object o) { return rlist.indexOf(o); } + @DoesNotUnrefineReceiver("modifiability") public E remove(int index) { return rlist.remove(index); } + @DoesNotUnrefineReceiver("modifiability") public void add(int index, E element) { rlist.add(index, element); } + @DoesNotUnrefineReceiver("modifiability") public E set(int index, E element) { return rlist.set(index, element); } @@ -1520,22 +1568,27 @@ public E get(int index) { return rlist.get(index); } + @DoesNotUnrefineReceiver("modifiability") public void clear() { rlist.clear(); } + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(int index, Collection c) { return rlist.addAll(index, c); } + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { return rlist.addAll(c); } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(Object o) { return rlist.remove(o); } + @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { return rlist.add(e); } @@ -1548,18 +1601,22 @@ public boolean contains(Object o) { return rlist.contains(o); } + @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { rdeque.addLast(e); } + @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { rdeque.addFirst(e); } + @DoesNotUnrefineReceiver("modifiability") public E removeLast() { return rdeque.removeLast(); } + @DoesNotUnrefineReceiver("modifiability") public E removeFirst() { return rdeque.removeFirst(); } diff --git a/src/java.base/share/classes/java/util/List.java b/src/java.base/share/classes/java/util/List.java index 70b9260fab3ef..c5c6bcd21fb5a 100644 --- a/src/java.base/share/classes/java/util/List.java +++ b/src/java.base/share/classes/java/util/List.java @@ -41,6 +41,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; @@ -636,6 +637,7 @@ default void sort(Comparator c) { * @throws IndexOutOfBoundsException if the index is out of range * ({@code index < 0 || index >= size()}) */ + @DoesNotUnrefineReceiver("modifiability") E set(@GuardSatisfied List this, @IndexFor({"this"}) int index, E element); /** diff --git a/src/java.base/share/classes/java/util/ListIterator.java b/src/java.base/share/classes/java/util/ListIterator.java index b44e644f1d3ae..ced399a07a776 100644 --- a/src/java.base/share/classes/java/util/ListIterator.java +++ b/src/java.base/share/classes/java/util/ListIterator.java @@ -30,6 +30,7 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf; import org.checkerframework.checker.nonempty.qual.NonEmpty; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; @@ -97,6 +98,7 @@ public interface ListIterator extends Iterator { * @throws NoSuchElementException if the iteration has no next element */ @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") E next(@GuardSatisfied @NonEmpty ListIterator this); /** @@ -123,6 +125,7 @@ public interface ListIterator extends Iterator { * @throws NoSuchElementException if the iteration has no previous * element */ + @DoesNotUnrefineReceiver("modifiability") E previous(@GuardSatisfied ListIterator this); /** @@ -166,6 +169,7 @@ public interface ListIterator extends Iterator { * {@code add} have been called after the last call to * {@code next} or {@code previous} */ + @DoesNotUnrefineReceiver("modifiability") void remove(@GuardSatisfied ListIterator this); /** @@ -188,6 +192,7 @@ public interface ListIterator extends Iterator { * {@code add} have been called after the last call to * {@code next} or {@code previous} */ + @DoesNotUnrefineReceiver("modifiability") void set(@GuardSatisfied ListIterator this, E e); /** @@ -210,5 +215,6 @@ public interface ListIterator extends Iterator { * @throws IllegalArgumentException if some aspect of this element * prevents it from being added to this list */ + @DoesNotUnrefineReceiver("modifiability") void add(@GuardSatisfied ListIterator this, E e); } diff --git a/src/java.base/share/classes/java/util/Map.java b/src/java.base/share/classes/java/util/Map.java index 64297dd01c7f8..350808ebc3bba 100644 --- a/src/java.base/share/classes/java/util/Map.java +++ b/src/java.base/share/classes/java/util/Map.java @@ -40,6 +40,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; import org.checkerframework.common.aliasing.qual.NonLeaked; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; @@ -302,6 +303,7 @@ public interface Map { @ReleasesNoLocks @EnsuresKeyFor(value={"#1"}, map={"this"}) @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") @Nullable V put(@GuardSatisfied Map this, K key, V value); /** @@ -333,6 +335,7 @@ public interface Map { * map does not permit null keys ({@linkplain Collection##optional-restrictions optional}) */ @CFComment("nullness: key is not @Nullable because this map might not permit null values") + @DoesNotUnrefineReceiver("modifiability") @Nullable V remove(@GuardSatisfied Map this, @GuardSatisfied @UnknownSignedness Object key); @@ -359,6 +362,7 @@ public interface Map { * @throws IllegalArgumentException if some property of a key or value in * the specified map prevents it from being stored in this map */ + @DoesNotUnrefineReceiver("modifiability") void putAll(@GuardSatisfied Map this, Map m); /** @@ -368,6 +372,7 @@ public interface Map { * @throws UnsupportedOperationException if the {@code clear} operation * is not supported by this map */ + @DoesNotUnrefineReceiver("modifiability") void clear(@GuardSatisfied Map this); @@ -532,6 +537,7 @@ interface Entry { * required to, throw this exception if the entry has been * removed from the backing map. */ + @DoesNotUnrefineReceiver("modifiability") V setValue(Map.@GuardSatisfied Entry this, V value); /** @@ -768,6 +774,7 @@ default V getOrDefault(@GuardSatisfied @UnknownSignedness Object key, V defaultV * removed during iteration * @since 1.8 */ + @DoesNotUnrefineReceiver("modifiability") default void forEach(@NonLeaked BiConsumer action) { Objects.requireNonNull(action); for (Map.Entry entry : entrySet()) { @@ -818,6 +825,7 @@ default void forEach(@NonLeaked BiConsumer action) { * removed during iteration * @since 1.8 */ + @DoesNotUnrefineReceiver("modifiability") default void replaceAll(BiFunction function) { Objects.requireNonNull(function); for (Map.Entry entry : entrySet()) { @@ -885,6 +893,7 @@ default void replaceAll(BiFunction function) * @since 1.8 */ @EnsuresKeyFor(value={"#1"}, map={"this"}) + @DoesNotUnrefineReceiver("modifiability") default @Nullable V putIfAbsent(K key, V value) { V v = get(key); if (v == null) { @@ -929,6 +938,7 @@ default void replaceAll(BiFunction function) * @since 1.8 */ @CFComment("nullness: key and value are not @Nullable because this map might not permit null values") + @DoesNotUnrefineReceiver("modifiability") default boolean remove(@GuardSatisfied @UnknownSignedness Object key, @GuardSatisfied @UnknownSignedness Object value) { Object curValue = get(key); if (!Objects.equals(curValue, value) || @@ -979,6 +989,7 @@ default boolean remove(@GuardSatisfied @UnknownSignedness Object key, @GuardSati * or value prevents it from being stored in this map * @since 1.8 */ + @DoesNotUnrefineReceiver("modifiability") default boolean replace(K key, V oldValue, V newValue) { Object curValue = get(key); if (!Objects.equals(curValue, oldValue) || @@ -1027,6 +1038,7 @@ default boolean replace(K key, V oldValue, V newValue) { * or value prevents it from being stored in this map * @since 1.8 */ + @DoesNotUnrefineReceiver("modifiability") default @Nullable V replace(K key, V value) { V curValue; if (((curValue = get(key)) != null) || containsKey(key)) { @@ -1109,6 +1121,7 @@ default boolean replace(K key, V oldValue, V newValue) { * ({@linkplain Collection##optional-restrictions optional}) * @since 1.8 */ + @DoesNotUnrefineReceiver("modifiability") default @PolyNull V computeIfAbsent(K key, Function mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1186,6 +1199,7 @@ default boolean replace(K key, V oldValue, V newValue) { * ({@linkplain Collection##optional-restrictions optional}) * @since 1.8 */ + @DoesNotUnrefineReceiver("modifiability") default @Nullable V computeIfPresent(K key, BiFunction remappingFunction) { Objects.requireNonNull(remappingFunction); @@ -1272,6 +1286,7 @@ default boolean replace(K key, V oldValue, V newValue) { * ({@linkplain Collection##optional-restrictions optional}) * @since 1.8 */ + @DoesNotUnrefineReceiver("modifiability") default @Nullable V compute(K key, BiFunction remappingFunction) { Objects.requireNonNull(remappingFunction); @@ -1370,6 +1385,7 @@ default boolean replace(K key, V oldValue, V newValue) { * null * @since 1.8 */ + @DoesNotUnrefineReceiver("modifiability") default @Nullable V merge(K key, @NonNull V value, BiFunction remappingFunction) { Objects.requireNonNull(remappingFunction); diff --git a/src/java.base/share/classes/java/util/NavigableMap.java b/src/java.base/share/classes/java/util/NavigableMap.java index 6fd455e0255de..8087a679af9fe 100644 --- a/src/java.base/share/classes/java/util/NavigableMap.java +++ b/src/java.base/share/classes/java/util/NavigableMap.java @@ -38,6 +38,7 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nullness.qual.KeyFor; import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; @@ -251,6 +252,7 @@ public interface NavigableMap extends SortedMap { * @return the removed first entry of this map, * or {@code null} if this map is empty */ + @DoesNotUnrefineReceiver("modifiability") Map.@Nullable Entry pollFirstEntry(@GuardSatisfied NavigableMap this); /** @@ -260,6 +262,7 @@ public interface NavigableMap extends SortedMap { * @return the removed last entry of this map, * or {@code null} if this map is empty */ + @DoesNotUnrefineReceiver("modifiability") Map.@Nullable Entry pollLastEntry(@GuardSatisfied NavigableMap this); /** diff --git a/src/java.base/share/classes/java/util/NavigableSet.java b/src/java.base/share/classes/java/util/NavigableSet.java index 3bcdf18792013..71b5d7cf52e44 100644 --- a/src/java.base/share/classes/java/util/NavigableSet.java +++ b/src/java.base/share/classes/java/util/NavigableSet.java @@ -39,6 +39,7 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nonempty.qual.PolyNonEmpty; import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; @@ -160,6 +161,7 @@ public interface NavigableSet extends SortedSet { * * @return the first element, or {@code null} if this set is empty */ + @DoesNotUnrefineReceiver("modifiability") @Nullable E pollFirst(@GuardSatisfied NavigableSet this); /** @@ -168,6 +170,7 @@ public interface NavigableSet extends SortedSet { * * @return the last element, or {@code null} if this set is empty */ + @DoesNotUnrefineReceiver("modifiability") @Nullable E pollLast(@GuardSatisfied NavigableSet this); /** @@ -193,6 +196,7 @@ public interface NavigableSet extends SortedSet { * * @return a reverse order view of this set */ + @DoesNotUnrefineReceiver("modifiability") NavigableSet descendingSet(); /** @@ -201,6 +205,7 @@ public interface NavigableSet extends SortedSet { * * @return an iterator over the elements in this set, in descending order */ + @DoesNotUnrefineReceiver("modifiability") Iterator descendingIterator(); /** @@ -349,6 +354,7 @@ NavigableSet subSet(@GuardSatisfied NavigableSet this, @GuardSatisfied E f * @throws UnsupportedOperationException {@inheritDoc} * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") default E removeFirst() { if (this.isEmpty()) { throw new NoSuchElementException(); @@ -368,6 +374,7 @@ default E removeFirst() { * @throws UnsupportedOperationException {@inheritDoc} * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") default E removeLast() { if (this.isEmpty()) { throw new NoSuchElementException(); @@ -388,6 +395,7 @@ default E removeLast() { * @return a reverse-ordered view of this collection, as a {@code NavigableSet} * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") default NavigableSet reversed() { return this.descendingSet(); } diff --git a/src/java.base/share/classes/java/util/PrimitiveIterator.java b/src/java.base/share/classes/java/util/PrimitiveIterator.java index ed9efa28db275..150564d3774a4 100644 --- a/src/java.base/share/classes/java/util/PrimitiveIterator.java +++ b/src/java.base/share/classes/java/util/PrimitiveIterator.java @@ -26,6 +26,7 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nonempty.qual.NonEmpty; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.framework.qual.AnnotatedFor; import java.util.function.Consumer; @@ -90,6 +91,7 @@ public interface PrimitiveIterator extends Iterator { * @throws NullPointerException if the specified action is null */ @SuppressWarnings("overloads") + @DoesNotUnrefineReceiver("modifiability") void forEachRemaining(T_CONS action); /** @@ -105,6 +107,7 @@ public static interface OfInt extends PrimitiveIterator { * @return the next {@code int} element in the iteration * @throws NoSuchElementException if the iteration has no more elements */ + @DoesNotUnrefineReceiver("modifiability") int nextInt(@NonEmpty OfInt this); /** @@ -116,6 +119,7 @@ public static interface OfInt extends PrimitiveIterator { * action.accept(nextInt()); * } */ + @DoesNotUnrefineReceiver("modifiability") default void forEachRemaining(IntConsumer action) { Objects.requireNonNull(action); while (hasNext()) @@ -129,6 +133,7 @@ default void forEachRemaining(IntConsumer action) { * {@link #nextInt()}, and returns that boxed result. */ @Override + @DoesNotUnrefineReceiver("modifiability") default Integer next(PrimitiveIterator.@GuardSatisfied OfInt this) { if (Tripwire.ENABLED) Tripwire.trip(getClass(), "{0} calling PrimitiveIterator.OfInt.nextInt()"); @@ -145,6 +150,7 @@ default Integer next(PrimitiveIterator.@GuardSatisfied OfInt this) { * and then passed to {@link #forEachRemaining}. */ @Override + @DoesNotUnrefineReceiver("modifiability") default void forEachRemaining(Consumer action) { if (action instanceof IntConsumer) { forEachRemaining((IntConsumer) action); @@ -173,6 +179,7 @@ public static interface OfLong extends PrimitiveIterator { * @return the next {@code long} element in the iteration * @throws NoSuchElementException if the iteration has no more elements */ + @DoesNotUnrefineReceiver("modifiability") long nextLong(@NonEmpty OfLong this); /** @@ -184,6 +191,7 @@ public static interface OfLong extends PrimitiveIterator { * action.accept(nextLong()); * } */ + @DoesNotUnrefineReceiver("modifiability") default void forEachRemaining(LongConsumer action) { Objects.requireNonNull(action); while (hasNext()) @@ -197,6 +205,7 @@ default void forEachRemaining(LongConsumer action) { * {@link #nextLong()}, and returns that boxed result. */ @Override + @DoesNotUnrefineReceiver("modifiability") default Long next(PrimitiveIterator.@GuardSatisfied OfLong this) { if (Tripwire.ENABLED) Tripwire.trip(getClass(), "{0} calling PrimitiveIterator.OfLong.nextLong()"); @@ -213,6 +222,7 @@ default Long next(PrimitiveIterator.@GuardSatisfied OfLong this) { * and then passed to {@link #forEachRemaining}. */ @Override + @DoesNotUnrefineReceiver("modifiability") default void forEachRemaining(Consumer action) { if (action instanceof LongConsumer) { forEachRemaining((LongConsumer) action); @@ -240,6 +250,7 @@ public static interface OfDouble extends PrimitiveIterator */ + @DoesNotUnrefineReceiver("modifiability") default void forEachRemaining(DoubleConsumer action) { Objects.requireNonNull(action); while (hasNext()) @@ -264,6 +276,7 @@ default void forEachRemaining(DoubleConsumer action) { * {@link #nextDouble()}, and returns that boxed result. */ @Override + @DoesNotUnrefineReceiver("modifiability") default Double next(PrimitiveIterator.@GuardSatisfied OfDouble this) { if (Tripwire.ENABLED) Tripwire.trip(getClass(), "{0} calling PrimitiveIterator.OfDouble.nextLong()"); @@ -281,6 +294,7 @@ default Double next(PrimitiveIterator.@GuardSatisfied OfDouble this) { * {@link #forEachRemaining}. */ @Override + @DoesNotUnrefineReceiver("modifiability") default void forEachRemaining(Consumer action) { if (action instanceof DoubleConsumer) { forEachRemaining((DoubleConsumer) action); diff --git a/src/java.base/share/classes/java/util/Properties.java b/src/java.base/share/classes/java/util/Properties.java index a25c6f4be6f8f..fe980b59d49b4 100644 --- a/src/java.base/share/classes/java/util/Properties.java +++ b/src/java.base/share/classes/java/util/Properties.java @@ -32,6 +32,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.propkey.qual.PropertyKey; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; @@ -238,6 +239,7 @@ private Properties(Properties defaults, int initialCapacity) { * @see #getProperty * @since 1.2 */ + @DoesNotUnrefineReceiver("modifiability") public synchronized @Nullable Object setProperty(@GuardSatisfied Properties this, @PropertyKey String key, String value) { return put(key, value); } @@ -1363,21 +1365,25 @@ public boolean containsKey(@GuardSatisfied @Nullable @UnknownSignedness Object k } @Override + @DoesNotUnrefineReceiver("modifiability") public synchronized Object put(Object key, Object value) { return map.put(key, value); } @Override + @DoesNotUnrefineReceiver("modifiability") public synchronized Object remove(@GuardSatisfied @Nullable @UnknownSignedness Object key) { return map.remove(key); } @Override + @DoesNotUnrefineReceiver("modifiability") public synchronized void putAll(Map t) { map.putAll(t); } @Override + @DoesNotUnrefineReceiver("modifiability") public synchronized void clear() { map.clear(); } @@ -1424,7 +1430,9 @@ private EntrySet(Set> entrySet) { @Override public boolean contains(@UnknownSignedness Object o) { return entrySet.contains(o); } @Override public Object[] toArray() { return entrySet.toArray(); } @Override public @Nullable T[] toArray(@PolyNull T[] a) { return entrySet.toArray(a); } + @DoesNotUnrefineReceiver("modifiability") @Override public void clear() { entrySet.clear(); } + @DoesNotUnrefineReceiver("modifiability") @Override public boolean remove(@UnknownSignedness Object o) { return entrySet.remove(o); } @Override @@ -1459,11 +1467,13 @@ public String toString() { } @Override + @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { return entrySet.removeAll(c); } @Override + @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { return entrySet.retainAll(c); } @@ -1491,54 +1501,64 @@ public Object getOrDefault(@GuardSatisfied @Nullable @UnknownSignedness Object k } @Override + @DoesNotUnrefineReceiver("modifiability") public synchronized void forEach(BiConsumer action) { map.forEach(action); } @Override + @DoesNotUnrefineReceiver("modifiability") public synchronized void replaceAll(BiFunction function) { map.replaceAll(function); } @Override + @DoesNotUnrefineReceiver("modifiability") public synchronized Object putIfAbsent(Object key, Object value) { return map.putIfAbsent(key, value); } @Override + @DoesNotUnrefineReceiver("modifiability") public synchronized boolean remove(@GuardSatisfied @Nullable @UnknownSignedness Object key, @GuardSatisfied @Nullable @UnknownSignedness Object value) { return map.remove(key, value); } @Override + @DoesNotUnrefineReceiver("modifiability") public synchronized boolean replace(Object key, Object oldValue, Object newValue) { return map.replace(key, oldValue, newValue); } @Override + @DoesNotUnrefineReceiver("modifiability") public synchronized Object replace(Object key, Object value) { return map.replace(key, value); } @Override + @DoesNotUnrefineReceiver("modifiability") public synchronized @PolyNull Object computeIfAbsent(Object key, Function mappingFunction) { return map.computeIfAbsent(key, mappingFunction); } @Override + @DoesNotUnrefineReceiver("modifiability") public synchronized @PolyNull Object computeIfPresent(Object key, BiFunction remappingFunction) { return map.computeIfPresent(key, remappingFunction); } @Override + @DoesNotUnrefineReceiver("modifiability") public synchronized @PolyNull Object compute(Object key, BiFunction remappingFunction) { return map.compute(key, remappingFunction); } @Override + @DoesNotUnrefineReceiver("modifiability") public synchronized @Nullable Object merge(Object key, Object value, BiFunction remappingFunction) { return map.merge(key, value, remappingFunction); diff --git a/src/java.base/share/classes/java/util/Queue.java b/src/java.base/share/classes/java/util/Queue.java index 056c44880016d..e04f0c2118afa 100644 --- a/src/java.base/share/classes/java/util/Queue.java +++ b/src/java.base/share/classes/java/util/Queue.java @@ -41,6 +41,7 @@ import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf; import org.checkerframework.checker.nonempty.qual.NonEmpty; import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; @@ -166,6 +167,7 @@ public interface Queue extends Collection { * prevents it from being added to this queue */ @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") boolean add(@GuardSatisfied Queue this, E e); /** @@ -185,6 +187,7 @@ public interface Queue extends Collection { * @throws IllegalArgumentException if some property of this element * prevents it from being added to this queue */ + @DoesNotUnrefineReceiver("modifiability") boolean offer(E e); /** @@ -195,6 +198,7 @@ public interface Queue extends Collection { * @return the head of this queue * @throws NoSuchElementException if this queue is empty */ + @DoesNotUnrefineReceiver("modifiability") E remove(@GuardSatisfied @NonEmpty @CanShrink Queue this); /** @@ -203,6 +207,7 @@ public interface Queue extends Collection { * * @return the head of this queue, or {@code null} if this queue is empty */ + @DoesNotUnrefineReceiver("modifiability") @Nullable E poll(@GuardSatisfied @CanShrink Queue this); /** @@ -221,5 +226,6 @@ public interface Queue extends Collection { * * @return the head of this queue, or {@code null} if this queue is empty */ + @DoesNotUnrefineReceiver("modifiability") @Nullable E peek(); } diff --git a/src/java.base/share/classes/java/util/RegularEnumSet.java b/src/java.base/share/classes/java/util/RegularEnumSet.java index a898d1090df28..9b5a5e2dddaf4 100644 --- a/src/java.base/share/classes/java/util/RegularEnumSet.java +++ b/src/java.base/share/classes/java/util/RegularEnumSet.java @@ -36,6 +36,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; @@ -63,15 +64,18 @@ final class RegularEnumSet> extends EnumSet { super(elementType, universe); } + @DoesNotUnrefineReceiver("modifiability") void addRange(E from, E to) { elements = (-1L >>> (from.ordinal() - to.ordinal() - 1)) << from.ordinal(); } + @DoesNotUnrefineReceiver("modifiability") void addAll() { if (universe.length != 0) elements = -1L >>> -universe.length; } + @DoesNotUnrefineReceiver("modifiability") void complement() { if (universe.length != 0) { elements = ~elements; @@ -89,6 +93,7 @@ void complement() { * * @return an iterator over the elements contained in this set */ + @DoesNotUnrefineReceiver("modifiability") public @PolyGrowShrink @PolyNonEmpty Iterator iterator(@PolyGrowShrink @PolyNonEmpty RegularEnumSet this) { return new EnumSetIterator<>(); } @@ -126,6 +131,7 @@ public E next(@NonEmpty EnumSetIterator this) { return (E) universe[Long.numberOfTrailingZeros(lastReturned)]; } + @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastReturned == 0) throw new IllegalStateException(); @@ -184,6 +190,7 @@ public boolean contains(@GuardSatisfied @Nullable @UnknownSignedness Object e) { * @throws NullPointerException if {@code e} is null */ @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { typeCheck(e); @@ -198,6 +205,7 @@ public boolean add(E e) { * @param e element to be removed from this set, if present * @return {@code true} if the set contained the specified element */ + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @Nullable @UnknownSignedness Object e) { if (e == null) return false; @@ -240,6 +248,7 @@ public boolean containsAll(Collection c) { * @throws NullPointerException if the specified collection or any * of its elements are null */ + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { if (!(c instanceof RegularEnumSet es)) return super.addAll(c); @@ -265,6 +274,7 @@ public boolean addAll(Collection c) { * @return {@code true} if this set changed as a result of the call * @throws NullPointerException if the specified collection is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { if (!(c instanceof RegularEnumSet es)) return super.removeAll(c); @@ -285,6 +295,7 @@ public boolean removeAll(Collection c) { * @return {@code true} if this set changed as a result of the call * @throws NullPointerException if the specified collection is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { if (!(c instanceof RegularEnumSet es)) return super.retainAll(c); @@ -303,6 +314,7 @@ public boolean retainAll(Collection c) { /** * Removes all of the elements from this set. */ + @DoesNotUnrefineReceiver("modifiability") public void clear() { elements = 0; } diff --git a/src/java.base/share/classes/java/util/SequencedCollection.java b/src/java.base/share/classes/java/util/SequencedCollection.java index 54237c7a3f775..40e77acb7b385 100644 --- a/src/java.base/share/classes/java/util/SequencedCollection.java +++ b/src/java.base/share/classes/java/util/SequencedCollection.java @@ -25,6 +25,8 @@ package java.util; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; + /** * A collection that has a well-defined encounter order, that supports operations at both ends, * and that is reversible. The elements of a sequenced collection have an @@ -87,6 +89,7 @@ public interface SequencedCollection extends Collection { * * @return a reverse-ordered view of this collection */ + @DoesNotUnrefineReceiver("modifiability") SequencedCollection reversed(); /** @@ -103,6 +106,7 @@ public interface SequencedCollection extends Collection { * @throws UnsupportedOperationException if this collection implementation * does not support this operation */ + @DoesNotUnrefineReceiver("modifiability") default void addFirst(E e) { throw new UnsupportedOperationException(); } @@ -121,6 +125,7 @@ default void addFirst(E e) { * @throws UnsupportedOperationException if this collection implementation * does not support this operation */ + @DoesNotUnrefineReceiver("modifiability") default void addLast(E e) { throw new UnsupportedOperationException(); } @@ -172,6 +177,7 @@ default E getLast() { * @throws UnsupportedOperationException if this collection implementation * does not support this operation */ + @DoesNotUnrefineReceiver("modifiability") default E removeFirst() { var it = this.iterator(); E e = it.next(); @@ -194,6 +200,7 @@ default E removeFirst() { * @throws UnsupportedOperationException if this collection implementation * does not support this operation */ + @DoesNotUnrefineReceiver("modifiability") default E removeLast() { var it = this.reversed().iterator(); E e = it.next(); diff --git a/src/java.base/share/classes/java/util/SequencedMap.java b/src/java.base/share/classes/java/util/SequencedMap.java index 6bff204b65dc9..d7bf9703ad57f 100644 --- a/src/java.base/share/classes/java/util/SequencedMap.java +++ b/src/java.base/share/classes/java/util/SequencedMap.java @@ -25,6 +25,8 @@ package java.util; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; + import jdk.internal.util.NullableKeyValueHolder; /** @@ -134,6 +136,7 @@ public interface SequencedMap extends Map { * * @return a reverse-ordered view of this map */ + @DoesNotUnrefineReceiver("modifiability") SequencedMap reversed(); /** @@ -184,6 +187,7 @@ default Map.Entry lastEntry() { * @throws UnsupportedOperationException if this collection implementation does not * support this operation */ + @DoesNotUnrefineReceiver("modifiability") default Map.Entry pollFirstEntry() { var it = entrySet().iterator(); if (it.hasNext()) { @@ -209,6 +213,7 @@ default Map.Entry pollFirstEntry() { * @throws UnsupportedOperationException if this collection implementation does not * support this operation */ + @DoesNotUnrefineReceiver("modifiability") default Map.Entry pollLastEntry() { var it = reversed().entrySet().iterator(); if (it.hasNext()) { @@ -235,6 +240,7 @@ default Map.Entry pollLastEntry() { * @throws UnsupportedOperationException if this collection implementation does not * support this operation */ + @DoesNotUnrefineReceiver("modifiability") default V putFirst(K k, V v) { throw new UnsupportedOperationException(); } @@ -254,6 +260,7 @@ default V putFirst(K k, V v) { * @throws UnsupportedOperationException if this collection implementation does not * support this operation */ + @DoesNotUnrefineReceiver("modifiability") default V putLast(K k, V v) { throw new UnsupportedOperationException(); } @@ -272,6 +279,7 @@ default V putLast(K k, V v) { * * @return a {@code SequencedSet} view of this map's {@code keySet} */ + @DoesNotUnrefineReceiver("modifiability") default SequencedSet sequencedKeySet() { class SeqKeySet extends AbstractMap.ViewCollection implements SequencedSet { Collection view() { @@ -305,6 +313,7 @@ public int hashCode() { * * @return a {@code SequencedCollection} view of this map's {@code values} collection */ + @DoesNotUnrefineReceiver("modifiability") default SequencedCollection sequencedValues() { class SeqValues extends AbstractMap.ViewCollection implements SequencedCollection { Collection view() { @@ -331,6 +340,7 @@ public SequencedCollection reversed() { * * @return a {@code SequencedSet} view of this map's {@code entrySet} */ + @DoesNotUnrefineReceiver("modifiability") default SequencedSet> sequencedEntrySet() { class SeqEntrySet extends AbstractMap.ViewCollection> implements SequencedSet> { diff --git a/src/java.base/share/classes/java/util/SequencedSet.java b/src/java.base/share/classes/java/util/SequencedSet.java index c02bfc123ff8f..d4bac4cd6747d 100644 --- a/src/java.base/share/classes/java/util/SequencedSet.java +++ b/src/java.base/share/classes/java/util/SequencedSet.java @@ -25,6 +25,8 @@ package java.util; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; + /** * A collection that is both a {@link SequencedCollection} and a {@link Set}. As such, * it can be thought of either as a {@code Set} that also has a well-defined @@ -54,5 +56,6 @@ public interface SequencedSet extends SequencedCollection, Set { * * @return a reverse-ordered view of this collection, as a {@code SequencedSet} */ + @DoesNotUnrefineReceiver("modifiability") SequencedSet reversed(); } diff --git a/src/java.base/share/classes/java/util/Set.java b/src/java.base/share/classes/java/util/Set.java index 914bfe89d5d7e..713a75e0a7a5b 100644 --- a/src/java.base/share/classes/java/util/Set.java +++ b/src/java.base/share/classes/java/util/Set.java @@ -36,6 +36,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; diff --git a/src/java.base/share/classes/java/util/SortedMap.java b/src/java.base/share/classes/java/util/SortedMap.java index 38dd78b2920c2..244e864a1bcd7 100644 --- a/src/java.base/share/classes/java/util/SortedMap.java +++ b/src/java.base/share/classes/java/util/SortedMap.java @@ -29,6 +29,7 @@ import org.checkerframework.checker.nonempty.qual.NonEmpty; import org.checkerframework.checker.nullness.qual.KeyFor; import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; @@ -313,6 +314,7 @@ public interface SortedMap extends SequencedMap { * @throws UnsupportedOperationException always * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") default V putFirst(K k, V v) { throw new UnsupportedOperationException(); } @@ -328,6 +330,7 @@ default V putFirst(K k, V v) { * @throws UnsupportedOperationException always * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") default V putLast(K k, V v) { throw new UnsupportedOperationException(); } @@ -342,6 +345,7 @@ default V putLast(K k, V v) { * @return a reverse-ordered view of this map, as a {@code SortedMap} * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") default SortedMap reversed() { return ReverseOrderSortedMapView.of(this); } diff --git a/src/java.base/share/classes/java/util/SortedSet.java b/src/java.base/share/classes/java/util/SortedSet.java index 31b1820d4b85a..071cfa146d1c1 100644 --- a/src/java.base/share/classes/java/util/SortedSet.java +++ b/src/java.base/share/classes/java/util/SortedSet.java @@ -28,6 +28,7 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nonempty.qual.NonEmpty; import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; @@ -268,6 +269,7 @@ public interface SortedSet extends Set, SequencedSet { * @since 1.8 */ @Override + @DoesNotUnrefineReceiver("modifiability") default Spliterator spliterator() { return new Spliterators.IteratorSpliterator( this, Spliterator.DISTINCT | Spliterator.SORTED | Spliterator.ORDERED) { @@ -291,6 +293,7 @@ public Comparator getComparator() { * @throws UnsupportedOperationException always * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") default void addFirst(E e) { throw new UnsupportedOperationException(); } @@ -306,6 +309,7 @@ default void addFirst(E e) { * @throws UnsupportedOperationException always * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") default void addLast(E e) { throw new UnsupportedOperationException(); } @@ -348,6 +352,7 @@ default E getLast() { * @throws UnsupportedOperationException {@inheritDoc} * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") default E removeFirst() { E e = this.first(); this.remove(e); @@ -366,6 +371,7 @@ default E removeFirst() { * @throws UnsupportedOperationException {@inheritDoc} * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") default E removeLast() { E e = this.last(); this.remove(e); @@ -382,6 +388,7 @@ default E removeLast() { * @return a reverse-ordered view of this collection, as a {@code SortedSet} * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") default SortedSet reversed() { return ReverseOrderSortedSetView.of(this); } diff --git a/src/java.base/share/classes/java/util/Stack.java b/src/java.base/share/classes/java/util/Stack.java index 4a960c5b90dbb..51008d83a3417 100644 --- a/src/java.base/share/classes/java/util/Stack.java +++ b/src/java.base/share/classes/java/util/Stack.java @@ -29,6 +29,7 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf; import org.checkerframework.checker.nonempty.qual.NonEmpty; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; @@ -75,6 +76,7 @@ public Stack() { * @return the {@code item} argument. * @see java.util.Vector#addElement */ + @DoesNotUnrefineReceiver("modifiability") public E push(@GuardSatisfied Stack this, E item) { addElement(item); @@ -89,6 +91,7 @@ public E push(@GuardSatisfied Stack this, E item) { * of the {@code Vector} object). * @throws EmptyStackException if this stack is empty. */ + @DoesNotUnrefineReceiver("modifiability") public synchronized E pop(@GuardSatisfied @NonEmpty @CanShrink Stack this) { E obj; int len = size(); diff --git a/src/java.base/share/classes/java/util/TreeMap.java b/src/java.base/share/classes/java/util/TreeMap.java index eeb4c76767273..c0229972f73b0 100644 --- a/src/java.base/share/classes/java/util/TreeMap.java +++ b/src/java.base/share/classes/java/util/TreeMap.java @@ -36,6 +36,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; @@ -309,6 +310,7 @@ public boolean containsValue(@GuardSatisfied TreeMap this, @GuardSatisfied * and this map uses natural ordering, or its comparator * does not permit null keys */ + @DoesNotUnrefineReceiver("modifiability") public @Nullable V get(@GuardSatisfied TreeMap this, @UnknownSignedness @GuardSatisfied Object key) { Entry p = getEntry(key); return (p==null ? null : p.value); @@ -341,6 +343,7 @@ public boolean containsValue(@GuardSatisfied TreeMap this, @GuardSatisfied * @throws UnsupportedOperationException always * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") public V putFirst(K k, V v) { throw new UnsupportedOperationException(); } @@ -353,6 +356,7 @@ public V putFirst(K k, V v) { * @throws UnsupportedOperationException always * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") public V putLast(K k, V v) { throw new UnsupportedOperationException(); } @@ -369,6 +373,7 @@ public V putLast(K k, V v) { * the specified map contains a null key and this map does not * permit null keys */ + @DoesNotUnrefineReceiver("modifiability") public void putAll(@GuardSatisfied TreeMap this, Map map) { int mapSize = map.size(); if (size==0 && mapSize!=0 && map instanceof SortedMap) { @@ -590,11 +595,13 @@ final Entry getLowerEntry(K key) { * does not permit null keys */ @EnsuresKeyFor(value={"#1"}, map={"this"}) + @DoesNotUnrefineReceiver("modifiability") public @Nullable V put(@GuardSatisfied TreeMap this, K key, V value) { return put(key, value, true); } @Override + @DoesNotUnrefineReceiver("modifiability") public V putIfAbsent(K key, V value) { return put(key, value, false); } @@ -610,6 +617,7 @@ public V putIfAbsent(K key, V value) { * mapping function modified this map */ @Override + @DoesNotUnrefineReceiver("modifiability") public V computeIfAbsent(K key, Function mappingFunction) { Objects.requireNonNull(mappingFunction); V newValue; @@ -680,6 +688,7 @@ else if (cmp > 0) * remapping function modified this map */ @Override + @DoesNotUnrefineReceiver("modifiability") public V computeIfPresent(K key, BiFunction remappingFunction) { Objects.requireNonNull(remappingFunction); Entry oldEntry = getEntry(key); @@ -701,6 +710,7 @@ public V computeIfPresent(K key, BiFunction r * remapping function modified this map */ @Override + @DoesNotUnrefineReceiver("modifiability") public V compute(K key, BiFunction remappingFunction) { Objects.requireNonNull(remappingFunction); V newValue; @@ -763,6 +773,7 @@ else if (cmp > 0) * remapping function modified this map */ @Override + @DoesNotUnrefineReceiver("modifiability") public V merge(K key, V value, BiFunction remappingFunction) { Objects.requireNonNull(remappingFunction); Objects.requireNonNull(value); @@ -937,6 +948,7 @@ private V mergeValue(Entry t, V value, BiFunction this, @GuardSatisfied @UnknownSignedness Object key) { Entry p = getEntry(key); if (p == null) @@ -951,6 +963,7 @@ private V mergeValue(Entry t, V value, BiFunction this) { modCount++; size = 0; @@ -963,6 +976,7 @@ public void clear(@GuardSatisfied TreeMap this) { * * @return a shallow copy of this map */ + @DoesNotUnrefineReceiver("modifiability") public Object clone(@GuardSatisfied TreeMap this) { TreeMap clone; try { @@ -1007,6 +1021,7 @@ public Object clone(@GuardSatisfied TreeMap this) { /** * @since 1.6 */ + @DoesNotUnrefineReceiver("modifiability") public Map.@Nullable Entry pollFirstEntry(@GuardSatisfied TreeMap this) { Entry p = getFirstEntry(); Map.Entry result = exportEntry(p); @@ -1018,6 +1033,7 @@ public Object clone(@GuardSatisfied TreeMap this) { /** * @since 1.6 */ + @DoesNotUnrefineReceiver("modifiability") public Map.@Nullable Entry pollLastEntry(@GuardSatisfied TreeMap this) { Entry p = getLastEntry(); Map.Entry result = exportEntry(p); @@ -1150,6 +1166,7 @@ public Object clone(@GuardSatisfied TreeMap this) { * operations. It does not support the {@code add} or {@code addAll} * operations. */ + @DoesNotUnrefineReceiver("modifiability") public Set<@KeyFor({"this"}) K> keySet(@GuardSatisfied TreeMap this) { return navigableKeySet(); } diff --git a/src/java.base/share/classes/java/util/TreeSet.java b/src/java.base/share/classes/java/util/TreeSet.java index b4770fab88f6a..37386cac38e44 100644 --- a/src/java.base/share/classes/java/util/TreeSet.java +++ b/src/java.base/share/classes/java/util/TreeSet.java @@ -35,6 +35,7 @@ import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; @@ -209,6 +210,7 @@ public TreeSet(@Nullable Comparator comparator) { * @return an iterator over the elements in this set in descending order * @since 1.6 */ + @DoesNotUnrefineReceiver("modifiability") public @PolyGrowShrink @PolyNonEmpty Iterator descendingIterator(@PolyGrowShrink @PolyNonEmpty TreeSet this) { return m.descendingKeySet().iterator(); } @@ -216,6 +218,7 @@ public TreeSet(@Nullable Comparator comparator) { /** * @since 1.6 */ + @DoesNotUnrefineReceiver("modifiability") public NavigableSet descendingSet() { return new TreeSet<>(m.descendingMap()); } @@ -280,6 +283,7 @@ public boolean contains(@GuardSatisfied TreeSet this, @GuardSatisfied @Unknow * does not permit null elements */ @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") public boolean add(@GuardSatisfied TreeSet this, E e) { return m.put(e, PRESENT)==null; } @@ -301,6 +305,7 @@ public boolean add(@GuardSatisfied TreeSet this, E e) { * and this set uses natural ordering, or its comparator * does not permit null elements */ + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied TreeSet this, @GuardSatisfied @UnknownSignedness Object o) { return m.remove(o)==PRESENT; } @@ -309,6 +314,7 @@ public boolean remove(@GuardSatisfied TreeSet this, @GuardSatisfied @UnknownS * Removes all of the elements from this set. * The set will be empty after this call returns. */ + @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied TreeSet this) { m.clear(); } @@ -324,6 +330,7 @@ public void clear(@GuardSatisfied TreeSet this) { * if any element is null and this set uses natural ordering, or * its comparator does not permit null elements */ + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@GuardSatisfied TreeSet this, Collection c) { // Use linear-time version if applicable if (m.size()==0 && c.size() > 0 && @@ -485,6 +492,7 @@ public E last(@GuardSatisfied @NonEmpty TreeSet this) { /** * @since 1.6 */ + @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollFirst(@GuardSatisfied TreeSet this) { Map.Entry e = m.pollFirstEntry(); return (e == null) ? null : e.getKey(); @@ -493,6 +501,7 @@ public E last(@GuardSatisfied @NonEmpty TreeSet this) { /** * @since 1.6 */ + @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollLast(@GuardSatisfied TreeSet this) { Map.Entry e = m.pollLastEntry(); return (e == null) ? null : e.getKey(); @@ -506,6 +515,7 @@ public E last(@GuardSatisfied @NonEmpty TreeSet this) { * @throws UnsupportedOperationException always * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { throw new UnsupportedOperationException(); } @@ -518,6 +528,7 @@ public void addFirst(E e) { * @throws UnsupportedOperationException always * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { throw new UnsupportedOperationException(); } @@ -614,6 +625,7 @@ private void readObject(java.io.ObjectInputStream s) * @return a {@code Spliterator} over the elements in this set * @since 1.8 */ + @DoesNotUnrefineReceiver("modifiability") public Spliterator spliterator() { return TreeMap.keySpliteratorFor(m); } diff --git a/src/java.base/share/classes/java/util/Vector.java b/src/java.base/share/classes/java/util/Vector.java index a8a3608bb7c2c..56f18e8dbc58b 100644 --- a/src/java.base/share/classes/java/util/Vector.java +++ b/src/java.base/share/classes/java/util/Vector.java @@ -38,6 +38,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; @@ -548,6 +549,7 @@ public synchronized E lastElement(@NonEmpty Vector this) { * @throws ArrayIndexOutOfBoundsException if the index is out of range * ({@code index < 0 || index >= size()}) */ + @DoesNotUnrefineReceiver("modifiability") public synchronized void setElementAt(@GuardSatisfied Vector this, E obj, @NonNegative int index) { if (index >= elementCount) { throw new ArrayIndexOutOfBoundsException(index + " >= " + @@ -575,6 +577,7 @@ public synchronized void setElementAt(@GuardSatisfied Vector this, E obj, @No * @throws ArrayIndexOutOfBoundsException if the index is out of range * ({@code index < 0 || index >= size()}) */ + @DoesNotUnrefineReceiver("modifiability") public synchronized void removeElementAt(@GuardSatisfied @CanShrink Vector this, @NonNegative int index) { if (index >= elementCount) { throw new ArrayIndexOutOfBoundsException(index + " >= " + @@ -615,6 +618,7 @@ else if (index < 0) { * @throws ArrayIndexOutOfBoundsException if the index is out of range * ({@code index < 0 || index > size()}) */ + @DoesNotUnrefineReceiver("modifiability") public synchronized void insertElementAt(@GuardSatisfied Vector this, E obj, @NonNegative int index) { if (index > elementCount) { throw new ArrayIndexOutOfBoundsException(index @@ -643,6 +647,7 @@ public synchronized void insertElementAt(@GuardSatisfied Vector this, E obj, * * @param obj the component to be added */ + @DoesNotUnrefineReceiver("modifiability") public synchronized void addElement(@GuardSatisfied Vector this, E obj) { modCount++; add(obj, elementData, elementCount); @@ -663,6 +668,7 @@ public synchronized void addElement(@GuardSatisfied Vector this, E obj) { * @return {@code true} if the argument was a component of this * vector; {@code false} otherwise. */ + @DoesNotUnrefineReceiver("modifiability") public synchronized boolean removeElement(@GuardSatisfied @CanShrink Vector this, Object obj) { modCount++; int i = indexOf(obj); @@ -679,6 +685,7 @@ public synchronized boolean removeElement(@GuardSatisfied @CanShrink Vector t *

This method is identical in functionality to the {@link #clear} * method (which is part of the {@link List} interface). */ + @DoesNotUnrefineReceiver("modifiability") public synchronized void removeAllElements(@GuardSatisfied @CanShrink Vector this) { final Object[] es = elementData; for (int to = elementCount, i = elementCount = 0; i < to; i++) @@ -798,6 +805,7 @@ public synchronized E get(@GuardSatisfied Vector this, @NonNegative int index * ({@code index < 0 || index >= size()}) * @since 1.2 */ + @DoesNotUnrefineReceiver("modifiability") public synchronized E set(@GuardSatisfied Vector this, @NonNegative int index, E element) { if (index >= elementCount) throw new ArrayIndexOutOfBoundsException(index); @@ -828,6 +836,7 @@ private void add(E e, Object[] elementData, int s) { */ @SideEffectsOnly("this") @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") public synchronized boolean add(@GuardSatisfied Vector this, E e) { modCount++; add(e, elementData, elementCount); @@ -845,6 +854,7 @@ public synchronized boolean add(@GuardSatisfied Vector this, E e) { * @return true if the Vector contained the specified element * @since 1.2 */ + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @CanShrink Vector this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { return removeElement(o); } @@ -860,6 +870,7 @@ public boolean remove(@GuardSatisfied @CanShrink Vector this, @GuardSatisfied * ({@code index < 0 || index > size()}) * @since 1.2 */ + @DoesNotUnrefineReceiver("modifiability") public void add(@GuardSatisfied Vector this, @NonNegative int index, E element) { insertElementAt(element, index); } @@ -875,6 +886,7 @@ public void add(@GuardSatisfied Vector this, @NonNegative int index, E elemen * ({@code index < 0 || index >= size()}) * @since 1.2 */ + @DoesNotUnrefineReceiver("modifiability") public synchronized E remove(@GuardSatisfied @CanShrink Vector this, @NonNegative int index) { modCount++; if (index >= elementCount) @@ -896,6 +908,7 @@ public synchronized E remove(@GuardSatisfied @CanShrink Vector this, @NonNega * * @since 1.2 */ + @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink Vector this) { removeAllElements(); } @@ -930,6 +943,7 @@ public synchronized boolean containsAll(@GuardSatisfied Vector this, @GuardSa * @throws NullPointerException if the specified collection is null * @since 1.2 */ + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@GuardSatisfied Vector this, Collection c) { Object[] a = c.toArray(); modCount++; @@ -964,6 +978,7 @@ public boolean addAll(@GuardSatisfied Vector this, Collection c) * or if the specified collection is null * @since 1.2 */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(@GuardSatisfied @CanShrink Vector this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> c.contains(e)); @@ -988,6 +1003,7 @@ public boolean removeAll(@GuardSatisfied @CanShrink Vector this, Collection this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> !c.contains(e)); @@ -998,6 +1014,7 @@ public boolean retainAll(@GuardSatisfied @CanShrink Vector this, Collection this, Predicate filter) { Objects.requireNonNull(filter); return bulkRemove(filter); @@ -1067,6 +1084,7 @@ private synchronized boolean bulkRemove(Predicate filter) { * @throws NullPointerException if the specified collection is null * @since 1.2 */ + @DoesNotUnrefineReceiver("modifiability") public synchronized boolean addAll(@GuardSatisfied Vector this, @NonNegative int index, Collection c) { if (index < 0 || index > elementCount) throw new ArrayIndexOutOfBoundsException(index); @@ -1172,6 +1190,7 @@ public synchronized String toString(@GuardSatisfied Vector this) { * This call shortens the list by {@code (toIndex - fromIndex)} elements. * (If {@code toIndex==fromIndex}, this operation has no effect.) */ + @DoesNotUnrefineReceiver("modifiability") protected synchronized void removeRange(@GuardSatisfied @CanShrink Vector this, int fromIndex, int toIndex) { modCount++; shiftTailOverGap(elementData, fromIndex, toIndex); @@ -1301,6 +1320,7 @@ public E next(@NonEmpty Itr this) { } } + @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastRet == -1) throw new IllegalStateException(); @@ -1372,6 +1392,7 @@ public E previous() { } } + @DoesNotUnrefineReceiver("modifiability") public void set(E e) { if (lastRet == -1) throw new IllegalStateException(); @@ -1381,6 +1402,7 @@ public void set(E e) { } } + @DoesNotUnrefineReceiver("modifiability") public void add(E e) { int i = cursor; synchronized (Vector.this) { @@ -1397,6 +1419,7 @@ public void add(E e) { * @throws NullPointerException {@inheritDoc} */ @Override + @DoesNotUnrefineReceiver("modifiability") public synchronized void forEach(Consumer action) { Objects.requireNonNull(action); final int expectedModCount = modCount; @@ -1413,6 +1436,7 @@ public synchronized void forEach(Consumer action) { */ @SuppressWarnings({"unchecked"}) @Override + @DoesNotUnrefineReceiver("modifiability") public synchronized void replaceAll(UnaryOperator operator) { Objects.requireNonNull(operator); final int expectedModCount = modCount; @@ -1428,6 +1452,7 @@ public synchronized void replaceAll(UnaryOperator operator) { @SuppressWarnings("unchecked") @Override + @DoesNotUnrefineReceiver("modifiability") public synchronized void sort(Comparator c) { final int expectedModCount = modCount; Arrays.sort((E[]) elementData, 0, elementCount, c); diff --git a/src/java.base/share/classes/java/util/WeakHashMap.java b/src/java.base/share/classes/java/util/WeakHashMap.java index 0bf358ec1f604..1a4dddae10bf5 100644 --- a/src/java.base/share/classes/java/util/WeakHashMap.java +++ b/src/java.base/share/classes/java/util/WeakHashMap.java @@ -36,6 +36,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; @@ -482,6 +483,7 @@ Entry getEntry(Object key) { * previously associated {@code null} with {@code key}.) */ @EnsuresKeyFor(value={"#1"}, map={"this"}) + @DoesNotUnrefineReceiver("modifiability") public @Nullable V put(@GuardSatisfied WeakHashMap this, K key, V value) { Object k = maskNull(key); int h = hash(k); @@ -574,6 +576,7 @@ private void transfer(Entry[] src, Entry[] dest) { * @param m mappings to be stored in this map. * @throws NullPointerException if the specified map is null. */ + @DoesNotUnrefineReceiver("modifiability") public void putAll(@GuardSatisfied WeakHashMap this, Map m) { int numKeysToBeAdded = m.size(); if (numKeysToBeAdded == 0) @@ -623,6 +626,7 @@ public void putAll(@GuardSatisfied WeakHashMap this, Map this, @GuardSatisfied @Nullable @UnknownSignedness Object key) { Object k = maskNull(key); int h = hash(k); @@ -682,6 +686,7 @@ boolean removeMapping(Object o) { * Removes all of the mappings from this map. * The map will be empty after this call returns. */ + @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied WeakHashMap this) { // clear out ref queue. We don't need to expunge entries // since table is getting cleared. @@ -762,6 +767,7 @@ public V getValue() { return value; } + @DoesNotUnrefineReceiver("modifiability") public V setValue(V newValue) { V oldValue = value; value = newValue; @@ -853,6 +859,7 @@ protected Entry nextEntry() { return lastReturned; } + @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastReturned == null) throw new IllegalStateException(); @@ -929,6 +936,7 @@ public boolean contains(@Nullable @UnknownSignedness Object o) { return containsKey(o); } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { if (containsKey(o)) { WeakHashMap.this.remove(o); @@ -938,6 +946,7 @@ public boolean remove(@Nullable @UnknownSignedness Object o) { return false; } + @DoesNotUnrefineReceiver("modifiability") public void clear() { WeakHashMap.this.clear(); } @@ -988,6 +997,7 @@ public boolean contains(@Nullable @UnknownSignedness Object o) { return containsValue(o); } + @DoesNotUnrefineReceiver("modifiability") public void clear() { WeakHashMap.this.clear(); } @@ -1032,6 +1042,7 @@ && getEntry(e.getKey()) != null && getEntry(e.getKey()).equals(e); } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { return removeMapping(o); } @@ -1041,6 +1052,7 @@ public boolean remove(@Nullable @UnknownSignedness Object o) { return WeakHashMap.this.size(); } + @DoesNotUnrefineReceiver("modifiability") public void clear() { WeakHashMap.this.clear(); } @@ -1070,6 +1082,7 @@ public Spliterator> spliterator() { @SuppressWarnings("unchecked") @Override + @DoesNotUnrefineReceiver("modifiability") public void forEach(BiConsumer action) { Objects.requireNonNull(action); int expectedModCount = modCount; @@ -1092,6 +1105,7 @@ public void forEach(BiConsumer action) { @SuppressWarnings("unchecked") @Override + @DoesNotUnrefineReceiver("modifiability") public void replaceAll(BiFunction function) { Objects.requireNonNull(function); int expectedModCount = modCount; diff --git a/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java index 44f6b775e8993..d468f56ef8743 100644 --- a/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java @@ -47,6 +47,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; @@ -343,6 +344,7 @@ public ArrayBlockingQueue(int capacity, boolean fair, * @throws NullPointerException if the specified element is null */ @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { return super.add(e); } @@ -356,6 +358,7 @@ public boolean add(E e) { * * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { Objects.requireNonNull(e); final ReentrantLock lock = this.lock; @@ -379,6 +382,7 @@ public boolean offer(E e) { * @throws InterruptedException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public void put(E e) throws InterruptedException { Objects.requireNonNull(e); final ReentrantLock lock = this.lock; @@ -400,6 +404,7 @@ public void put(E e) throws InterruptedException { * @throws InterruptedException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException { @@ -420,6 +425,7 @@ public boolean offer(E e, long timeout, TimeUnit unit) } } + @DoesNotUnrefineReceiver("modifiability") public E poll(@GuardSatisfied @CanShrink ArrayBlockingQueue this) { final ReentrantLock lock = this.lock; lock.lock(); @@ -430,6 +436,7 @@ public E poll(@GuardSatisfied @CanShrink ArrayBlockingQueue this) { } } + @DoesNotUnrefineReceiver("modifiability") public E take(@GuardSatisfied @CanShrink ArrayBlockingQueue this) throws InterruptedException { final ReentrantLock lock = this.lock; lock.lockInterruptibly(); @@ -442,6 +449,7 @@ public E take(@GuardSatisfied @CanShrink ArrayBlockingQueue this) throws Inte } } + @DoesNotUnrefineReceiver("modifiability") public E poll(@GuardSatisfied @CanShrink ArrayBlockingQueue this, long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); final ReentrantLock lock = this.lock; @@ -527,6 +535,7 @@ 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 */ + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink ArrayBlockingQueue this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { if (o == null) return false; final ReentrantLock lock = this.lock; @@ -678,6 +687,7 @@ public String toString() { * Atomically removes all of the elements from this queue. * The queue will be empty after this call returns. */ + @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink ArrayBlockingQueue this) { final ReentrantLock lock = this.lock; lock.lock(); @@ -717,6 +727,7 @@ private static void circularClear(Object[] items, int i, int end) { * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink ArrayBlockingQueue this, Collection c) { return drainTo(c, Integer.MAX_VALUE); } @@ -727,6 +738,7 @@ public int drainTo(@GuardSatisfied @CanShrink ArrayBlockingQueue this, Collec * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink ArrayBlockingQueue this, Collection c, int maxElements) { Objects.requireNonNull(c); if (c == this) @@ -1292,6 +1304,7 @@ public void forEachRemaining(Consumer action) { } } + @DoesNotUnrefineReceiver("modifiability") public void remove() { final ReentrantLock lock = ArrayBlockingQueue.this.lock; lock.lock(); @@ -1493,6 +1506,7 @@ public void forEach(Consumer action) { /** * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink ArrayBlockingQueue this, Predicate filter) { Objects.requireNonNull(filter); return bulkRemove(filter); @@ -1501,6 +1515,7 @@ public boolean removeIf(@CanShrink ArrayBlockingQueue this, Predicate this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> c.contains(e)); @@ -1509,6 +1524,7 @@ public boolean removeAll(@CanShrink ArrayBlockingQueue this, Collection this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> !c.contains(e)); diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java index f5bfb81b94a01..2303a0578076a 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java @@ -48,6 +48,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; @@ -664,6 +665,7 @@ static class Node implements Map.Entry { public final String toString() { return Helpers.mapEntryToString(key, val); } + @DoesNotUnrefineReceiver("modifiability") public final V setValue(V value) { throw new UnsupportedOperationException(); } @@ -1029,6 +1031,7 @@ public boolean containsValue(@GuardSatisfied @UnknownSignedness Object value) { * @throws NullPointerException if the specified key or value is null */ @EnsuresKeyFor(value={"#1"}, map={"this"}) + @DoesNotUnrefineReceiver("modifiability") public @Nullable V put(K key, V value) { return putVal(key, value, false); } @@ -1110,6 +1113,7 @@ else if (f instanceof ReservationNode) * * @param m mappings to be stored in this map */ + @DoesNotUnrefineReceiver("modifiability") public void putAll(Map m) { tryPresize(m.size()); for (Map.Entry e : m.entrySet()) @@ -1125,6 +1129,7 @@ public void putAll(Map m) { * {@code null} if there was no mapping for {@code key} * @throws NullPointerException if the specified key is null */ + @DoesNotUnrefineReceiver("modifiability") public @Nullable V remove(@GuardSatisfied @UnknownSignedness Object key) { return replaceNode(key, null, null); } @@ -1210,6 +1215,7 @@ else if (f instanceof ReservationNode) /** * Removes all of the mappings from this map. */ + @DoesNotUnrefineReceiver("modifiability") public void clear() { long delta = 0L; // negative number of deletions int i = 0; @@ -1570,6 +1576,7 @@ private void readObject(java.io.ObjectInputStream s) * @throws NullPointerException if the specified key or value is null */ @EnsuresKeyFor(value={"#1"}, map={"this"}) + @DoesNotUnrefineReceiver("modifiability") public @Nullable V putIfAbsent(K key, V value) { return putVal(key, value, true); } @@ -1579,6 +1586,7 @@ private void readObject(java.io.ObjectInputStream s) * * @throws NullPointerException if the specified key is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @UnknownSignedness Object key, @GuardSatisfied @UnknownSignedness Object value) { if (key == null) throw new NullPointerException(); @@ -1590,6 +1598,7 @@ public boolean remove(@GuardSatisfied @UnknownSignedness Object key, @GuardSatis * * @throws NullPointerException if any of the arguments are null */ + @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { if (key == null || oldValue == null || newValue == null) throw new NullPointerException(); @@ -1603,6 +1612,7 @@ public boolean replace(K key, V oldValue, V newValue) { * or {@code null} if there was no mapping for the key * @throws NullPointerException if the specified key or value is null */ + @DoesNotUnrefineReceiver("modifiability") public @Nullable V replace(K key, V value) { if (key == null || value == null) throw new NullPointerException(); @@ -1628,6 +1638,7 @@ public V getOrDefault(@GuardSatisfied @UnknownSignedness Object key, V defaultVa return (v = get(key)) == null ? defaultValue : v; } + @DoesNotUnrefineReceiver("modifiability") public void forEach(BiConsumer action) { if (action == null) throw new NullPointerException(); Node[] t; @@ -1639,6 +1650,7 @@ public void forEach(BiConsumer action) { } } + @DoesNotUnrefineReceiver("modifiability") public void replaceAll(BiFunction function) { if (function == null) throw new NullPointerException(); Node[] t; @@ -1722,6 +1734,7 @@ boolean removeValueIf(Predicate function) { * @throws RuntimeException or Error if the mappingFunction does so, * in which case the mapping is left unestablished */ + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V computeIfAbsent(K key, Function mappingFunction) { if (key == null || mappingFunction == null) throw new NullPointerException(); @@ -1834,6 +1847,7 @@ else if (f instanceof ReservationNode) * @throws RuntimeException or Error if the remappingFunction does so, * in which case the mapping is unchanged */ + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V computeIfPresent(K key, BiFunction remappingFunction) { if (key == null || remappingFunction == null) throw new NullPointerException(); @@ -1928,6 +1942,7 @@ else if (f instanceof ReservationNode) * @throws RuntimeException or Error if the remappingFunction does so, * in which case the mapping is unchanged */ + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V compute(K key, BiFunction remappingFunction) { if (key == null || remappingFunction == null) @@ -2057,6 +2072,7 @@ else if (f instanceof ReservationNode) * @throws RuntimeException or Error if the remappingFunction does so, * in which case the mapping is unchanged */ + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V merge(K key, @NonNull V value, BiFunction remappingFunction) { if (key == null || value == null || remappingFunction == null) throw new NullPointerException(); @@ -3478,6 +3494,7 @@ static class BaseIterator extends Traverser { @Pure public final boolean hasMoreElements() { return next != null; } + @DoesNotUnrefineReceiver("modifiability") public final void remove() { Node p; if ((p = lastReturned) == null) @@ -3582,6 +3599,7 @@ public boolean equals(Object o) { * could even have been removed, in which case the put will * re-establish). We do not and cannot guarantee more. */ + @DoesNotUnrefineReceiver("modifiability") public V setValue(V value) { if (value == null) throw new NullPointerException(); V v = val; @@ -4473,6 +4491,7 @@ abstract static sealed class CollectionView * Removes all of the elements from this view, by removing all * the mappings from the map backing this view. */ + @DoesNotUnrefineReceiver("modifiability") public final void clear() { map.clear(); } @Pure public final int size() { return map.size(); } @@ -4495,6 +4514,7 @@ abstract static sealed class CollectionView @Pure @EnsuresNonEmptyIf(result = true, expression = "this") public abstract boolean contains(@UnknownSignedness Object o); + @DoesNotUnrefineReceiver("modifiability") public abstract boolean remove(@UnknownSignedness Object o); private static final String OOME_MSG = "Required array size too large"; @@ -4591,6 +4611,7 @@ public final boolean containsAll(Collection c) { if (c == null) throw new NullPointerException(); boolean modified = false; @@ -4613,6 +4634,7 @@ public boolean removeAll(Collection c) { if (c == null) throw new NullPointerException(); boolean modified = false; @@ -4677,6 +4699,7 @@ public static final class KeySetView extends CollectionView * @return {@code true} if the backing map contained the specified key * @throws NullPointerException if the specified key is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { return map.remove(o) != null; } /** @@ -4701,6 +4724,7 @@ public Iterator iterator() { * for additions was provided */ @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") public boolean add(K e) { V v; if ((v = value) == null) @@ -4719,6 +4743,7 @@ public boolean add(K e) { * @throws UnsupportedOperationException if no default mapped value * for additions was provided */ + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { boolean added = false; V v; @@ -4780,6 +4805,7 @@ public final boolean contains(@UnknownSignedness Object o) { return map.containsValue(o); } + @DoesNotUnrefineReceiver("modifiability") public final boolean remove(@UnknownSignedness Object o) { if (o != null) { for (Iterator it = iterator(); it.hasNext();) { @@ -4801,9 +4827,11 @@ public final Iterator iterator() { } @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") public final boolean add(V e) { throw new UnsupportedOperationException(); } + @DoesNotUnrefineReceiver("modifiability") public final boolean addAll(Collection c) { throw new UnsupportedOperationException(); } @@ -4820,6 +4848,7 @@ public final boolean addAll(Collection c) { return modified; } + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { return map.removeValueIf(filter); } @@ -4885,10 +4914,12 @@ public Iterator> iterator() { } @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") public boolean add(Entry e) { return map.putVal(e.getKey(), e.getValue(), false) == null; } + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection> c) { boolean added = false; for (Entry e : c) { @@ -4898,6 +4929,7 @@ public boolean addAll(Collection> c) { return added; } + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate> filter) { return map.removeEntryIf(filter); } diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java index b3a9cf89266e0..ba68e9406fb99 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java @@ -48,6 +48,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; @@ -842,6 +843,7 @@ private void initHeadTail(Node h, Node t) { * * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { linkFirst(e); } @@ -855,6 +857,7 @@ public void addFirst(E e) { * * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { linkLast(e); } @@ -866,6 +869,7 @@ public void addLast(E e) { * @return {@code true} (as specified by {@link Deque#offerFirst}) * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean offerFirst(E e) { linkFirst(e); return true; @@ -880,6 +884,7 @@ public boolean offerFirst(E e) { * @return {@code true} (as specified by {@link Deque#offerLast}) * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean offerLast(E e) { linkLast(e); return true; @@ -931,6 +936,7 @@ public E getLast(@NonEmpty ConcurrentLinkedDeque this) { return screenNullResult(peekLast()); } + @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollFirst(@GuardSatisfied @CanShrink ConcurrentLinkedDeque this) { restart: for (;;) { for (Node first = first(), p = first;;) { @@ -952,6 +958,7 @@ public E getLast(@NonEmpty ConcurrentLinkedDeque this) { } } + @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollLast(@GuardSatisfied @CanShrink ConcurrentLinkedDeque this) { restart: for (;;) { for (Node last = last(), p = last;;) { @@ -976,6 +983,7 @@ public E getLast(@NonEmpty ConcurrentLinkedDeque this) { /** * @throws NoSuchElementException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public E removeFirst(@GuardSatisfied @NonEmpty @CanShrink ConcurrentLinkedDeque this) { return screenNullResult(pollFirst()); } @@ -983,6 +991,7 @@ public E removeFirst(@GuardSatisfied @NonEmpty @CanShrink ConcurrentLinkedDeque< /** * @throws NoSuchElementException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public E removeLast(@GuardSatisfied @NonEmpty @CanShrink ConcurrentLinkedDeque this) { return screenNullResult(pollLast()); } @@ -996,6 +1005,7 @@ public E removeLast(@GuardSatisfied @NonEmpty @CanShrink ConcurrentLinkedDeque this) { return pollFirst(); } @Pure public @Nullable E peek() { return peekFirst(); } @@ -1020,11 +1032,13 @@ public boolean add(E e) { /** * @throws NoSuchElementException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public E remove(@NonEmpty @CanShrink ConcurrentLinkedDeque this) { return removeFirst(); } /** * @throws NoSuchElementException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public E pop(@GuardSatisfied @NonEmpty @CanShrink ConcurrentLinkedDeque this) { return removeFirst(); } /** @@ -1035,6 +1049,7 @@ public boolean add(E e) { /** * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public void push(E e) { addFirst(e); } /** @@ -1049,6 +1064,7 @@ public boolean add(E e) { * @return {@code true} if the deque contained the specified element * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeFirstOccurrence(@CanShrink ConcurrentLinkedDeque this, Object o) { Objects.requireNonNull(o); for (Node p = first(); p != null; p = succ(p)) { @@ -1075,6 +1091,7 @@ public boolean removeFirstOccurrence(@CanShrink ConcurrentLinkedDeque this, O * @return {@code true} if the deque contained the specified element * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeLastOccurrence(@CanShrink ConcurrentLinkedDeque this, Object o) { Objects.requireNonNull(o); for (Node p = last(); p != null; p = pred(p)) { @@ -1167,6 +1184,7 @@ public int size() { * @return {@code true} if the deque contained the specified element * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink ConcurrentLinkedDeque this, @GuardSatisfied @UnknownSignedness Object o) { return removeFirstOccurrence(o); } @@ -1183,6 +1201,7 @@ public boolean remove(@CanShrink ConcurrentLinkedDeque this, @GuardSatisfied * of its elements are null * @throws IllegalArgumentException if the collection is this deque */ + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { if (c == this) // As historically specified in AbstractQueue#addAll @@ -1237,6 +1256,7 @@ else if (p.prev == p) // NEXT_TERMINATOR /** * Removes all of the elements from this deque. */ + @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink ConcurrentLinkedDeque this) { while (pollFirst() != null) ; @@ -1453,6 +1473,7 @@ public E next(@NonEmpty AbstractItr this) { return item; } + @DoesNotUnrefineReceiver("modifiability") public void remove() { Node l = lastRet; if (l == null) throw new IllegalStateException(); @@ -1638,6 +1659,7 @@ private void readObject(java.io.ObjectInputStream s) /** * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink ConcurrentLinkedDeque this, Predicate filter) { Objects.requireNonNull(filter); return bulkRemove(filter); @@ -1646,6 +1668,7 @@ public boolean removeIf(@CanShrink ConcurrentLinkedDeque this, Predicate this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> c.contains(e)); @@ -1654,6 +1677,7 @@ public boolean removeAll(@CanShrink ConcurrentLinkedDeque this, Collection this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> !c.contains(e)); diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java index 18ee6f6aebc46..e51cb0e6a989f 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java @@ -47,6 +47,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; @@ -298,6 +299,7 @@ public ConcurrentLinkedQueue(Collection c) { * @throws NullPointerException if the specified element is null */ @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { return offer(e); } @@ -370,6 +372,7 @@ private Node skipDeadNodes(Node pred, Node c, Node p, Node q) { * @return {@code true} (as specified by {@link Queue#offer}) * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { final Node newNode = new Node(Objects.requireNonNull(e)); @@ -399,6 +402,7 @@ else if (p == q) } } + @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink ConcurrentLinkedQueue this) { restartFromHead: for (;;) { for (Node h = head, p = h, q;; p = q) { @@ -543,6 +547,7 @@ public boolean contains(@GuardSatisfied @UnknownSignedness Object o) { * @param o element to be removed from this queue, if present * @return {@code true} if this queue changed as a result of the call */ + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink ConcurrentLinkedQueue this, @GuardSatisfied @UnknownSignedness Object o) { if (o == null) return false; restartFromHead: for (;;) { @@ -579,6 +584,7 @@ public boolean remove(@CanShrink ConcurrentLinkedQueue this, @GuardSatisfied * of its elements are null * @throws IllegalArgumentException if the collection is this queue */ + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { if (c == this) // As historically specified in AbstractQueue#addAll @@ -825,6 +831,7 @@ public E next(@NonEmpty Itr this) { // Default implementation of forEachRemaining is "good enough". + @DoesNotUnrefineReceiver("modifiability") public void remove() { Node l = lastRet; if (l == null) throw new IllegalStateException(); @@ -991,6 +998,7 @@ public Spliterator spliterator() { /** * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink ConcurrentLinkedQueue this, Predicate filter) { Objects.requireNonNull(filter); return bulkRemove(filter); @@ -999,6 +1007,7 @@ public boolean removeIf(@CanShrink ConcurrentLinkedQueue this, Predicate this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> c.contains(e)); @@ -1007,11 +1016,13 @@ public boolean removeAll(@CanShrink ConcurrentLinkedQueue this, Collection this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> !c.contains(e)); } + @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink ConcurrentLinkedQueue this) { bulkRemove(e -> true); } diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java index bda48d782303a..9a400a014e248 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java @@ -44,6 +44,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; @@ -1356,6 +1357,7 @@ public V getOrDefault(@GuardSatisfied @UnknownSignedness Object key, V defaultVa * with the keys currently in the map * @throws NullPointerException if the specified key or value is null */ + @DoesNotUnrefineReceiver("modifiability") public V put(K key, V value) { if (value == null) throw new NullPointerException(); @@ -1372,6 +1374,7 @@ public V put(K key, V value) { * with the keys currently in the map * @throws NullPointerException if the specified key is null */ + @DoesNotUnrefineReceiver("modifiability") public V remove(@GuardSatisfied @UnknownSignedness Object key) { return doRemove(key, null); } @@ -1427,6 +1430,7 @@ public boolean isEmpty() { /** * Removes all of the mappings from this map. */ + @DoesNotUnrefineReceiver("modifiability") public void clear() { Index h, r, d; Node b; VarHandle.acquireFence(); @@ -1472,6 +1476,7 @@ else if ((d = h.down) != null) // remove levels * or the mappingFunction is null * @since 1.8 */ + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V computeIfAbsent(K key, Function mappingFunction) { if (key == null || mappingFunction == null) @@ -1496,6 +1501,7 @@ else if ((d = h.down) != null) // remove levels * or the remappingFunction is null * @since 1.8 */ + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V computeIfPresent(K key, BiFunction remappingFunction) { if (key == null || remappingFunction == null) @@ -1528,6 +1534,7 @@ else if (doRemove(key, v) != null) * or the remappingFunction is null * @since 1.8 */ + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V compute(K key, BiFunction remappingFunction) { if (key == null || remappingFunction == null) @@ -1567,6 +1574,7 @@ else if (doRemove(key, v) != null) * or the remappingFunction is null * @since 1.8 */ + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V merge(K key, @NonNull V value, BiFunction remappingFunction) { if (key == null || value == null || remappingFunction == null) @@ -1806,6 +1814,7 @@ public boolean equals(@Nullable Object o) { * with the keys currently in the map * @throws NullPointerException if the specified key or value is null */ + @DoesNotUnrefineReceiver("modifiability") public V putIfAbsent(K key, V value) { if (value == null) throw new NullPointerException(); @@ -1819,6 +1828,7 @@ public V putIfAbsent(K key, V value) { * with the keys currently in the map * @throws NullPointerException if the specified key is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @UnknownSignedness Object key, @GuardSatisfied @UnknownSignedness Object value) { if (key == null) throw new NullPointerException(); @@ -1832,6 +1842,7 @@ public boolean remove(@GuardSatisfied @UnknownSignedness Object key, @GuardSatis * with the keys currently in the map * @throws NullPointerException if any of the arguments are null */ + @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { if (key == null || oldValue == null || newValue == null) throw new NullPointerException(); @@ -1857,6 +1868,7 @@ public boolean replace(K key, V oldValue, V newValue) { * with the keys currently in the map * @throws NullPointerException if the specified key or value is null */ + @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { if (key == null || value == null) throw new NullPointerException(); @@ -1903,6 +1915,7 @@ public K lastKey(@NonEmpty ConcurrentSkipListMap this) { * @throws UnsupportedOperationException always * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") public V putFirst(K k, V v) { throw new UnsupportedOperationException(); } @@ -1915,6 +1928,7 @@ public V putFirst(K k, V v) { * @throws UnsupportedOperationException always * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") public V putLast(K k, V v) { throw new UnsupportedOperationException(); } @@ -2113,6 +2127,7 @@ public Map.Entry lastEntry() { * The returned entry does not support * the {@code Entry.setValue} method. */ + @DoesNotUnrefineReceiver("modifiability") public Map.Entry pollFirstEntry() { return doRemoveFirstEntry(); } @@ -2123,6 +2138,7 @@ public Map.Entry pollFirstEntry() { * The returned entry does not support * the {@code Entry.setValue} method. */ + @DoesNotUnrefineReceiver("modifiability") public Map.Entry pollLastEntry() { return doRemoveLastEntry(); } @@ -2163,6 +2179,7 @@ final void advance(Node b) { next = n; } + @DoesNotUnrefineReceiver("modifiability") public final void remove() { Node n; K k; if ((n = lastReturned) == null || (k = n.key) == null) @@ -2235,7 +2252,9 @@ static final class KeySet @Pure @EnsuresNonEmptyIf(result = true, expression = "this") public boolean contains(@UnknownSignedness Object o) { return m.containsKey(o); } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { return m.remove(o) != null; } + @DoesNotUnrefineReceiver("modifiability") public void clear() { m.clear(); } public K lower(K e) { return m.lowerKey(e); } public K floor(K e) { return m.floorKey(e); } @@ -2244,10 +2263,12 @@ static final class KeySet public Comparator comparator() { return m.comparator(); } public K first() { return m.firstKey(); } public K last() { return m.lastKey(); } + @DoesNotUnrefineReceiver("modifiability") public K pollFirst() { Map.Entry e = m.pollFirstEntry(); return (e == null) ? null : e.getKey(); } + @DoesNotUnrefineReceiver("modifiability") public K pollLast() { Map.Entry e = m.pollLastEntry(); return (e == null) ? null : e.getKey(); @@ -2325,6 +2346,7 @@ public Iterator iterator() { @Pure @EnsuresNonEmptyIf(result = true, expression = "this") public boolean contains(@UnknownSignedness Object o) { return m.containsValue(o); } + @DoesNotUnrefineReceiver("modifiability") public void clear() { m.clear(); } public Object[] toArray() { return toList(this).toArray(); } public @Nullable T[] toArray(@PolyNull T[] a) { return toList(this).toArray(a); } @@ -2335,6 +2357,7 @@ public Spliterator spliterator() { : ((SubMap)m).new SubMapValueIterator(); } + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { if (filter == null) throw new NullPointerException(); if (m instanceof ConcurrentSkipListMap) @@ -2373,6 +2396,7 @@ public boolean contains(@UnknownSignedness Object o) { V v = m.get(e.getKey()); return v != null && v.equals(e.getValue()); } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { if (!(o instanceof Map.Entry)) return false; @@ -2389,6 +2413,7 @@ public boolean isEmpty() { public int size() { return m.size(); } + @DoesNotUnrefineReceiver("modifiability") public void clear() { m.clear(); } @@ -2412,6 +2437,7 @@ public Spliterator> spliterator() { ? ((ConcurrentSkipListMap)m).entrySpliterator() : ((SubMap)m).new SubMapEntryIterator(); } + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate> filter) { if (filter == null) throw new NullPointerException(); if (m instanceof ConcurrentSkipListMap) @@ -2698,11 +2724,13 @@ public V get(Object key) { return (!inBounds(key, m.comparator)) ? null : m.get(key); } + @DoesNotUnrefineReceiver("modifiability") public V put(K key, V value) { checkKeyBounds(key, m.comparator); return m.put(key, value); } + @DoesNotUnrefineReceiver("modifiability") public V remove(Object key) { return (!inBounds(key, m.comparator)) ? null : m.remove(key); } @@ -2742,6 +2770,7 @@ public boolean containsValue(@UnknownSignedness Object value) { return false; } + @DoesNotUnrefineReceiver("modifiability") public void clear() { Comparator cmp = m.comparator; for (ConcurrentSkipListMap.Node n = loNode(cmp); @@ -2754,20 +2783,24 @@ public void clear() { /* ---------------- ConcurrentMap API methods -------------- */ + @DoesNotUnrefineReceiver("modifiability") public V putIfAbsent(K key, V value) { checkKeyBounds(key, m.comparator); return m.putIfAbsent(key, value); } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object key, @UnknownSignedness Object value) { return inBounds(key, m.comparator) && m.remove(key, value); } + @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { checkKeyBounds(key, m.comparator); return m.replace(key, oldValue, newValue); } + @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { checkKeyBounds(key, m.comparator); return m.replace(key, value); @@ -2917,10 +2950,12 @@ public Map.Entry lastEntry() { return isDescending ? lowestEntry() : highestEntry(); } + @DoesNotUnrefineReceiver("modifiability") public Map.Entry pollFirstEntry() { return isDescending ? removeHighest() : removeLowest(); } + @DoesNotUnrefineReceiver("modifiability") public Map.Entry pollLastEntry() { return isDescending ? removeLowest() : removeHighest(); } @@ -3038,6 +3073,7 @@ private void descend() { } } + @DoesNotUnrefineReceiver("modifiability") public void remove() { Node l = lastReturned; if (l == null) @@ -3110,6 +3146,7 @@ public int characteristics() { // default Map method overrides + @DoesNotUnrefineReceiver("modifiability") public void forEach(BiConsumer action) { if (action == null) throw new NullPointerException(); Node b, n; V v; @@ -3122,6 +3159,7 @@ public void forEach(BiConsumer action) { } } + @DoesNotUnrefineReceiver("modifiability") public void replaceAll(BiFunction function) { if (function == null) throw new NullPointerException(); Node b, n; V v; diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java index 1e02531ced656..6a90b130ae0f5 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java @@ -45,6 +45,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; @@ -261,6 +262,7 @@ public boolean contains(@GuardSatisfied @UnknownSignedness Object o) { * @throws NullPointerException if the specified element is null */ @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { return m.putIfAbsent(e, Boolean.TRUE) == null; } @@ -279,6 +281,7 @@ public boolean add(E e) { * with the elements currently in this set * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @UnknownSignedness Object o) { return m.remove(o, Boolean.TRUE); } @@ -286,6 +289,7 @@ public boolean remove(@GuardSatisfied @UnknownSignedness Object o) { /** * Removes all of the elements from this set. */ + @DoesNotUnrefineReceiver("modifiability") public void clear() { m.clear(); } @@ -354,6 +358,7 @@ public boolean equals(@Nullable Object o) { * @throws NullPointerException if the specified collection or any * of its elements are null */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { // Override AbstractSet version to avoid unnecessary call to size() boolean modified = false; @@ -397,11 +402,13 @@ public E higher(E e) { return m.higherKey(e); } + @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollFirst() { Map.Entry e = m.pollFirstEntry(); return (e == null) ? null : e.getKey(); } + @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollLast() { Map.Entry e = m.pollLastEntry(); return (e == null) ? null : e.getKey(); diff --git a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java index c1e3a26613db1..4c6d6260bcbea 100644 --- a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java +++ b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java @@ -47,6 +47,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; @@ -459,6 +460,7 @@ public E getLast() { * * @throws IndexOutOfBoundsException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public E set(int index, E element) { synchronized (lock) { Object[] es = getArray(); @@ -481,6 +483,7 @@ public E set(int index, E element) { * @return {@code true} (as specified by {@link Collection#add}) */ @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { synchronized (lock) { Object[] es = getArray(); @@ -499,6 +502,7 @@ public boolean add(E e) { * * @throws IndexOutOfBoundsException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public void add(int index, E element) { synchronized (lock) { Object[] es = getArray(); @@ -525,6 +529,7 @@ public void add(int index, E element) { * * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { add(0, e); } @@ -534,6 +539,7 @@ public void addFirst(E e) { * * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { synchronized (lock) { add(getArray().length, e); @@ -547,6 +553,7 @@ public void addLast(E e) { * * @throws IndexOutOfBoundsException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @CanShrink CopyOnWriteArrayList this, int index) { synchronized (lock) { Object[] es = getArray(); @@ -573,6 +580,7 @@ public E remove(@GuardSatisfied @CanShrink CopyOnWriteArrayList this, int ind * @throws NoSuchElementException {@inheritDoc} * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") public E removeFirst() { synchronized (lock) { if (getArray().length == 0) @@ -588,6 +596,7 @@ public E removeFirst() { * @throws NoSuchElementException {@inheritDoc} * @since 21 */ + @DoesNotUnrefineReceiver("modifiability") public E removeLast() { synchronized (lock) { int size = getArray().length; @@ -610,6 +619,7 @@ public E removeLast() { * @param o element to be removed from this list, if present * @return {@code true} if this list contained the specified element */ + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink CopyOnWriteArrayList this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { Object[] snapshot = getArray(); int index = indexOfRange(o, snapshot, 0, snapshot.length); @@ -690,6 +700,7 @@ void removeRange(@GuardSatisfied @CanShrink CopyOnWriteArrayList this, int fr * @param e element to be added to this list, if absent * @return {@code true} if the element was added */ + @DoesNotUnrefineReceiver("modifiability") public boolean addIfAbsent(E e) { Object[] snapshot = getArray(); return indexOfRange(e, snapshot, 0, snapshot.length) < 0 @@ -758,6 +769,7 @@ public boolean containsAll(Collection c) { * or if the specified collection is null * @see #remove(Object) */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(@CanShrink CopyOnWriteArrayList this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> c.contains(e)); @@ -779,6 +791,7 @@ public boolean removeAll(@CanShrink CopyOnWriteArrayList this, Collection this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> !c.contains(e)); @@ -795,6 +808,7 @@ public boolean retainAll(@GuardSatisfied @CanShrink CopyOnWriteArrayList this * @throws NullPointerException if the specified collection is null * @see #addIfAbsent(Object) */ + @DoesNotUnrefineReceiver("modifiability") public int addAllAbsent(Collection c) { Object[] cs = c.toArray(); if (c.getClass() != ArrayList.class) { @@ -826,6 +840,7 @@ public int addAllAbsent(Collection c) { * Removes all of the elements from this list. * The list will be empty after this call returns. */ + @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink CopyOnWriteArrayList this) { synchronized (lock) { setArray(new Object[0]); @@ -842,6 +857,7 @@ public void clear(@GuardSatisfied @CanShrink CopyOnWriteArrayList this) { * @throws NullPointerException if the specified collection is null * @see #add(Object) */ + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { Object[] cs = (c.getClass() == CopyOnWriteArrayList.class) ? ((CopyOnWriteArrayList)c).getArray() : c.toArray(); @@ -879,6 +895,7 @@ public boolean addAll(Collection c) { * @throws NullPointerException if the specified collection is null * @see #add(int,Object) */ + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(int index, Collection c) { Object[] cs = c.toArray(); synchronized (lock) { @@ -919,6 +936,7 @@ public void forEach(Consumer action) { /** * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink CopyOnWriteArrayList this, Predicate filter) { Objects.requireNonNull(filter); return bulkRemove(filter); @@ -976,6 +994,7 @@ boolean bulkRemove(Predicate filter, int i, int end) { } } + @DoesNotUnrefineReceiver("modifiability") public void replaceAll(UnaryOperator operator) { synchronized (lock) { replaceAllRange(operator, 0, getArray().length); @@ -991,6 +1010,7 @@ void replaceAllRange(UnaryOperator operator, int i, int end) { setArray(es); } + @DoesNotUnrefineReceiver("modifiability") public void sort(Comparator c) { synchronized (lock) { sortRange(c, 0, getArray().length); @@ -1237,6 +1257,7 @@ public int previousIndex() { * @throws UnsupportedOperationException always; {@code remove} * is not supported by this iterator. */ + @DoesNotUnrefineReceiver("modifiability") public void remove() { throw new UnsupportedOperationException(); } @@ -1246,6 +1267,7 @@ public void remove() { * @throws UnsupportedOperationException always; {@code set} * is not supported by this iterator. */ + @DoesNotUnrefineReceiver("modifiability") public void set(E e) { throw new UnsupportedOperationException(); } @@ -1255,6 +1277,7 @@ public void set(E e) { * @throws UnsupportedOperationException always; {@code add} * is not supported by this iterator. */ + @DoesNotUnrefineReceiver("modifiability") public void add(E e) { throw new UnsupportedOperationException(); } @@ -1462,6 +1485,7 @@ public boolean equals(Object o) { return !it.hasNext(); } + @DoesNotUnrefineReceiver("modifiability") public E set(int index, E element) { synchronized (lock) { rangeCheck(index); @@ -1507,6 +1531,7 @@ public int size() { } @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") public boolean add(E element) { synchronized (lock) { checkForComodification(); @@ -1517,6 +1542,7 @@ public boolean add(E element) { return true; } + @DoesNotUnrefineReceiver("modifiability") public void add(int index, E element) { synchronized (lock) { checkForComodification(); @@ -1527,16 +1553,19 @@ public void add(int index, E element) { } } + @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { add(0, e); } + @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { synchronized (lock) { add(size, e); } } + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { synchronized (lock) { final Object[] oldArray = getArrayChecked(); @@ -1547,6 +1576,7 @@ public boolean addAll(Collection c) { } } + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(int index, Collection c) { synchronized (lock) { rangeCheckForAdd(index); @@ -1558,6 +1588,7 @@ public boolean addAll(int index, Collection c) { } } + @DoesNotUnrefineReceiver("modifiability") public void clear() { synchronized (lock) { checkForComodification(); @@ -1567,6 +1598,7 @@ public void clear() { } } + @DoesNotUnrefineReceiver("modifiability") public E remove(int index) { synchronized (lock) { rangeCheck(index); @@ -1578,6 +1610,7 @@ public E remove(int index) { } } + @DoesNotUnrefineReceiver("modifiability") public E removeFirst() { synchronized (lock) { if (size == 0) @@ -1587,6 +1620,7 @@ public E removeFirst() { } } + @DoesNotUnrefineReceiver("modifiability") public E removeLast() { synchronized (lock) { if (size == 0) @@ -1596,6 +1630,7 @@ public E removeLast() { } } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { synchronized (lock) { checkForComodification(); @@ -1645,6 +1680,7 @@ public void forEach(Consumer action) { action.accept(elementAt(es, i)); } + @DoesNotUnrefineReceiver("modifiability") public void replaceAll(UnaryOperator operator) { synchronized (lock) { checkForComodification(); @@ -1653,6 +1689,7 @@ public void replaceAll(UnaryOperator operator) { } } + @DoesNotUnrefineReceiver("modifiability") public void sort(Comparator c) { synchronized (lock) { checkForComodification(); @@ -1661,16 +1698,19 @@ public void sort(Comparator c) { } } + @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> c.contains(e)); } + @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> !c.contains(e)); } + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { Objects.requireNonNull(filter); return bulkRemove(filter); @@ -1800,6 +1840,7 @@ class DescendingIterator implements Iterator { } public boolean hasNext() { return it.hasPrevious(); } public E next() { return it.previous(); } + @DoesNotUnrefineReceiver("modifiability") public void remove() { it.remove(); } } @@ -1871,11 +1912,13 @@ public Spliterator spliterator() { // ========== Collection ========== + @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { base.add(0, e); return true; } + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { @SuppressWarnings("unchecked") E[] es = (E[]) c.toArray(); @@ -1888,6 +1931,7 @@ public boolean addAll(Collection c) { } } + @DoesNotUnrefineReceiver("modifiability") public void clear() { base.clear(); } @@ -1934,6 +1978,7 @@ public Stream parallelStream() { return StreamSupport.stream(spliterator(), true); } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(Object o) { synchronized (lock) { int index = indexOf(o); @@ -1944,10 +1989,12 @@ public boolean remove(Object o) { } } + @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { return base.removeAll(c); } + @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { return base.retainAll(c); } @@ -1993,20 +2040,24 @@ public String toString() { // ========== List ========== + @DoesNotUnrefineReceiver("modifiability") public void add(int index, E element) { synchronized (lock) { base.add(base.size() - index, element); } } + @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { base.add(e); } + @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { base.add(0, e); } + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(int index, Collection c) { @SuppressWarnings("unchecked") E[] es = (E[]) c.toArray(); @@ -2068,12 +2119,14 @@ public ListIterator listIterator(int index) { return new DescendingListIterator(index); } + @DoesNotUnrefineReceiver("modifiability") public E remove(int index) { synchronized (lock) { return base.remove(base.size() - index - 1); } } + @DoesNotUnrefineReceiver("modifiability") public E removeFirst() { synchronized (lock) { int size = base.size(); @@ -2084,6 +2137,7 @@ public E removeFirst() { } } + @DoesNotUnrefineReceiver("modifiability") public E removeLast() { synchronized (lock) { if (base.size() == 0) @@ -2093,18 +2147,22 @@ public E removeLast() { } } + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { return base.removeIf(filter); } + @DoesNotUnrefineReceiver("modifiability") public void replaceAll(UnaryOperator operator) { base.replaceAll(operator); } + @DoesNotUnrefineReceiver("modifiability") public void sort(Comparator c) { base.sort(Collections.reverseOrder(c)); } + @DoesNotUnrefineReceiver("modifiability") public E set(int index, E element) { synchronized (lock) { return base.set(base.size() - index - 1, element); diff --git a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java index b0078296d26ef..c8ac6fa4ac538 100644 --- a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java +++ b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java @@ -47,6 +47,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; @@ -246,6 +247,7 @@ public boolean contains(@GuardSatisfied @Nullable @UnknownSignedness Object o) { * Removes all of the elements from this set. * The set will be empty after this call returns. */ + @DoesNotUnrefineReceiver("modifiability") public void clear() { al.clear(); } @@ -261,6 +263,7 @@ public void clear() { * @param o object to be removed from this set, if present * @return {@code true} if this set contained the specified element */ + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @Nullable @UnknownSignedness Object o) { return al.remove(o); } @@ -278,6 +281,7 @@ public boolean remove(@GuardSatisfied @Nullable @UnknownSignedness Object o) { * element */ @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { return al.addIfAbsent(e); } @@ -348,6 +352,7 @@ private static int compareSets(Object[] snapshot, Set set) { * @throws NullPointerException if the specified collection is null * @see #add(Object) */ + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { return al.addAllAbsent(c) > 0; } @@ -369,6 +374,7 @@ public boolean addAll(Collection c) { * or if the specified collection is null * @see #remove(Object) */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { return al.removeAll(c); } @@ -392,6 +398,7 @@ public boolean removeAll(Collection c) { return al.retainAll(c); } @@ -438,6 +445,7 @@ public boolean equals(@Nullable Object o) { /** * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { return al.removeIf(filter); } diff --git a/src/java.base/share/classes/java/util/concurrent/DelayQueue.java b/src/java.base/share/classes/java/util/concurrent/DelayQueue.java index 368384198af83..ecf6e19e6501f 100644 --- a/src/java.base/share/classes/java/util/concurrent/DelayQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/DelayQueue.java @@ -43,6 +43,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; @@ -170,6 +171,7 @@ public DelayQueue(Collection c) { * @throws NullPointerException if the specified element is null */ @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { return offer(e); } @@ -181,6 +183,7 @@ public boolean add(E e) { * @return {@code true} * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { final ReentrantLock lock = this.lock; lock.lock(); @@ -203,6 +206,7 @@ public boolean offer(E e) { * @param e the element to add * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public void put(E e) { offer(e); } @@ -217,6 +221,7 @@ public void put(E e) { * @return {@code true} * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e, long timeout, TimeUnit unit) { return offer(e); } @@ -229,6 +234,7 @@ public boolean offer(E e, long timeout, TimeUnit unit) { * @return the expired head of this queue, or {@code null} if this * queue has no elements with an expired delay */ + @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink DelayQueue this) { final ReentrantLock lock = this.lock; lock.lock(); @@ -250,6 +256,7 @@ public boolean offer(E e, long timeout, TimeUnit unit) { * @return the expired head of this queue * @throws InterruptedException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public E take(@GuardSatisfied @CanShrink DelayQueue this) throws InterruptedException { final ReentrantLock lock = this.lock; lock.lockInterruptibly(); @@ -295,6 +302,7 @@ public E take(@GuardSatisfied @CanShrink DelayQueue this) throws InterruptedE * an expired delay becomes available * @throws InterruptedException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink DelayQueue this, long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); final ReentrantLock lock = this.lock; @@ -345,6 +353,7 @@ public E take(@GuardSatisfied @CanShrink DelayQueue this) throws InterruptedE * @throws NoSuchElementException if this queue has no elements with an * expired delay */ + @DoesNotUnrefineReceiver("modifiability") public E remove() { return super.remove(); } @@ -386,6 +395,7 @@ public int size() { * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink DelayQueue this, Collection c) { return drainTo(c, Integer.MAX_VALUE); } @@ -396,6 +406,7 @@ public int drainTo(@GuardSatisfied @CanShrink DelayQueue this, Collection this, Collection c, int maxElements) { Objects.requireNonNull(c); if (c == this) @@ -426,6 +437,7 @@ public int drainTo(@GuardSatisfied @CanShrink DelayQueue this, Collection this) { final ReentrantLock lock = this.lock; lock.lock(); @@ -520,6 +532,7 @@ public int remainingCapacity() { * Removes a single instance of the specified element from this * queue, if it is present, whether or not it has expired. */ + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink DelayQueue this, @UnknownSignedness Object o) { final ReentrantLock lock = this.lock; lock.lock(); @@ -590,6 +603,7 @@ public E next(@NonEmpty Itr this) { return (E)array[lastRet = cursor++]; } + @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastRet < 0) throw new IllegalStateException(); diff --git a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java index a77ccefcce810..60e15e79c35b9 100644 --- a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java +++ b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java @@ -47,6 +47,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; @@ -331,6 +332,7 @@ void unlink(@CanShrink LinkedBlockingDeque this, Node x) { * @throws IllegalStateException if this deque is full * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { if (!offerFirst(e)) throw new IllegalStateException("Deque full"); @@ -340,6 +342,7 @@ public void addFirst(E e) { * @throws IllegalStateException if this deque is full * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { if (!offerLast(e)) throw new IllegalStateException("Deque full"); @@ -348,6 +351,7 @@ public void addLast(E e) { /** * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean offerFirst(E e) { if (e == null) throw new NullPointerException(); Node node = new Node(e); @@ -363,6 +367,7 @@ public boolean offerFirst(E e) { /** * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean offerLast(E e) { if (e == null) throw new NullPointerException(); Node node = new Node(e); @@ -379,6 +384,7 @@ public boolean offerLast(E e) { * @throws NullPointerException {@inheritDoc} * @throws InterruptedException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public void putFirst(E e) throws InterruptedException { if (e == null) throw new NullPointerException(); Node node = new Node(e); @@ -396,6 +402,7 @@ public void putFirst(E e) throws InterruptedException { * @throws NullPointerException {@inheritDoc} * @throws InterruptedException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public void putLast(E e) throws InterruptedException { if (e == null) throw new NullPointerException(); Node node = new Node(e); @@ -413,6 +420,7 @@ public void putLast(E e) throws InterruptedException { * @throws NullPointerException {@inheritDoc} * @throws InterruptedException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException { if (e == null) throw new NullPointerException(); @@ -436,6 +444,7 @@ public boolean offerFirst(E e, long timeout, TimeUnit unit) * @throws NullPointerException {@inheritDoc} * @throws InterruptedException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean offerLast(E e, long timeout, TimeUnit unit) throws InterruptedException { if (e == null) throw new NullPointerException(); @@ -458,6 +467,7 @@ public boolean offerLast(E e, long timeout, TimeUnit unit) /** * @throws NoSuchElementException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public E removeFirst(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque this) { E x = pollFirst(); if (x == null) throw new NoSuchElementException(); @@ -467,12 +477,14 @@ public E removeFirst(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque /** * @throws NoSuchElementException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public E removeLast(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque this) { E x = pollLast(); if (x == null) throw new NoSuchElementException(); return x; } + @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollFirst(@GuardSatisfied @CanShrink LinkedBlockingDeque this) { final ReentrantLock lock = this.lock; lock.lock(); @@ -483,6 +495,7 @@ public E removeLast(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque } } + @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollLast(@GuardSatisfied @CanShrink LinkedBlockingDeque this) { final ReentrantLock lock = this.lock; lock.lock(); @@ -493,6 +506,7 @@ public E removeLast(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque } } + @DoesNotUnrefineReceiver("modifiability") public E takeFirst(@GuardSatisfied @CanShrink LinkedBlockingDeque this) throws InterruptedException { final ReentrantLock lock = this.lock; lock.lock(); @@ -506,6 +520,7 @@ public E takeFirst(@GuardSatisfied @CanShrink LinkedBlockingDeque this) throw } } + @DoesNotUnrefineReceiver("modifiability") public E takeLast(@GuardSatisfied @CanShrink LinkedBlockingDeque this) throws InterruptedException { final ReentrantLock lock = this.lock; lock.lock(); @@ -519,6 +534,7 @@ public E takeLast(@GuardSatisfied @CanShrink LinkedBlockingDeque this) throws } } + @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollFirst(@GuardSatisfied @CanShrink LinkedBlockingDeque this, long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); @@ -537,6 +553,7 @@ public E takeLast(@GuardSatisfied @CanShrink LinkedBlockingDeque this) throws } } + @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollLast(@GuardSatisfied @CanShrink LinkedBlockingDeque this, long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); @@ -595,6 +612,7 @@ public E getLast(@NonEmpty LinkedBlockingDeque this) { } } + @DoesNotUnrefineReceiver("modifiability") public boolean removeFirstOccurrence(@CanShrink LinkedBlockingDeque this, Object o) { if (o == null) return false; final ReentrantLock lock = this.lock; @@ -612,6 +630,7 @@ public boolean removeFirstOccurrence(@CanShrink LinkedBlockingDeque this, Obj } } + @DoesNotUnrefineReceiver("modifiability") public boolean removeLastOccurrence(@CanShrink LinkedBlockingDeque this, Object o) { if (o == null) return false; final ReentrantLock lock = this.lock; @@ -642,6 +661,7 @@ public boolean removeLastOccurrence(@CanShrink LinkedBlockingDeque this, Obje * @throws NullPointerException if the specified element is null */ @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { addLast(e); return true; @@ -650,6 +670,7 @@ public boolean add(E e) { /** * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { return offerLast(e); } @@ -658,6 +679,7 @@ public boolean offer(E e) { * @throws NullPointerException {@inheritDoc} * @throws InterruptedException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public void put(E e) throws InterruptedException { putLast(e); } @@ -666,6 +688,7 @@ public void put(E e) throws InterruptedException { * @throws NullPointerException {@inheritDoc} * @throws InterruptedException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException { return offerLast(e, timeout, unit); @@ -681,18 +704,22 @@ public boolean offer(E e, long timeout, TimeUnit unit) * @return the head of the queue represented by this deque * @throws NoSuchElementException if this deque is empty */ + @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque this) { return removeFirst(); } + @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink LinkedBlockingDeque this) { return pollFirst(); } + @DoesNotUnrefineReceiver("modifiability") public E take(@GuardSatisfied @CanShrink LinkedBlockingDeque this) throws InterruptedException { return takeFirst(); } + @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink LinkedBlockingDeque this, long timeout, TimeUnit unit) throws InterruptedException { return pollFirst(timeout, unit); } @@ -743,6 +770,7 @@ public int remainingCapacity() { * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink LinkedBlockingDeque this, Collection c) { return drainTo(c, Integer.MAX_VALUE); } @@ -753,6 +781,7 @@ public int drainTo(@GuardSatisfied @CanShrink LinkedBlockingDeque this, Colle * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink LinkedBlockingDeque this, Collection c, int maxElements) { Objects.requireNonNull(c); if (c == this) @@ -779,6 +808,7 @@ public int drainTo(@GuardSatisfied @CanShrink LinkedBlockingDeque this, Colle * @throws IllegalStateException if this deque is full * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public void push(E e) { addFirst(e); } @@ -786,6 +816,7 @@ public void push(E e) { /** * @throws NoSuchElementException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public E pop(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque this) { return removeFirst(); } @@ -806,6 +837,7 @@ public E pop(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque this) { * @param o element to be removed from this deque, if present * @return {@code true} if this deque changed as a result of the call */ + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink LinkedBlockingDeque this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { return removeFirstOccurrence(o); } @@ -864,6 +896,7 @@ public boolean contains(@GuardSatisfied @Nullable @UnknownSignedness Object o) { * @throws IllegalStateException if this deque is full * @see #add(Object) */ + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { if (c == this) // As historically specified in AbstractQueue#addAll @@ -1001,6 +1034,7 @@ public String toString() { * Atomically removes all of the elements from this deque. * The deque will be empty after this call returns. */ + @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink LinkedBlockingDeque this) { final ReentrantLock lock = this.lock; lock.lock(); @@ -1170,6 +1204,7 @@ public void forEachRemaining(Consumer action) { } while (n > 0 && p != null); } + @DoesNotUnrefineReceiver("modifiability") public void remove() { Node n = lastRet; if (n == null) @@ -1357,6 +1392,7 @@ void forEachFrom(Consumer action, Node p) { /** * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink LinkedBlockingDeque this, Predicate filter) { Objects.requireNonNull(filter); return bulkRemove(filter); @@ -1365,6 +1401,7 @@ public boolean removeIf(@CanShrink LinkedBlockingDeque this, Predicate this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> c.contains(e)); @@ -1373,6 +1410,7 @@ public boolean removeAll(@CanShrink LinkedBlockingDeque this, Collection this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> !c.contains(e)); diff --git a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java index b8bb0e7c10752..07f803be79da4 100644 --- a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java @@ -46,6 +46,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; @@ -340,6 +341,7 @@ public int remainingCapacity() { * @throws InterruptedException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public void put(E e) throws InterruptedException { if (e == null) throw new NullPointerException(); final int c; @@ -379,6 +381,7 @@ public void put(E e) throws InterruptedException { * @throws InterruptedException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException { @@ -417,6 +420,7 @@ public boolean offer(E e, long timeout, TimeUnit unit) * * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { if (e == null) throw new NullPointerException(); final AtomicInteger count = this.count; @@ -441,6 +445,7 @@ public boolean offer(E e) { return true; } + @DoesNotUnrefineReceiver("modifiability") public E take(@GuardSatisfied @CanShrink LinkedBlockingQueue this) throws InterruptedException { final E x; final int c; @@ -463,6 +468,7 @@ public E take(@GuardSatisfied @CanShrink LinkedBlockingQueue this) throws Int return x; } + @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink LinkedBlockingQueue this, long timeout, TimeUnit unit) throws InterruptedException { final E x; final int c; @@ -488,6 +494,7 @@ public E take(@GuardSatisfied @CanShrink LinkedBlockingQueue this) throws Int return x; } + @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink LinkedBlockingQueue this) { final AtomicInteger count = this.count; if (count.get() == 0) @@ -552,6 +559,7 @@ void unlink(Node p, Node pred) { * @param o element to be removed from this queue, if present * @return {@code true} if this queue changed as a result of the call */ + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink LinkedBlockingQueue this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { if (o == null) return false; fullyLock(); @@ -683,6 +691,7 @@ public String toString() { * Atomically removes all of the elements from this queue. * The queue will be empty after this call returns. */ + @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink LinkedBlockingQueue this) { fullyLock(); try { @@ -705,6 +714,7 @@ public void clear(@GuardSatisfied @CanShrink LinkedBlockingQueue this) { * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink LinkedBlockingQueue this, Collection c) { return drainTo(c, Integer.MAX_VALUE); } @@ -715,6 +725,7 @@ public int drainTo(@GuardSatisfied @CanShrink LinkedBlockingQueue this, Colle * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink LinkedBlockingQueue this, Collection c, int maxElements) { Objects.requireNonNull(c); if (c == this) @@ -867,6 +878,7 @@ public void forEachRemaining(Consumer action) { } while (n > 0 && p != null); } + @DoesNotUnrefineReceiver("modifiability") public void remove() { Node p = lastRet; if (p == null) @@ -1040,6 +1052,7 @@ void forEachFrom(Consumer action, Node p) { /** * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink LinkedBlockingQueue this, Predicate filter) { Objects.requireNonNull(filter); return bulkRemove(filter); @@ -1048,6 +1061,7 @@ public boolean removeIf(@CanShrink LinkedBlockingQueue this, Predicate this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> c.contains(e)); @@ -1056,6 +1070,7 @@ public boolean removeAll(@CanShrink LinkedBlockingQueue this, Collection this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> !c.contains(e)); diff --git a/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java b/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java index 2c501cca26064..c21aceedbe8e4 100644 --- a/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java @@ -47,6 +47,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; @@ -941,6 +942,7 @@ public void forEachRemaining(Consumer action) { lastRet = q; } + @DoesNotUnrefineReceiver("modifiability") public final void remove() { final Node lastRet = this.lastRet; if (lastRet == null) @@ -1202,6 +1204,7 @@ public LinkedTransferQueue(Collection c) { * * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public void put(E e) { xfer(e, true, ASYNC, 0L); } @@ -1215,6 +1218,7 @@ public void put(E e) { * {@link BlockingQueue#offer(Object,long,TimeUnit) BlockingQueue.offer}) * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e, long timeout, TimeUnit unit) { xfer(e, true, ASYNC, 0L); return true; @@ -1227,6 +1231,7 @@ public boolean offer(E e, long timeout, TimeUnit unit) { * @return {@code true} (as specified by {@link Queue#offer}) * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { xfer(e, true, ASYNC, 0L); return true; @@ -1241,6 +1246,7 @@ public boolean offer(E e) { * @throws NullPointerException if the specified element is null */ @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { xfer(e, true, ASYNC, 0L); return true; @@ -1256,6 +1262,7 @@ public boolean add(E e) { * * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean tryTransfer(@GuardSatisfied @CanShrink LinkedTransferQueue this, E e) { return xfer(e, true, NOW, 0L) == null; } @@ -1271,6 +1278,7 @@ public boolean tryTransfer(@GuardSatisfied @CanShrink LinkedTransferQueue thi * * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public void transfer(@GuardSatisfied @CanShrink LinkedTransferQueue this, E e) throws InterruptedException { if (xfer(e, true, SYNC, 0L) != null) { Thread.interrupted(); // failure possible only due to interrupt @@ -1292,6 +1300,7 @@ public void transfer(@GuardSatisfied @CanShrink LinkedTransferQueue this, E e * * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean tryTransfer(@GuardSatisfied @CanShrink LinkedTransferQueue this, E e, long timeout, TimeUnit unit) throws InterruptedException { if (xfer(e, true, TIMED, unit.toNanos(timeout)) == null) @@ -1301,6 +1310,7 @@ public boolean tryTransfer(@GuardSatisfied @CanShrink LinkedTransferQueue thi throw new InterruptedException(); } + @DoesNotUnrefineReceiver("modifiability") public E take(@GuardSatisfied @CanShrink LinkedTransferQueue this) throws InterruptedException { E e = xfer(null, false, SYNC, 0L); if (e != null) @@ -1309,6 +1319,7 @@ public E take(@GuardSatisfied @CanShrink LinkedTransferQueue this) throws Int throw new InterruptedException(); } + @DoesNotUnrefineReceiver("modifiability") public E poll(@GuardSatisfied @CanShrink LinkedTransferQueue this, long timeout, TimeUnit unit) throws InterruptedException { E e = xfer(null, false, TIMED, unit.toNanos(timeout)); if (e != null || !Thread.interrupted()) @@ -1316,6 +1327,7 @@ public E poll(@GuardSatisfied @CanShrink LinkedTransferQueue this, long timeo throw new InterruptedException(); } + @DoesNotUnrefineReceiver("modifiability") public E poll(@GuardSatisfied @CanShrink LinkedTransferQueue this) { return xfer(null, false, NOW, 0L); } @@ -1324,6 +1336,7 @@ public E poll(@GuardSatisfied @CanShrink LinkedTransferQueue this) { * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink LinkedTransferQueue this, Collection c) { Objects.requireNonNull(c); if (c == this) @@ -1338,6 +1351,7 @@ public int drainTo(@GuardSatisfied @CanShrink LinkedTransferQueue this, Colle * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink LinkedTransferQueue this, Collection c, int maxElements) { Objects.requireNonNull(c); if (c == this) @@ -1441,6 +1455,7 @@ public int getWaitingConsumerCount() { * @param o element to be removed from this queue, if present * @return {@code true} if this queue changed as a result of the call */ + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink LinkedTransferQueue this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { if (o == null) return false; restartFromHead: for (;;) { @@ -1561,6 +1576,7 @@ private void readObject(java.io.ObjectInputStream s) /** * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink LinkedTransferQueue this, Predicate filter) { Objects.requireNonNull(filter); return bulkRemove(filter); @@ -1569,6 +1585,7 @@ public boolean removeIf(@CanShrink LinkedTransferQueue this, Predicate this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> c.contains(e)); @@ -1577,11 +1594,13 @@ public boolean removeAll(@CanShrink LinkedTransferQueue this, Collection this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> !c.contains(e)); } + @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink LinkedTransferQueue this) { bulkRemove(e -> true); } diff --git a/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java index 44da54e18eaea..39602023380a6 100644 --- a/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java @@ -47,6 +47,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; @@ -463,6 +464,7 @@ private void heapify() { * @throws NullPointerException if the specified element is null */ @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { return offer(e); } @@ -478,6 +480,7 @@ public boolean add(E e) { * priority queue's ordering * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { if (e == null) throw new NullPointerException(); @@ -511,6 +514,7 @@ public boolean offer(E e) { * priority queue's ordering * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public void put(E e) { offer(e); // never need to block } @@ -530,10 +534,12 @@ public void put(E e) { * priority queue's ordering * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e, long timeout, TimeUnit unit) { return offer(e); // never need to block } + @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink PriorityBlockingQueue this) { final ReentrantLock lock = this.lock; lock.lock(); @@ -544,6 +550,7 @@ public boolean offer(E e, long timeout, TimeUnit unit) { } } + @DoesNotUnrefineReceiver("modifiability") public E take(@GuardSatisfied @CanShrink PriorityBlockingQueue this) throws InterruptedException { final ReentrantLock lock = this.lock; lock.lockInterruptibly(); @@ -557,6 +564,7 @@ public E take(@GuardSatisfied @CanShrink PriorityBlockingQueue this) throws I return result; } + @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink PriorityBlockingQueue this, long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); final ReentrantLock lock = this.lock; @@ -662,6 +670,7 @@ private void removeAt(int i) { * @param o element to be removed from this queue, if present * @return {@code true} if this queue changed as a result of the call */ + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink PriorityBlockingQueue this, @Nullable @UnknownSignedness Object o) { final ReentrantLock lock = this.lock; lock.lock(); @@ -727,6 +736,7 @@ public String toString() { * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink PriorityBlockingQueue this, Collection c) { return drainTo(c, Integer.MAX_VALUE); } @@ -737,6 +747,7 @@ public int drainTo(@GuardSatisfied @CanShrink PriorityBlockingQueue this, Col * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink PriorityBlockingQueue this, Collection c, int maxElements) { Objects.requireNonNull(c); if (c == this) @@ -761,6 +772,7 @@ public int drainTo(@GuardSatisfied @CanShrink PriorityBlockingQueue this, Col * Atomically removes all of the elements from this queue. * The queue will be empty after this call returns. */ + @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink PriorityBlockingQueue this) { final ReentrantLock lock = this.lock; lock.lock(); @@ -888,6 +900,7 @@ public E next(@NonEmpty Itr this) { return (E)array[lastRet = cursor++]; } + @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastRet < 0) throw new IllegalStateException(); @@ -1033,6 +1046,7 @@ public Spliterator spliterator() { /** * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink PriorityBlockingQueue this, Predicate filter) { Objects.requireNonNull(filter); return bulkRemove(filter); @@ -1041,6 +1055,7 @@ public boolean removeIf(@CanShrink PriorityBlockingQueue this, Predicate this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> c.contains(e)); @@ -1049,6 +1064,7 @@ public boolean removeAll(@CanShrink PriorityBlockingQueue this, Collection this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> !c.contains(e)); diff --git a/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java b/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java index e29caabac9291..8ef42d917d905 100644 --- a/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java @@ -46,6 +46,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; @@ -849,6 +850,7 @@ public SynchronousQueue(boolean fair) { * @throws InterruptedException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public void put(E e) throws InterruptedException { if (e == null) throw new NullPointerException(); if (transferer.transfer(e, false, 0) == null) { @@ -866,6 +868,7 @@ public void put(E e) throws InterruptedException { * @throws InterruptedException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException { if (e == null) throw new NullPointerException(); @@ -885,6 +888,7 @@ public boolean offer(E e, long timeout, TimeUnit unit) * {@code false} * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { if (e == null) throw new NullPointerException(); return transferer.transfer(e, true, 0) != null; @@ -897,6 +901,7 @@ public boolean offer(E e) { * @return the head of this queue * @throws InterruptedException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public E take(@GuardSatisfied @CanShrink SynchronousQueue this) throws InterruptedException { E e = transferer.transfer(null, false, 0); if (e != null) @@ -914,6 +919,7 @@ public E take(@GuardSatisfied @CanShrink SynchronousQueue this) throws Interr * specified waiting time elapses before an element is present * @throws InterruptedException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public E poll(@GuardSatisfied @CanShrink SynchronousQueue this, long timeout, TimeUnit unit) throws InterruptedException { E e = transferer.transfer(null, true, unit.toNanos(timeout)); if (e != null || !Thread.interrupted()) @@ -928,6 +934,7 @@ public E poll(@GuardSatisfied @CanShrink SynchronousQueue this, long timeout, * @return the head of this queue, or {@code null} if no * element is available */ + @DoesNotUnrefineReceiver("modifiability") public E poll(@GuardSatisfied @CanShrink SynchronousQueue this) { return transferer.transfer(null, true, 0); } @@ -969,6 +976,7 @@ public int remainingCapacity() { * Does nothing. * A {@code SynchronousQueue} has no internal capacity. */ + @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink SynchronousQueue this) { } @@ -992,6 +1000,7 @@ public boolean contains(@GuardSatisfied @Nullable @UnknownSignedness Object o) { * @param o the element to remove * @return {@code false} */ + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink SynchronousQueue this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { return false; } @@ -1015,6 +1024,7 @@ public boolean containsAll(Collection c) { * @param c the collection * @return {@code false} */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(@CanShrink SynchronousQueue this, Collection c) { return false; } @@ -1026,6 +1036,7 @@ public boolean removeAll(@CanShrink SynchronousQueue this, Collection this, Collection c) { return false; } @@ -1103,6 +1114,7 @@ public String toString() { * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink SynchronousQueue this, Collection c) { Objects.requireNonNull(c); if (c == this) @@ -1119,6 +1131,7 @@ public int drainTo(@GuardSatisfied @CanShrink SynchronousQueue this, Collecti * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink SynchronousQueue this, Collection c, int maxElements) { Objects.requireNonNull(c); if (c == this) From f7504357b050efb2cf1f663db7e202ab5ab59e34 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Mon, 18 May 2026 19:14:06 -0700 Subject: [PATCH 02/15] Add more annotations --- .../classes/java/util/AbstractSequentialList.java | 5 +++++ src/java.base/share/classes/java/util/EnumMap.java | 5 +++++ .../share/classes/java/util/PriorityQueue.java | 10 ++++++++++ .../classes/java/util/concurrent/BlockingDeque.java | 1 + .../classes/java/util/concurrent/BlockingQueue.java | 10 ++++++++++ 5 files changed, 31 insertions(+) diff --git a/src/java.base/share/classes/java/util/AbstractSequentialList.java b/src/java.base/share/classes/java/util/AbstractSequentialList.java index 9097f49066f51..bf6d47806003b 100644 --- a/src/java.base/share/classes/java/util/AbstractSequentialList.java +++ b/src/java.base/share/classes/java/util/AbstractSequentialList.java @@ -29,6 +29,7 @@ import org.checkerframework.checker.index.qual.PolyGrowShrink; import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nonempty.qual.PolyNonEmpty; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; @@ -124,6 +125,7 @@ public E get(@GuardSatisfied AbstractSequentialList this, int index) { * @throws IllegalArgumentException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public E set(@GuardSatisfied AbstractSequentialList this, int index, E element) { try { ListIterator e = listIterator(index); @@ -155,6 +157,7 @@ public E set(@GuardSatisfied AbstractSequentialList this, int index, E elemen * @throws IllegalArgumentException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public void add(@GuardSatisfied AbstractSequentialList this, int index, E element) { try { listIterator(index).add(element); @@ -180,6 +183,7 @@ public void add(@GuardSatisfied AbstractSequentialList this, int index, E ele * @throws UnsupportedOperationException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @CanShrink AbstractSequentialList this, int index) { try { ListIterator e = listIterator(index); @@ -223,6 +227,7 @@ public E remove(@GuardSatisfied @CanShrink AbstractSequentialList this, int i * @throws IllegalArgumentException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@GuardSatisfied AbstractSequentialList this, int index, Collection c) { try { boolean modified = false; diff --git a/src/java.base/share/classes/java/util/EnumMap.java b/src/java.base/share/classes/java/util/EnumMap.java index 880386c3749b9..d7fa5e73f22bd 100644 --- a/src/java.base/share/classes/java/util/EnumMap.java +++ b/src/java.base/share/classes/java/util/EnumMap.java @@ -37,6 +37,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.nullness.qual.RequiresNonNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; @@ -286,6 +287,7 @@ private boolean containsMapping(@GuardSatisfied @UnknownSignedness Object key, @ * @throws NullPointerException if the specified key is null */ @EnsuresKeyFor(value={"#1"}, map={"this"}) + @DoesNotUnrefineReceiver("modifiability") public @Nullable V put(K key, V value) { typeCheck(key); @@ -306,6 +308,7 @@ private boolean containsMapping(@GuardSatisfied @UnknownSignedness Object key, @ * return can also indicate that the map previously associated * {@code null} with the specified key.) */ + @DoesNotUnrefineReceiver("modifiability") public @Nullable V remove(@GuardSatisfied @UnknownSignedness Object key) { if (!isValidKey(key)) return null; @@ -358,6 +361,7 @@ private boolean isValidKey(@GuardSatisfied @UnknownSignedness Object key) { "and vals are private class members for EnumMap and are absent in AbstractMap."}) @SuppressWarnings({"nullness:contracts.precondition.override.invalid"}) @RequiresNonNull({"keyUniverse", "vals"}) + @DoesNotUnrefineReceiver("modifiability") public void putAll(@UnknownInitialization EnumMap this, Map m) { if (m instanceof EnumMap em) { if (em.keyType != keyType) { @@ -382,6 +386,7 @@ public void putAll(@UnknownInitialization EnumMap this, Map this, E e) { return offer(e); } @@ -343,6 +345,7 @@ public boolean add(@GuardSatisfied PriorityQueue this, E e) { * according to the priority queue's ordering * @throws NullPointerException if the specified element is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { if (e == null) throw new NullPointerException(); @@ -381,6 +384,7 @@ private int indexOf(@GuardSatisfied @Nullable @UnknownSignedness Object o) { * @param o element to be removed from this queue, if present * @return {@code true} if this queue changed as a result of the call */ + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @CanShrink PriorityQueue this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { int i = indexOf(o); if (i == -1) @@ -593,6 +597,7 @@ public void remove() { * Removes all of the elements from this priority queue. * The queue will be empty after this call returns. */ + @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink PriorityQueue this) { modCount++; final Object[] es = queue; @@ -601,6 +606,7 @@ public void clear(@GuardSatisfied @CanShrink PriorityQueue this) { size = 0; } + @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink PriorityQueue this) { final Object[] es; final E result; @@ -924,6 +930,7 @@ public int characteristics() { /** * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@GuardSatisfied @CanShrink PriorityQueue this, Predicate filter) { Objects.requireNonNull(filter); return bulkRemove(filter); @@ -932,6 +939,7 @@ public boolean removeIf(@GuardSatisfied @CanShrink PriorityQueue this, Predic /** * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(@GuardSatisfied @CanShrink PriorityQueue this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> c.contains(e)); @@ -940,6 +948,7 @@ public boolean removeAll(@GuardSatisfied @CanShrink PriorityQueue this, Colle /** * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(@GuardSatisfied @CanShrink PriorityQueue this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> !c.contains(e)); @@ -995,6 +1004,7 @@ private boolean bulkRemove(Predicate filter) { /** * @throws NullPointerException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") public void forEach(Consumer action) { Objects.requireNonNull(action); final int expectedModCount = modCount; diff --git a/src/java.base/share/classes/java/util/concurrent/BlockingDeque.java b/src/java.base/share/classes/java/util/concurrent/BlockingDeque.java index 81eecd574430a..1bb1c2f974b20 100644 --- a/src/java.base/share/classes/java/util/concurrent/BlockingDeque.java +++ b/src/java.base/share/classes/java/util/concurrent/BlockingDeque.java @@ -45,6 +45,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; diff --git a/src/java.base/share/classes/java/util/concurrent/BlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/BlockingQueue.java index f33a527593edb..a14527eabc2cc 100644 --- a/src/java.base/share/classes/java/util/concurrent/BlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/BlockingQueue.java @@ -43,6 +43,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.framework.qual.AnnotatedFor; @@ -208,6 +209,7 @@ public interface BlockingQueue extends Queue { * element prevents it from being added to this queue */ @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") boolean add(E e); /** @@ -227,6 +229,7 @@ public interface BlockingQueue extends Queue { * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this queue */ + @DoesNotUnrefineReceiver("modifiability") boolean offer(E e); /** @@ -241,6 +244,7 @@ public interface BlockingQueue extends Queue { * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this queue */ + @DoesNotUnrefineReceiver("modifiability") void put(E e) throws InterruptedException; /** @@ -261,6 +265,7 @@ public interface BlockingQueue extends Queue { * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this queue */ + @DoesNotUnrefineReceiver("modifiability") boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException; @@ -271,6 +276,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * @return the head of this queue * @throws InterruptedException if interrupted while waiting */ + @DoesNotUnrefineReceiver("modifiability") E take() throws InterruptedException; /** @@ -285,6 +291,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * specified waiting time elapses before an element is available * @throws InterruptedException if interrupted while waiting */ + @DoesNotUnrefineReceiver("modifiability") @Nullable E poll(long timeout, TimeUnit unit) throws InterruptedException; @@ -319,6 +326,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * @throws NullPointerException if the specified element is null * (optional) */ + @DoesNotUnrefineReceiver("modifiability") boolean remove(@CanShrink BlockingQueue this, @UnknownSignedness Object o); /** @@ -361,6 +369,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * queue, or some property of an element of this queue prevents * it from being added to the specified collection */ + @DoesNotUnrefineReceiver("modifiability") int drainTo(@GuardSatisfied @CanShrink BlockingQueue this, Collection c); /** @@ -386,5 +395,6 @@ boolean offer(E e, long timeout, TimeUnit unit) * queue, or some property of an element of this queue prevents * it from being added to the specified collection */ + @DoesNotUnrefineReceiver("modifiability") int drainTo(@GuardSatisfied @CanShrink BlockingQueue this, Collection c, int maxElements); } From 696ba57528f52cd5501cf09197ed247caac9bf31 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Mon, 18 May 2026 19:38:41 -0700 Subject: [PATCH 03/15] Add annotations, fix imports --- .../java/lang/AbstractStringBuilder.java | 1 + .../share/classes/java/lang/StringBuffer.java | 1 + .../classes/java/lang/StringBuilder.java | 1 + .../classes/java/util/AbstractCollection.java | 2 +- .../share/classes/java/util/AbstractList.java | 2 +- .../share/classes/java/util/AbstractMap.java | 2 +- .../classes/java/util/AbstractQueue.java | 2 +- .../java/util/AbstractSequentialList.java | 2 +- .../share/classes/java/util/AbstractSet.java | 2 +- .../share/classes/java/util/ArrayDeque.java | 2 +- .../share/classes/java/util/ArrayList.java | 2 +- .../share/classes/java/util/Collection.java | 2 +- .../share/classes/java/util/Collections.java | 2 +- .../share/classes/java/util/Deque.java | 2 +- .../share/classes/java/util/EnumMap.java | 2 +- .../share/classes/java/util/EnumSet.java | 2 +- .../share/classes/java/util/HashMap.java | 2 +- .../share/classes/java/util/HashSet.java | 2 +- .../share/classes/java/util/Hashtable.java | 2 +- .../classes/java/util/IdentityHashMap.java | 2 +- .../share/classes/java/util/Iterator.java | 2 +- .../share/classes/java/util/JumboEnumSet.java | 2 +- .../classes/java/util/LinkedHashMap.java | 2 +- .../classes/java/util/LinkedHashSet.java | 2 +- .../share/classes/java/util/LinkedList.java | 2 +- .../share/classes/java/util/List.java | 2 +- .../share/classes/java/util/ListIterator.java | 2 +- .../share/classes/java/util/Map.java | 2 +- .../share/classes/java/util/NavigableMap.java | 2 +- .../share/classes/java/util/NavigableSet.java | 2 +- .../classes/java/util/PrimitiveIterator.java | 2 +- .../classes/java/util/PriorityQueue.java | 2 +- .../share/classes/java/util/Properties.java | 2 +- .../share/classes/java/util/Queue.java | 2 +- .../classes/java/util/RegularEnumSet.java | 2 +- .../java/util/SequencedCollection.java | 2 +- .../share/classes/java/util/SequencedMap.java | 2 +- .../share/classes/java/util/SequencedSet.java | 2 +- .../share/classes/java/util/Set.java | 2 +- .../share/classes/java/util/SortedMap.java | 2 +- .../share/classes/java/util/SortedSet.java | 2 +- .../share/classes/java/util/Stack.java | 2 +- .../share/classes/java/util/TreeMap.java | 2 +- .../share/classes/java/util/TreeSet.java | 2 +- .../share/classes/java/util/Vector.java | 2 +- .../share/classes/java/util/WeakHashMap.java | 2 +- .../util/concurrent/ArrayBlockingQueue.java | 2 +- .../java/util/concurrent/BlockingDeque.java | 28 ++++++++++++++++++- .../java/util/concurrent/BlockingQueue.java | 2 +- .../util/concurrent/ConcurrentHashMap.java | 2 +- .../concurrent/ConcurrentLinkedDeque.java | 2 +- .../concurrent/ConcurrentLinkedQueue.java | 2 +- .../java/util/concurrent/ConcurrentMap.java | 1 + .../concurrent/ConcurrentSkipListMap.java | 2 +- .../concurrent/ConcurrentSkipListSet.java | 2 +- .../util/concurrent/CopyOnWriteArrayList.java | 2 +- .../util/concurrent/CopyOnWriteArraySet.java | 2 +- .../java/util/concurrent/DelayQueue.java | 2 +- .../util/concurrent/LinkedBlockingDeque.java | 2 +- .../util/concurrent/LinkedBlockingQueue.java | 2 +- .../util/concurrent/LinkedTransferQueue.java | 2 +- .../concurrent/PriorityBlockingQueue.java | 2 +- .../util/concurrent/SynchronousQueue.java | 2 +- 63 files changed, 89 insertions(+), 59 deletions(-) diff --git a/src/java.base/share/classes/java/lang/AbstractStringBuilder.java b/src/java.base/share/classes/java/lang/AbstractStringBuilder.java index e862852c7dbc4..958daaf01dc16 100644 --- a/src/java.base/share/classes/java/lang/AbstractStringBuilder.java +++ b/src/java.base/share/classes/java/lang/AbstractStringBuilder.java @@ -33,6 +33,7 @@ import org.checkerframework.checker.interning.qual.UsesObjectEquals; import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/lang/StringBuffer.java b/src/java.base/share/classes/java/lang/StringBuffer.java index eddd4aa36513a..163eee363856f 100644 --- a/src/java.base/share/classes/java/lang/StringBuffer.java +++ b/src/java.base/share/classes/java/lang/StringBuffer.java @@ -33,6 +33,7 @@ import org.checkerframework.common.aliasing.qual.LeakedToResult; import org.checkerframework.common.aliasing.qual.NonLeaked; import org.checkerframework.common.aliasing.qual.Unique; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/lang/StringBuilder.java b/src/java.base/share/classes/java/lang/StringBuilder.java index 6c17308dfdbc9..78d5000b1f87b 100644 --- a/src/java.base/share/classes/java/lang/StringBuilder.java +++ b/src/java.base/share/classes/java/lang/StringBuilder.java @@ -32,6 +32,7 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.regex.qual.PolyRegex; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/AbstractCollection.java b/src/java.base/share/classes/java/util/AbstractCollection.java index 11a4724781b54..5a67a347ba449 100644 --- a/src/java.base/share/classes/java/util/AbstractCollection.java +++ b/src/java.base/share/classes/java/util/AbstractCollection.java @@ -35,7 +35,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; diff --git a/src/java.base/share/classes/java/util/AbstractList.java b/src/java.base/share/classes/java/util/AbstractList.java index 552ac7bdd81ab..8a7588b68a2de 100644 --- a/src/java.base/share/classes/java/util/AbstractList.java +++ b/src/java.base/share/classes/java/util/AbstractList.java @@ -37,7 +37,7 @@ import org.checkerframework.checker.nonempty.qual.PolyNonEmpty; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/AbstractMap.java b/src/java.base/share/classes/java/util/AbstractMap.java index 6cfcfe86cbcd2..b5775777d5b08 100644 --- a/src/java.base/share/classes/java/util/AbstractMap.java +++ b/src/java.base/share/classes/java/util/AbstractMap.java @@ -35,7 +35,7 @@ import org.checkerframework.checker.nullness.qual.KeyFor; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/AbstractQueue.java b/src/java.base/share/classes/java/util/AbstractQueue.java index 8870a514949cc..8afc291dcb068 100644 --- a/src/java.base/share/classes/java/util/AbstractQueue.java +++ b/src/java.base/share/classes/java/util/AbstractQueue.java @@ -39,7 +39,7 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nonempty.qual.EnsuresNonEmpty; import org.checkerframework.checker.nonempty.qual.NonEmpty; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.framework.qual.AnnotatedFor; /** diff --git a/src/java.base/share/classes/java/util/AbstractSequentialList.java b/src/java.base/share/classes/java/util/AbstractSequentialList.java index bf6d47806003b..1a00705398f3d 100644 --- a/src/java.base/share/classes/java/util/AbstractSequentialList.java +++ b/src/java.base/share/classes/java/util/AbstractSequentialList.java @@ -29,7 +29,7 @@ import org.checkerframework.checker.index.qual.PolyGrowShrink; import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nonempty.qual.PolyNonEmpty; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; diff --git a/src/java.base/share/classes/java/util/AbstractSet.java b/src/java.base/share/classes/java/util/AbstractSet.java index 5ba0ab38ee047..3438244dd7a31 100644 --- a/src/java.base/share/classes/java/util/AbstractSet.java +++ b/src/java.base/share/classes/java/util/AbstractSet.java @@ -28,7 +28,7 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; diff --git a/src/java.base/share/classes/java/util/ArrayDeque.java b/src/java.base/share/classes/java/util/ArrayDeque.java index ed41a5775dd00..e5cf586d5fe57 100644 --- a/src/java.base/share/classes/java/util/ArrayDeque.java +++ b/src/java.base/share/classes/java/util/ArrayDeque.java @@ -48,7 +48,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/ArrayList.java b/src/java.base/share/classes/java/util/ArrayList.java index 5e70be7c83155..2bcf080a16129 100644 --- a/src/java.base/share/classes/java/util/ArrayList.java +++ b/src/java.base/share/classes/java/util/ArrayList.java @@ -40,7 +40,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/Collection.java b/src/java.base/share/classes/java/util/Collection.java index d9bd2148d82e2..ec63a3537ca0e 100644 --- a/src/java.base/share/classes/java/util/Collection.java +++ b/src/java.base/share/classes/java/util/Collection.java @@ -37,7 +37,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; diff --git a/src/java.base/share/classes/java/util/Collections.java b/src/java.base/share/classes/java/util/Collections.java index cd71f55ed133a..4b35085b4f7b7 100644 --- a/src/java.base/share/classes/java/util/Collections.java +++ b/src/java.base/share/classes/java/util/Collections.java @@ -43,7 +43,7 @@ import org.checkerframework.common.value.qual.ArrayLen; import org.checkerframework.common.value.qual.MinLen; import org.checkerframework.common.value.qual.StaticallyExecutable; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/Deque.java b/src/java.base/share/classes/java/util/Deque.java index 3873b8414a903..2ff8351cdd270 100644 --- a/src/java.base/share/classes/java/util/Deque.java +++ b/src/java.base/share/classes/java/util/Deque.java @@ -45,7 +45,7 @@ import org.checkerframework.checker.nonempty.qual.PolyNonEmpty; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; diff --git a/src/java.base/share/classes/java/util/EnumMap.java b/src/java.base/share/classes/java/util/EnumMap.java index d7fa5e73f22bd..50baf7d331930 100644 --- a/src/java.base/share/classes/java/util/EnumMap.java +++ b/src/java.base/share/classes/java/util/EnumMap.java @@ -37,7 +37,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.nullness.qual.RequiresNonNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; diff --git a/src/java.base/share/classes/java/util/EnumSet.java b/src/java.base/share/classes/java/util/EnumSet.java index 14c2c2ee396e5..1abbfa1b40db5 100644 --- a/src/java.base/share/classes/java/util/EnumSet.java +++ b/src/java.base/share/classes/java/util/EnumSet.java @@ -26,7 +26,7 @@ package java.util; import org.checkerframework.checker.nullness.qual.Nullable; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.framework.qual.AnnotatedFor; import jdk.internal.access.SharedSecrets; diff --git a/src/java.base/share/classes/java/util/HashMap.java b/src/java.base/share/classes/java/util/HashMap.java index 71646a33cf2d2..20d58faf38ab2 100644 --- a/src/java.base/share/classes/java/util/HashMap.java +++ b/src/java.base/share/classes/java/util/HashMap.java @@ -37,7 +37,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/HashSet.java b/src/java.base/share/classes/java/util/HashSet.java index c87fca402347a..b7e766bc732d3 100644 --- a/src/java.base/share/classes/java/util/HashSet.java +++ b/src/java.base/share/classes/java/util/HashSet.java @@ -35,7 +35,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/Hashtable.java b/src/java.base/share/classes/java/util/Hashtable.java index a46dabf6df1b2..842476fd4b437 100644 --- a/src/java.base/share/classes/java/util/Hashtable.java +++ b/src/java.base/share/classes/java/util/Hashtable.java @@ -37,7 +37,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/IdentityHashMap.java b/src/java.base/share/classes/java/util/IdentityHashMap.java index c008bcc8bb161..0b21d12952b82 100644 --- a/src/java.base/share/classes/java/util/IdentityHashMap.java +++ b/src/java.base/share/classes/java/util/IdentityHashMap.java @@ -35,7 +35,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/Iterator.java b/src/java.base/share/classes/java/util/Iterator.java index 37cd9bbda450b..baa55eeb009b2 100644 --- a/src/java.base/share/classes/java/util/Iterator.java +++ b/src/java.base/share/classes/java/util/Iterator.java @@ -29,7 +29,7 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf; import org.checkerframework.checker.nonempty.qual.NonEmpty; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; diff --git a/src/java.base/share/classes/java/util/JumboEnumSet.java b/src/java.base/share/classes/java/util/JumboEnumSet.java index 72dc66eb20723..21c9a851b21a0 100644 --- a/src/java.base/share/classes/java/util/JumboEnumSet.java +++ b/src/java.base/share/classes/java/util/JumboEnumSet.java @@ -35,7 +35,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/LinkedHashMap.java b/src/java.base/share/classes/java/util/LinkedHashMap.java index 3175d39c8363a..20459d97a5293 100644 --- a/src/java.base/share/classes/java/util/LinkedHashMap.java +++ b/src/java.base/share/classes/java/util/LinkedHashMap.java @@ -34,7 +34,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/LinkedHashSet.java b/src/java.base/share/classes/java/util/LinkedHashSet.java index c2e6a9c921681..24415b0ec9215 100644 --- a/src/java.base/share/classes/java/util/LinkedHashSet.java +++ b/src/java.base/share/classes/java/util/LinkedHashSet.java @@ -26,7 +26,7 @@ package java.util; import org.checkerframework.dataflow.qual.Deterministic; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; diff --git a/src/java.base/share/classes/java/util/LinkedList.java b/src/java.base/share/classes/java/util/LinkedList.java index 8aa098df3e0e5..bb1111520f015 100644 --- a/src/java.base/share/classes/java/util/LinkedList.java +++ b/src/java.base/share/classes/java/util/LinkedList.java @@ -39,7 +39,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/List.java b/src/java.base/share/classes/java/util/List.java index c5c6bcd21fb5a..9e59d0d3ad704 100644 --- a/src/java.base/share/classes/java/util/List.java +++ b/src/java.base/share/classes/java/util/List.java @@ -41,7 +41,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/ListIterator.java b/src/java.base/share/classes/java/util/ListIterator.java index ced399a07a776..e2b3c8bf01e73 100644 --- a/src/java.base/share/classes/java/util/ListIterator.java +++ b/src/java.base/share/classes/java/util/ListIterator.java @@ -30,7 +30,7 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf; import org.checkerframework.checker.nonempty.qual.NonEmpty; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; diff --git a/src/java.base/share/classes/java/util/Map.java b/src/java.base/share/classes/java/util/Map.java index 350808ebc3bba..1d6c6261cf101 100644 --- a/src/java.base/share/classes/java/util/Map.java +++ b/src/java.base/share/classes/java/util/Map.java @@ -40,7 +40,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; import org.checkerframework.common.aliasing.qual.NonLeaked; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; diff --git a/src/java.base/share/classes/java/util/NavigableMap.java b/src/java.base/share/classes/java/util/NavigableMap.java index 8087a679af9fe..44e774ffac482 100644 --- a/src/java.base/share/classes/java/util/NavigableMap.java +++ b/src/java.base/share/classes/java/util/NavigableMap.java @@ -38,7 +38,7 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nullness.qual.KeyFor; import org.checkerframework.checker.nullness.qual.Nullable; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; diff --git a/src/java.base/share/classes/java/util/NavigableSet.java b/src/java.base/share/classes/java/util/NavigableSet.java index 71b5d7cf52e44..9a16eb7eaf837 100644 --- a/src/java.base/share/classes/java/util/NavigableSet.java +++ b/src/java.base/share/classes/java/util/NavigableSet.java @@ -39,7 +39,7 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nonempty.qual.PolyNonEmpty; import org.checkerframework.checker.nullness.qual.Nullable; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; diff --git a/src/java.base/share/classes/java/util/PrimitiveIterator.java b/src/java.base/share/classes/java/util/PrimitiveIterator.java index 150564d3774a4..5536b06b2c73c 100644 --- a/src/java.base/share/classes/java/util/PrimitiveIterator.java +++ b/src/java.base/share/classes/java/util/PrimitiveIterator.java @@ -26,7 +26,7 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nonempty.qual.NonEmpty; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.framework.qual.AnnotatedFor; import java.util.function.Consumer; diff --git a/src/java.base/share/classes/java/util/PriorityQueue.java b/src/java.base/share/classes/java/util/PriorityQueue.java index 971ef1404bf23..457babafd3556 100644 --- a/src/java.base/share/classes/java/util/PriorityQueue.java +++ b/src/java.base/share/classes/java/util/PriorityQueue.java @@ -39,7 +39,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/Properties.java b/src/java.base/share/classes/java/util/Properties.java index fe980b59d49b4..b492991de4c30 100644 --- a/src/java.base/share/classes/java/util/Properties.java +++ b/src/java.base/share/classes/java/util/Properties.java @@ -32,7 +32,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.propkey.qual.PropertyKey; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; diff --git a/src/java.base/share/classes/java/util/Queue.java b/src/java.base/share/classes/java/util/Queue.java index e04f0c2118afa..d4f567a30282b 100644 --- a/src/java.base/share/classes/java/util/Queue.java +++ b/src/java.base/share/classes/java/util/Queue.java @@ -41,7 +41,7 @@ import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf; import org.checkerframework.checker.nonempty.qual.NonEmpty; import org.checkerframework.checker.nullness.qual.Nullable; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; diff --git a/src/java.base/share/classes/java/util/RegularEnumSet.java b/src/java.base/share/classes/java/util/RegularEnumSet.java index 9b5a5e2dddaf4..0fe13bdab68c0 100644 --- a/src/java.base/share/classes/java/util/RegularEnumSet.java +++ b/src/java.base/share/classes/java/util/RegularEnumSet.java @@ -36,7 +36,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/SequencedCollection.java b/src/java.base/share/classes/java/util/SequencedCollection.java index 40e77acb7b385..2e7c94dc442eb 100644 --- a/src/java.base/share/classes/java/util/SequencedCollection.java +++ b/src/java.base/share/classes/java/util/SequencedCollection.java @@ -25,7 +25,7 @@ package java.util; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; /** * A collection that has a well-defined encounter order, that supports operations at both ends, diff --git a/src/java.base/share/classes/java/util/SequencedMap.java b/src/java.base/share/classes/java/util/SequencedMap.java index d7bf9703ad57f..9881328c6db35 100644 --- a/src/java.base/share/classes/java/util/SequencedMap.java +++ b/src/java.base/share/classes/java/util/SequencedMap.java @@ -25,7 +25,7 @@ package java.util; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import jdk.internal.util.NullableKeyValueHolder; diff --git a/src/java.base/share/classes/java/util/SequencedSet.java b/src/java.base/share/classes/java/util/SequencedSet.java index d4bac4cd6747d..c4fa139e9e418 100644 --- a/src/java.base/share/classes/java/util/SequencedSet.java +++ b/src/java.base/share/classes/java/util/SequencedSet.java @@ -25,7 +25,7 @@ package java.util; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; /** * A collection that is both a {@link SequencedCollection} and a {@link Set}. As such, diff --git a/src/java.base/share/classes/java/util/Set.java b/src/java.base/share/classes/java/util/Set.java index 713a75e0a7a5b..4e0953c500b27 100644 --- a/src/java.base/share/classes/java/util/Set.java +++ b/src/java.base/share/classes/java/util/Set.java @@ -36,7 +36,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; diff --git a/src/java.base/share/classes/java/util/SortedMap.java b/src/java.base/share/classes/java/util/SortedMap.java index 244e864a1bcd7..706bc2fd501b4 100644 --- a/src/java.base/share/classes/java/util/SortedMap.java +++ b/src/java.base/share/classes/java/util/SortedMap.java @@ -29,7 +29,7 @@ import org.checkerframework.checker.nonempty.qual.NonEmpty; import org.checkerframework.checker.nullness.qual.KeyFor; import org.checkerframework.checker.nullness.qual.Nullable; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; diff --git a/src/java.base/share/classes/java/util/SortedSet.java b/src/java.base/share/classes/java/util/SortedSet.java index 071cfa146d1c1..eb8dfa734365e 100644 --- a/src/java.base/share/classes/java/util/SortedSet.java +++ b/src/java.base/share/classes/java/util/SortedSet.java @@ -28,7 +28,7 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nonempty.qual.NonEmpty; import org.checkerframework.checker.nullness.qual.Nullable; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; diff --git a/src/java.base/share/classes/java/util/Stack.java b/src/java.base/share/classes/java/util/Stack.java index 51008d83a3417..f8d3256a08adc 100644 --- a/src/java.base/share/classes/java/util/Stack.java +++ b/src/java.base/share/classes/java/util/Stack.java @@ -29,7 +29,7 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf; import org.checkerframework.checker.nonempty.qual.NonEmpty; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; diff --git a/src/java.base/share/classes/java/util/TreeMap.java b/src/java.base/share/classes/java/util/TreeMap.java index c0229972f73b0..4a19071d4d528 100644 --- a/src/java.base/share/classes/java/util/TreeMap.java +++ b/src/java.base/share/classes/java/util/TreeMap.java @@ -36,7 +36,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/TreeSet.java b/src/java.base/share/classes/java/util/TreeSet.java index 37386cac38e44..d9f6109f653fd 100644 --- a/src/java.base/share/classes/java/util/TreeSet.java +++ b/src/java.base/share/classes/java/util/TreeSet.java @@ -35,7 +35,7 @@ import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; diff --git a/src/java.base/share/classes/java/util/Vector.java b/src/java.base/share/classes/java/util/Vector.java index 56f18e8dbc58b..3dc8ec166d3af 100644 --- a/src/java.base/share/classes/java/util/Vector.java +++ b/src/java.base/share/classes/java/util/Vector.java @@ -38,7 +38,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/WeakHashMap.java b/src/java.base/share/classes/java/util/WeakHashMap.java index 1a4dddae10bf5..e97c0c6c26c14 100644 --- a/src/java.base/share/classes/java/util/WeakHashMap.java +++ b/src/java.base/share/classes/java/util/WeakHashMap.java @@ -36,7 +36,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java index d468f56ef8743..1500522d97dc9 100644 --- a/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java @@ -47,7 +47,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; diff --git a/src/java.base/share/classes/java/util/concurrent/BlockingDeque.java b/src/java.base/share/classes/java/util/concurrent/BlockingDeque.java index 1bb1c2f974b20..914985bf9b4a1 100644 --- a/src/java.base/share/classes/java/util/concurrent/BlockingDeque.java +++ b/src/java.base/share/classes/java/util/concurrent/BlockingDeque.java @@ -45,7 +45,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; @@ -232,6 +232,7 @@ public interface BlockingDeque extends BlockingQueue< * @throws NullPointerException if the specified element is null * @throws IllegalArgumentException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") void addFirst(E e); /** @@ -247,6 +248,7 @@ public interface BlockingDeque extends BlockingQueue< * @throws NullPointerException if the specified element is null * @throws IllegalArgumentException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") void addLast(E e); /** @@ -263,6 +265,7 @@ public interface BlockingDeque extends BlockingQueue< * @throws NullPointerException if the specified element is null * @throws IllegalArgumentException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") boolean offerFirst(E e); /** @@ -279,6 +282,7 @@ public interface BlockingDeque extends BlockingQueue< * @throws NullPointerException if the specified element is null * @throws IllegalArgumentException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") boolean offerLast(E e); /** @@ -293,6 +297,7 @@ public interface BlockingDeque extends BlockingQueue< * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ + @DoesNotUnrefineReceiver("modifiability") void putFirst(E e) throws InterruptedException; /** @@ -307,6 +312,7 @@ public interface BlockingDeque extends BlockingQueue< * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ + @DoesNotUnrefineReceiver("modifiability") void putLast(E e) throws InterruptedException; /** @@ -328,6 +334,7 @@ public interface BlockingDeque extends BlockingQueue< * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ + @DoesNotUnrefineReceiver("modifiability") boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException; @@ -350,6 +357,7 @@ boolean offerFirst(E e, long timeout, TimeUnit unit) * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ + @DoesNotUnrefineReceiver("modifiability") boolean offerLast(E e, long timeout, TimeUnit unit) throws InterruptedException; @@ -360,6 +368,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * @return the head of this deque * @throws InterruptedException if interrupted while waiting */ + @DoesNotUnrefineReceiver("modifiability") E takeFirst(@CanShrink BlockingDeque this) throws InterruptedException; /** @@ -369,6 +378,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * @return the tail of this deque * @throws InterruptedException if interrupted while waiting */ + @DoesNotUnrefineReceiver("modifiability") E takeLast(@CanShrink BlockingDeque this) throws InterruptedException; /** @@ -384,6 +394,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * waiting time elapses before an element is available * @throws InterruptedException if interrupted while waiting */ + @DoesNotUnrefineReceiver("modifiability") @Nullable E pollFirst(@CanShrink BlockingDeque this, long timeout, TimeUnit unit) throws InterruptedException; @@ -400,6 +411,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * waiting time elapses before an element is available * @throws InterruptedException if interrupted while waiting */ + @DoesNotUnrefineReceiver("modifiability") @Nullable E pollLast(@CanShrink BlockingDeque this, long timeout, TimeUnit unit) throws InterruptedException; @@ -419,6 +431,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * @throws NullPointerException if the specified element is null * (optional) */ + @DoesNotUnrefineReceiver("modifiability") boolean removeFirstOccurrence(@CanShrink BlockingDeque this, Object o); /** @@ -437,6 +450,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * @throws NullPointerException if the specified element is null * (optional) */ + @DoesNotUnrefineReceiver("modifiability") boolean removeLastOccurrence(@CanShrink BlockingDeque this, Object o); // *** BlockingQueue methods *** @@ -460,6 +474,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ + @DoesNotUnrefineReceiver("modifiability") @EnsuresNonEmpty("this") boolean add(E e); @@ -481,6 +496,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ + @DoesNotUnrefineReceiver("modifiability") boolean offer(E e); /** @@ -498,6 +514,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ + @DoesNotUnrefineReceiver("modifiability") void put(E e) throws InterruptedException; /** @@ -518,6 +535,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ + @DoesNotUnrefineReceiver("modifiability") boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException; @@ -532,6 +550,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * @return the head of the queue represented by this deque * @throws NoSuchElementException if this deque is empty */ + @DoesNotUnrefineReceiver("modifiability") E remove(@GuardSatisfied @NonEmpty @CanShrink BlockingDeque this); /** @@ -543,6 +562,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * * @return the head of this deque, or {@code null} if this deque is empty */ + @DoesNotUnrefineReceiver("modifiability") @Nullable E poll(@CanShrink BlockingDeque this); /** @@ -555,6 +575,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * @return the head of this deque * @throws InterruptedException if interrupted while waiting */ + @DoesNotUnrefineReceiver("modifiability") E take(@CanShrink BlockingDeque this) throws InterruptedException; /** @@ -569,6 +590,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * specified waiting time elapses before an element is available * @throws InterruptedException if interrupted while waiting */ + @DoesNotUnrefineReceiver("modifiability") @Nullable E poll(@CanShrink BlockingDeque this, long timeout, TimeUnit unit) throws InterruptedException; @@ -583,6 +605,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * @return the head of this deque * @throws NoSuchElementException if this deque is empty */ + @Pure E element(@NonEmpty BlockingDeque this); /** @@ -594,6 +617,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * * @return the head of this deque, or {@code null} if this deque is empty */ + @Pure @Nullable E peek(); /** @@ -615,6 +639,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * @throws NullPointerException if the specified element is null * (optional) */ + @DoesNotUnrefineReceiver("modifiability") boolean remove(@CanShrink BlockingDeque this, @UnknownSignedness Object o); /** @@ -666,5 +691,6 @@ boolean offer(E e, long timeout, TimeUnit unit) * @throws NullPointerException if the specified element is null * @throws IllegalArgumentException {@inheritDoc} */ + @DoesNotUnrefineReceiver("modifiability") void push(E e); } diff --git a/src/java.base/share/classes/java/util/concurrent/BlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/BlockingQueue.java index a14527eabc2cc..76a8d29b5a1c9 100644 --- a/src/java.base/share/classes/java/util/concurrent/BlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/BlockingQueue.java @@ -43,7 +43,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.framework.qual.AnnotatedFor; diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java index 2303a0578076a..5a17333b2e671 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java @@ -48,7 +48,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java index ba68e9406fb99..60e763281b85c 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java @@ -48,7 +48,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java index e51cb0e6a989f..eabba33e783fe 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java @@ -47,7 +47,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentMap.java index 018492522c1a4..0a05f7aad2b85 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentMap.java @@ -40,6 +40,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.PolyNull; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.framework.qual.AnnotatedFor; diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java index 9a400a014e248..c477c5e819da8 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java @@ -44,7 +44,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java index 6a90b130ae0f5..eaf6fccb55253 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java @@ -45,7 +45,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; diff --git a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java index 4c6d6260bcbea..4809969f14b02 100644 --- a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java +++ b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java @@ -47,7 +47,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java index c8ac6fa4ac538..236a7855275bd 100644 --- a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java +++ b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java @@ -47,7 +47,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; diff --git a/src/java.base/share/classes/java/util/concurrent/DelayQueue.java b/src/java.base/share/classes/java/util/concurrent/DelayQueue.java index ecf6e19e6501f..b4d263d97f0b3 100644 --- a/src/java.base/share/classes/java/util/concurrent/DelayQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/DelayQueue.java @@ -43,7 +43,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java index 60e15e79c35b9..686521594f7d2 100644 --- a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java +++ b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java @@ -47,7 +47,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; diff --git a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java index 07f803be79da4..1b2ffa1766d1c 100644 --- a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java @@ -46,7 +46,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; diff --git a/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java b/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java index c21aceedbe8e4..592377b9775e2 100644 --- a/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java @@ -47,7 +47,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java index 39602023380a6..6e23f869ab209 100644 --- a/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java @@ -47,7 +47,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; diff --git a/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java b/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java index 8ef42d917d905..fc43091c127dd 100644 --- a/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java @@ -46,7 +46,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.dataflow.qual.DoesNotUnrefineReceiver; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; From cf6c94d868a19a35ca7b9ea182f2a44989491248 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 19 May 2026 08:12:44 -0700 Subject: [PATCH 04/15] Checkpoint --- .../share/classes/java/io/BufferedReader.java | 2 ++ .../share/classes/java/lang/AbstractStringBuilder.java | 1 - .../share/classes/java/lang/CharSequence.java | 3 +++ .../share/classes/java/lang/StringBuffer.java | 1 - .../share/classes/java/lang/StringBuilder.java | 1 - .../java/lang/invoke/AbstractConstantGroup.java | 2 ++ src/java.base/share/classes/java/net/URL.java | 2 ++ .../share/classes/java/nio/charset/Charset.java | 2 ++ .../share/classes/java/nio/file/FileTreeIterator.java | 2 ++ src/java.base/share/classes/java/nio/file/Files.java | 2 ++ src/java.base/share/classes/java/nio/file/Path.java | 2 ++ src/java.base/share/classes/java/util/Arrays.java | 2 ++ src/java.base/share/classes/java/util/Enumeration.java | 2 ++ .../share/classes/java/util/ImmutableCollections.java | 5 +++++ .../share/classes/java/util/ServiceLoader.java | 5 +++++ .../share/classes/java/util/Spliterators.java | 5 +++++ .../classes/java/util/concurrent/ConcurrentMap.java | 10 ++++++++++ .../util/concurrent/ScheduledThreadPoolExecutor.java | 2 ++ .../share/classes/java/util/regex/Matcher.java | 2 ++ .../share/classes/java/util/regex/Pattern.java | 2 ++ src/java.base/share/classes/java/util/zip/ZipFile.java | 3 +++ 21 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/java.base/share/classes/java/io/BufferedReader.java b/src/java.base/share/classes/java/io/BufferedReader.java index 54985d9826ece..41f6de0853dd0 100644 --- a/src/java.base/share/classes/java/io/BufferedReader.java +++ b/src/java.base/share/classes/java/io/BufferedReader.java @@ -40,6 +40,7 @@ import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.Iterator; import java.util.NoSuchElementException; @@ -709,6 +710,7 @@ public boolean hasNext() { @Override @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public String next(/*@NonEmpty Iterator this*/) { if (nextLine != null || hasNext()) { String line = nextLine; diff --git a/src/java.base/share/classes/java/lang/AbstractStringBuilder.java b/src/java.base/share/classes/java/lang/AbstractStringBuilder.java index 958daaf01dc16..e862852c7dbc4 100644 --- a/src/java.base/share/classes/java/lang/AbstractStringBuilder.java +++ b/src/java.base/share/classes/java/lang/AbstractStringBuilder.java @@ -33,7 +33,6 @@ import org.checkerframework.checker.interning.qual.UsesObjectEquals; import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nullness.qual.Nullable; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/lang/CharSequence.java b/src/java.base/share/classes/java/lang/CharSequence.java index e79f030b6edd6..9850955c2037a 100644 --- a/src/java.base/share/classes/java/lang/CharSequence.java +++ b/src/java.base/share/classes/java/lang/CharSequence.java @@ -36,6 +36,7 @@ import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.NoSuchElementException; import java.util.Objects; @@ -175,6 +176,7 @@ public boolean hasNext() { } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public int nextInt(@NonEmpty CharIterator this) { if (hasNext()) { return charAt(cur++); @@ -252,6 +254,7 @@ public boolean hasNext() { } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public int nextInt(@NonEmpty CodePointIterator this) { final int length = length(); diff --git a/src/java.base/share/classes/java/lang/StringBuffer.java b/src/java.base/share/classes/java/lang/StringBuffer.java index 163eee363856f..eddd4aa36513a 100644 --- a/src/java.base/share/classes/java/lang/StringBuffer.java +++ b/src/java.base/share/classes/java/lang/StringBuffer.java @@ -33,7 +33,6 @@ import org.checkerframework.common.aliasing.qual.LeakedToResult; import org.checkerframework.common.aliasing.qual.NonLeaked; import org.checkerframework.common.aliasing.qual.Unique; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/lang/StringBuilder.java b/src/java.base/share/classes/java/lang/StringBuilder.java index 78d5000b1f87b..6c17308dfdbc9 100644 --- a/src/java.base/share/classes/java/lang/StringBuilder.java +++ b/src/java.base/share/classes/java/lang/StringBuilder.java @@ -32,7 +32,6 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.regex.qual.PolyRegex; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; diff --git a/src/java.base/share/classes/java/lang/invoke/AbstractConstantGroup.java b/src/java.base/share/classes/java/lang/invoke/AbstractConstantGroup.java index 1863d17c0821b..674838eca05be 100644 --- a/src/java.base/share/classes/java/lang/invoke/AbstractConstantGroup.java +++ b/src/java.base/share/classes/java/lang/invoke/AbstractConstantGroup.java @@ -29,6 +29,7 @@ import org.checkerframework.checker.nonempty.qual.NonEmpty; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.*; import jdk.internal.vm.annotation.Stable; @@ -101,6 +102,7 @@ public boolean hasNext() { @Override @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public Object next(@NonEmpty AsIterator this) { int i = bumpIndex(); if (resolving) diff --git a/src/java.base/share/classes/java/net/URL.java b/src/java.base/share/classes/java/net/URL.java index 56c7f6c8496e4..7519c017ba9aa 100644 --- a/src/java.base/share/classes/java/net/URL.java +++ b/src/java.base/share/classes/java/net/URL.java @@ -35,6 +35,7 @@ import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.io.File; import java.io.IOException; @@ -1513,6 +1514,7 @@ public boolean hasNext() { } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public URLStreamHandlerProvider next(/*@NonEmpty Iterator this*/) { if (!getNext()) throw new NoSuchElementException(); diff --git a/src/java.base/share/classes/java/nio/charset/Charset.java b/src/java.base/share/classes/java/nio/charset/Charset.java index 5cb2e1a6dfc7d..3a518470c51b6 100644 --- a/src/java.base/share/classes/java/nio/charset/Charset.java +++ b/src/java.base/share/classes/java/nio/charset/Charset.java @@ -29,6 +29,7 @@ import org.checkerframework.checker.nonempty.qual.NonEmpty; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import jdk.internal.misc.ThreadTracker; import jdk.internal.misc.VM; @@ -371,6 +372,7 @@ public boolean hasNext() { } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public CharsetProvider next(/*@NonEmpty Iterator this*/) { if (!getNext()) throw new NoSuchElementException(); diff --git a/src/java.base/share/classes/java/nio/file/FileTreeIterator.java b/src/java.base/share/classes/java/nio/file/FileTreeIterator.java index 1015bb8f2c1a2..c8675e2d16b1d 100644 --- a/src/java.base/share/classes/java/nio/file/FileTreeIterator.java +++ b/src/java.base/share/classes/java/nio/file/FileTreeIterator.java @@ -29,6 +29,7 @@ import org.checkerframework.checker.nonempty.qual.NonEmpty; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.io.Closeable; import java.io.IOException; @@ -113,6 +114,7 @@ public boolean hasNext() { @Override @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public Event next(@NonEmpty FileTreeIterator this) { if (!walker.isOpen()) throw new IllegalStateException(); diff --git a/src/java.base/share/classes/java/nio/file/Files.java b/src/java.base/share/classes/java/nio/file/Files.java index b0ff3926bcbd1..be49e03ea0b7c 100644 --- a/src/java.base/share/classes/java/nio/file/Files.java +++ b/src/java.base/share/classes/java/nio/file/Files.java @@ -35,6 +35,7 @@ import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.checker.nullness.qual.Nullable; import java.io.BufferedReader; @@ -3866,6 +3867,7 @@ public boolean hasNext() { } } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") @Override public Path next(/*@NonEmpty Iterator this*/) { try { diff --git a/src/java.base/share/classes/java/nio/file/Path.java b/src/java.base/share/classes/java/nio/file/Path.java index a5e263acdae8e..3780a87b696fb 100644 --- a/src/java.base/share/classes/java/nio/file/Path.java +++ b/src/java.base/share/classes/java/nio/file/Path.java @@ -32,6 +32,7 @@ import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.io.File; import java.io.IOException; @@ -963,6 +964,7 @@ public boolean hasNext() { @Override @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public Path next(/*@NonEmpty Iterator this*/) { if (i < getNameCount()) { Path result = getName(i); diff --git a/src/java.base/share/classes/java/util/Arrays.java b/src/java.base/share/classes/java/util/Arrays.java index e8c55ba81a54c..d7d43d421a57e 100644 --- a/src/java.base/share/classes/java/util/Arrays.java +++ b/src/java.base/share/classes/java/util/Arrays.java @@ -47,6 +47,7 @@ import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import jdk.internal.util.ArraysSupport; import jdk.internal.vm.annotation.ForceInline; @@ -4402,6 +4403,7 @@ public boolean hasNext() { @Override @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty ArrayItr this) { int i = cursor; if (i >= a.length) { diff --git a/src/java.base/share/classes/java/util/Enumeration.java b/src/java.base/share/classes/java/util/Enumeration.java index 5a51f4931776a..f86132d27e72c 100644 --- a/src/java.base/share/classes/java/util/Enumeration.java +++ b/src/java.base/share/classes/java/util/Enumeration.java @@ -31,6 +31,7 @@ import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; /** * An object that implements the Enumeration interface generates a @@ -134,6 +135,7 @@ default Iterator asIterator() { return hasMoreElements(); } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") @Override public E next(/*@NonEmpty Iterator this*/) { return nextElement(); } diff --git a/src/java.base/share/classes/java/util/ImmutableCollections.java b/src/java.base/share/classes/java/util/ImmutableCollections.java index 293e8c224488a..78f460363cbd3 100644 --- a/src/java.base/share/classes/java/util/ImmutableCollections.java +++ b/src/java.base/share/classes/java/util/ImmutableCollections.java @@ -35,6 +35,7 @@ import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.io.IOException; import java.io.InvalidObjectException; @@ -390,6 +391,7 @@ public boolean hasNext() { } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty ListItr this) { try { int i = cursor; @@ -864,6 +866,7 @@ public boolean hasNext() { @Override @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") @SuppressWarnings("unchecked") public E next(/*@NonEmpty Iterator this*/) { if (idx == 1) { @@ -1002,6 +1005,7 @@ public boolean hasNext() { @Override @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty SetNIterator this) { if (remaining > 0) { E element; @@ -1324,6 +1328,7 @@ public boolean hasNext() { } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") private int nextIndex() { int idx = this.idx; if (REVERSE) { diff --git a/src/java.base/share/classes/java/util/ServiceLoader.java b/src/java.base/share/classes/java/util/ServiceLoader.java index f8574ad10e616..076d5a5e85f00 100644 --- a/src/java.base/share/classes/java/util/ServiceLoader.java +++ b/src/java.base/share/classes/java/util/ServiceLoader.java @@ -34,6 +34,7 @@ import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.io.BufferedReader; import java.io.IOException; @@ -979,6 +980,7 @@ public boolean hasNext() { @Override @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public Provider next(@NonEmpty LayerLookupIterator this) { if (!hasNext()) throw new NoSuchElementException(); @@ -1300,6 +1302,7 @@ public boolean hasNext() { @SuppressWarnings("removal") @Override @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public Provider next(@NonEmpty LazyClassPathLookupIterator this) { if (acc == null) { return nextService(); @@ -1331,6 +1334,7 @@ public boolean hasNext() { } @Override @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public Provider next(/*@NonEmpty Iterator> this*/) { if (first.hasNext()) { return first.next(); @@ -1420,6 +1424,7 @@ public boolean hasNext() { @Override @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public S next(/*@NonEmpty Iterator this*/) { checkReloadCount(); S next; diff --git a/src/java.base/share/classes/java/util/Spliterators.java b/src/java.base/share/classes/java/util/Spliterators.java index 233943e4e16e4..c9dc86621403a 100644 --- a/src/java.base/share/classes/java/util/Spliterators.java +++ b/src/java.base/share/classes/java/util/Spliterators.java @@ -29,6 +29,7 @@ import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.function.Consumer; import java.util.function.DoubleConsumer; import java.util.function.IntConsumer; @@ -697,6 +698,7 @@ public boolean hasNext() { @Override @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public T next(@NonEmpty Adapter this) { if (!valueReady && !hasNext()) throw new NoSuchElementException(); @@ -759,6 +761,7 @@ public boolean hasNext() { @Override @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public int nextInt(@NonEmpty Adapter this) { if (!valueReady && !hasNext()) throw new NoSuchElementException(); @@ -817,6 +820,7 @@ public boolean hasNext() { @Override @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public long nextLong(@NonEmpty Adapter this) { if (!valueReady && !hasNext()) throw new NoSuchElementException(); @@ -875,6 +879,7 @@ public boolean hasNext() { @Override @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public double nextDouble(@NonEmpty Adapter this) { if (!valueReady && !hasNext()) throw new NoSuchElementException(); diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentMap.java index 0a05f7aad2b85..f063bb3d726c8 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentMap.java @@ -118,6 +118,7 @@ default V getOrDefault(Object key, V defaultValue) { * @since 1.8 */ @Override + @DoesNotUnrefineReceiver("modifiability") default void forEach(BiConsumer action) { Objects.requireNonNull(action); for (Map.Entry entry : entrySet()) { @@ -166,6 +167,7 @@ default void forEach(BiConsumer action) { * or value prevents it from being stored in this map */ @EnsuresKeyFor(value={"#1"}, map={"this"}) + @DoesNotUnrefineReceiver("modifiability") @Nullable V putIfAbsent(K key, V value); /** @@ -197,6 +199,7 @@ default void forEach(BiConsumer action) { * and this map does not permit null keys or values * (optional) */ + @DoesNotUnrefineReceiver("modifiability") boolean remove(@UnknownSignedness Object key, @UnknownSignedness Object value); /** @@ -229,6 +232,7 @@ default void forEach(BiConsumer action) { * @throws IllegalArgumentException if some property of a specified key * or value prevents it from being stored in this map */ + @DoesNotUnrefineReceiver("modifiability") boolean replace(K key, V oldValue, V newValue); /** @@ -261,6 +265,7 @@ default void forEach(BiConsumer action) { * @throws IllegalArgumentException if some property of the specified key * or value prevents it from being stored in this map */ + @DoesNotUnrefineReceiver("modifiability") @Nullable V replace(K key, V value); /** @@ -294,6 +299,7 @@ default void forEach(BiConsumer action) { * @since 1.8 */ @Override + @DoesNotUnrefineReceiver("modifiability") default void replaceAll(BiFunction function) { Objects.requireNonNull(function); forEach((k,v) -> { @@ -334,6 +340,7 @@ default void replaceAll(BiFunction function) * @since 1.8 */ @Override + @DoesNotUnrefineReceiver("modifiability") default @PolyNull V computeIfAbsent(K key, Function mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -376,6 +383,7 @@ default void replaceAll(BiFunction function) * @since 1.8 */ @Override + @DoesNotUnrefineReceiver("modifiability") default @PolyNull V computeIfPresent(K key, BiFunction remappingFunction) { Objects.requireNonNull(remappingFunction); @@ -424,6 +432,7 @@ default void replaceAll(BiFunction function) * @since 1.8 */ @Override + @DoesNotUnrefineReceiver("modifiability") default @PolyNull V compute(K key, BiFunction remappingFunction) { retry: for (;;) { @@ -484,6 +493,7 @@ else if ((oldValue = putIfAbsent(key, newValue)) == null) * @since 1.8 */ @Override + @DoesNotUnrefineReceiver("modifiability") default @PolyNull V merge(K key, @NonNull V value, BiFunction remappingFunction) { Objects.requireNonNull(remappingFunction); diff --git a/src/java.base/share/classes/java/util/concurrent/ScheduledThreadPoolExecutor.java b/src/java.base/share/classes/java/util/concurrent/ScheduledThreadPoolExecutor.java index 3861899a7f2eb..2e9822843421e 100644 --- a/src/java.base/share/classes/java/util/concurrent/ScheduledThreadPoolExecutor.java +++ b/src/java.base/share/classes/java/util/concurrent/ScheduledThreadPoolExecutor.java @@ -43,6 +43,7 @@ import org.checkerframework.checker.signedness.qual.UnknownSignedness; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.NANOSECONDS; @@ -1352,6 +1353,7 @@ public boolean hasNext() { } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public Runnable next(@NonEmpty Itr this) { if (cursor >= array.length) throw new NoSuchElementException(); diff --git a/src/java.base/share/classes/java/util/regex/Matcher.java b/src/java.base/share/classes/java/util/regex/Matcher.java index a74582f40feb4..801ef291d3f41 100644 --- a/src/java.base/share/classes/java/util/regex/Matcher.java +++ b/src/java.base/share/classes/java/util/regex/Matcher.java @@ -37,6 +37,7 @@ import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.io.IOException; import java.util.ConcurrentModificationException; @@ -1356,6 +1357,7 @@ class MatchResultIterator implements Iterator { @Override @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public MatchResult next(@NonEmpty MatchResultIterator this) { if (expectedCount >= 0 && expectedCount != modCount) throw new ConcurrentModificationException(); diff --git a/src/java.base/share/classes/java/util/regex/Pattern.java b/src/java.base/share/classes/java/util/regex/Pattern.java index 05864157b3a7b..ea22bef401a8f 100644 --- a/src/java.base/share/classes/java/util/regex/Pattern.java +++ b/src/java.base/share/classes/java/util/regex/Pattern.java @@ -38,6 +38,7 @@ import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.text.Normalizer; import java.text.Normalizer.Form; @@ -6086,6 +6087,7 @@ class MatcherIterator implements Iterator { private int emptyElementCount; @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public String next(@NonEmpty MatcherIterator this) { if (!hasNext()) throw new NoSuchElementException(); diff --git a/src/java.base/share/classes/java/util/zip/ZipFile.java b/src/java.base/share/classes/java/util/zip/ZipFile.java index 01acfda1c42e8..d318e73aa21d0 100644 --- a/src/java.base/share/classes/java/util/zip/ZipFile.java +++ b/src/java.base/share/classes/java/util/zip/ZipFile.java @@ -39,6 +39,7 @@ import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.io.Closeable; import java.io.InputStream; @@ -523,6 +524,7 @@ public boolean hasNext() { @Override @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public T nextElement(@NonEmpty ZipEntryIterator this) { return next(); } @@ -530,6 +532,7 @@ public T nextElement(@NonEmpty ZipEntryIterator this) { @Override @SuppressWarnings("unchecked") @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public T next(@NonEmpty ZipEntryIterator this) { synchronized (ZipFile.this) { ensureOpen(); From 2a4dea3e3d33c51a74c9043902c2ad665361f448 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 19 May 2026 08:36:12 -0700 Subject: [PATCH 05/15] More annotations --- .../share/classes/java/util/AbstractList.java | 13 ++ .../share/classes/java/util/AbstractMap.java | 4 + .../share/classes/java/util/ArrayDeque.java | 2 + .../share/classes/java/util/ArrayList.java | 4 + .../share/classes/java/util/Collections.java | 127 ++++++++++++++++++ .../share/classes/java/util/EnumMap.java | 11 ++ .../share/classes/java/util/HashSet.java | 3 + .../share/classes/java/util/Hashtable.java | 2 + .../classes/java/util/IdentityHashMap.java | 6 + .../share/classes/java/util/JumboEnumSet.java | 8 ++ .../classes/java/util/LinkedHashMap.java | 5 + .../share/classes/java/util/LinkedList.java | 2 + .../share/classes/java/util/List.java | 41 +++++- .../classes/java/util/PriorityQueue.java | 2 + .../classes/java/util/RegularEnumSet.java | 1 + .../share/classes/java/util/Scanner.java | 5 + .../share/classes/java/util/TreeMap.java | 31 +++++ .../share/classes/java/util/Vector.java | 1 + .../share/classes/java/util/WeakHashMap.java | 3 + .../util/concurrent/ArrayBlockingQueue.java | 1 + .../util/concurrent/ConcurrentHashMap.java | 6 + .../concurrent/ConcurrentLinkedDeque.java | 1 + .../concurrent/ConcurrentLinkedQueue.java | 1 + .../concurrent/ConcurrentSkipListMap.java | 6 + .../util/concurrent/CopyOnWriteArrayList.java | 7 + .../java/util/concurrent/DelayQueue.java | 1 + .../util/concurrent/LinkedBlockingDeque.java | 1 + .../util/concurrent/LinkedBlockingQueue.java | 1 + .../util/concurrent/LinkedTransferQueue.java | 1 + .../classes/java/util/jar/Attributes.java | 5 + .../org/objectweb/asm/tree/InsnList.java | 5 + .../classes/sun/net/www/HeaderParser.java | 3 + .../classes/sun/net/www/MessageHeader.java | 3 + 33 files changed, 312 insertions(+), 1 deletion(-) diff --git a/src/java.base/share/classes/java/util/AbstractList.java b/src/java.base/share/classes/java/util/AbstractList.java index 8a7588b68a2de..25c5017e2128a 100644 --- a/src/java.base/share/classes/java/util/AbstractList.java +++ b/src/java.base/share/classes/java/util/AbstractList.java @@ -402,6 +402,7 @@ public boolean hasNext() { } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty Itr this) { checkForComodification(); try { @@ -416,6 +417,7 @@ public E next(@NonEmpty Itr this) { } } + @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastRet < 0) throw new IllegalStateException(); @@ -468,6 +470,7 @@ public int previousIndex() { return cursor-1; } + @DoesNotUnrefineReceiver("modifiability") public void set(E e) { if (lastRet < 0) throw new IllegalStateException(); @@ -481,6 +484,7 @@ public void set(E e) { } } + @DoesNotUnrefineReceiver("modifiability") public void add(E e) { checkForComodification(); @@ -816,6 +820,7 @@ protected SubList(SubList parent, int fromIndex, int toIndex) { this.modCount = root.modCount; } + @DoesNotUnrefineReceiver("modifiability") public E set(int index, E element) { Objects.checkIndex(index, size); checkForComodification(); @@ -834,6 +839,7 @@ public int size() { return size; } + @DoesNotUnrefineReceiver("modifiability") public void add(int index, E element) { rangeCheckForAdd(index); checkForComodification(); @@ -841,6 +847,7 @@ public void add(int index, E element) { updateSizeAndModCount(1); } + @DoesNotUnrefineReceiver("modifiability") public E remove(int index) { Objects.checkIndex(index, size); checkForComodification(); @@ -855,10 +862,12 @@ protected void removeRange(int fromIndex, int toIndex) { updateSizeAndModCount(fromIndex - toIndex); } + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { return addAll(size, c); } + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(int index, Collection c) { rangeCheckForAdd(index); int cSize = c.size(); @@ -889,6 +898,7 @@ public boolean hasNext() { } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(/*@NonEmpty ListIterator this*/) { if (hasNext()) return i.next(); @@ -919,15 +929,18 @@ public int previousIndex() { return i.previousIndex() - offset; } + @DoesNotUnrefineReceiver("modifiability") public void remove() { i.remove(); updateSizeAndModCount(-1); } + @DoesNotUnrefineReceiver("modifiability") public void set(E e) { i.set(e); } + @DoesNotUnrefineReceiver("modifiability") public void add(E e) { i.add(e); updateSizeAndModCount(1); diff --git a/src/java.base/share/classes/java/util/AbstractMap.java b/src/java.base/share/classes/java/util/AbstractMap.java index b5775777d5b08..9a2da50fbb0e0 100644 --- a/src/java.base/share/classes/java/util/AbstractMap.java +++ b/src/java.base/share/classes/java/util/AbstractMap.java @@ -396,6 +396,7 @@ public boolean hasNext() { } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public K next(/*@NonEmpty Iterator this*/) { return i.next().getKey(); } @@ -465,6 +466,7 @@ public boolean hasNext() { } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public V next(/*@NonEmpty Iterator this*/) { return i.next().getValue(); } @@ -971,7 +973,9 @@ public String toString(AbstractMap.@GuardSatisfied SimpleImmutableEntry th UnsupportedOperationException uoe() { return new UnsupportedOperationException(); } abstract Collection view(); + @DoesNotUnrefineReceiver("modifiability") public boolean add(E t) { throw uoe(); } + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { throw uoe(); } @DoesNotUnrefineReceiver("modifiability") public void clear() { view().clear(); } diff --git a/src/java.base/share/classes/java/util/ArrayDeque.java b/src/java.base/share/classes/java/util/ArrayDeque.java index e5cf586d5fe57..a66c580f0b128 100644 --- a/src/java.base/share/classes/java/util/ArrayDeque.java +++ b/src/java.base/share/classes/java/util/ArrayDeque.java @@ -743,6 +743,7 @@ public final boolean hasNext() { } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty DeqIterator this) { if (remaining <= 0) throw new NoSuchElementException(); @@ -792,6 +793,7 @@ public void forEachRemaining(Consumer action) { private class DescendingIterator extends DeqIterator { DescendingIterator() { cursor = dec(tail, elements.length); } + @DoesNotUnrefineReceiver("modifiability") public final E next(@NonEmpty DescendingIterator this) { if (remaining <= 0) throw new NoSuchElementException(); diff --git a/src/java.base/share/classes/java/util/ArrayList.java b/src/java.base/share/classes/java/util/ArrayList.java index 2bcf080a16129..38dc47cd960ec 100644 --- a/src/java.base/share/classes/java/util/ArrayList.java +++ b/src/java.base/share/classes/java/util/ArrayList.java @@ -534,6 +534,7 @@ private void add(E e, Object[] elementData, int s) { */ @SideEffectsOnly("this") @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") public boolean add(@GuardSatisfied ArrayList this, E e) { modCount++; add(e, elementData, size); @@ -550,6 +551,7 @@ public boolean add(@GuardSatisfied ArrayList this, E e) { * @throws IndexOutOfBoundsException {@inheritDoc} */ @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public void add(@GuardSatisfied ArrayList this, @NonNegative int index, E element) { rangeCheckForAdd(index); modCount++; @@ -802,6 +804,7 @@ public void clear(@GuardSatisfied @CanShrink ArrayList this) { * @throws NullPointerException if the specified collection is null */ @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@GuardSatisfied ArrayList this, Collection c) { Object[] a = c.toArray(); modCount++; @@ -833,6 +836,7 @@ public boolean addAll(@GuardSatisfied ArrayList this, Collection * @throws NullPointerException if the specified collection is null */ @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@GuardSatisfied ArrayList this, @NonNegative int index, Collection c) { rangeCheckForAdd(index); diff --git a/src/java.base/share/classes/java/util/Collections.java b/src/java.base/share/classes/java/util/Collections.java index 4b35085b4f7b7..9cebd4abae61f 100644 --- a/src/java.base/share/classes/java/util/Collections.java +++ b/src/java.base/share/classes/java/util/Collections.java @@ -1124,6 +1124,7 @@ static class UnmodifiableCollection implements Collection, Serializable { @EnsuresNonEmptyIf(result = true, expression = "this") public boolean hasNext() {return i.hasNext();} @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(/*@NonEmpty Iterator this*/) {return i.next();} @DoesNotUnrefineReceiver("modifiability") public void remove() { @@ -1623,6 +1624,7 @@ public ListIterator listIterator(final int index) { @EnsuresNonEmptyIf(result = true, expression = "this") public boolean hasNext() {return i.hasNext();} @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(/*@NonEmpty ListIterator this*/) {return i.next();} @Pure public boolean hasPrevious() {return i.hasPrevious();} @@ -1631,12 +1633,15 @@ public ListIterator listIterator(final int index) { public int nextIndex() {return i.nextIndex();} public int previousIndex() {return i.previousIndex();} + @DoesNotUnrefineReceiver("modifiability") public void remove() { throw new UnsupportedOperationException(); } + @DoesNotUnrefineReceiver("modifiability") public void set(E e) { throw new UnsupportedOperationException(); } + @DoesNotUnrefineReceiver("modifiability") public void add(E e) { throw new UnsupportedOperationException(); } @@ -1755,16 +1760,20 @@ private static class UnmodifiableMap implements Map, Serializable { public boolean containsValue(@UnknownSignedness Object val) {return m.containsValue(val);} public V get(Object key) {return m.get(key);} + @DoesNotUnrefineReceiver("modifiability") @EnsuresKeyFor(value={"#1"}, map={"this"}) public V put(K key, V value) { throw new UnsupportedOperationException(); } + @DoesNotUnrefineReceiver("modifiability") public V remove(Object key) { throw new UnsupportedOperationException(); } + @DoesNotUnrefineReceiver("modifiability") public void putAll(Map m) { throw new UnsupportedOperationException(); } + @DoesNotUnrefineReceiver("modifiability") public void clear() { throw new UnsupportedOperationException(); } @@ -1811,10 +1820,12 @@ public void forEach(BiConsumer action) { } @Override + @DoesNotUnrefineReceiver("modifiability") public void replaceAll(BiFunction function) { throw new UnsupportedOperationException(); } + @DoesNotUnrefineReceiver("modifiability") @EnsuresKeyFor(value={"#1"}, map={"this"}) @Override public V putIfAbsent(K key, V value) { @@ -1822,38 +1833,45 @@ public V putIfAbsent(K key, V value) { } @Override + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object key, @UnknownSignedness Object value) { throw new UnsupportedOperationException(); } @Override + @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { throw new UnsupportedOperationException(); } @Override + @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { throw new UnsupportedOperationException(); } @Override + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V computeIfAbsent(K key, Function mappingFunction) { throw new UnsupportedOperationException(); } @Override + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V computeIfPresent(K key, BiFunction remappingFunction) { throw new UnsupportedOperationException(); } @Override + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V compute(K key, BiFunction remappingFunction) { throw new UnsupportedOperationException(); } @Override + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V merge(K key, @NonNull V value, BiFunction remappingFunction) { throw new UnsupportedOperationException(); @@ -1967,9 +1985,11 @@ public boolean hasNext() { return i.hasNext(); } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(/*@NonEmpty Iterator> this*/) { return new UnmodifiableEntry<>(i.next()); } + @DoesNotUnrefineReceiver("modifiability") public void remove() { throw new UnsupportedOperationException(); } @@ -2123,18 +2143,22 @@ public SequencedMap reversed() { return new UnmodifiableSequencedMap<>(sm().reversed()); } + @DoesNotUnrefineReceiver("modifiability") public Entry pollFirstEntry() { throw new UnsupportedOperationException(); } + @DoesNotUnrefineReceiver("modifiability") public Entry pollLastEntry() { throw new UnsupportedOperationException(); } + @DoesNotUnrefineReceiver("modifiability") public V putFirst(K k, V v) { throw new UnsupportedOperationException(); } + @DoesNotUnrefineReceiver("modifiability") public V putLast(K k, V v) { throw new UnsupportedOperationException(); } @@ -2323,8 +2347,10 @@ public Entry lastEntry() { : null; } + @DoesNotUnrefineReceiver("modifiability") public Entry pollFirstEntry() { throw new UnsupportedOperationException(); } + @DoesNotUnrefineReceiver("modifiability") public Entry pollLastEntry() { throw new UnsupportedOperationException(); } @SideEffectFree @@ -2447,10 +2473,12 @@ public Iterator iterator() { return c.iterator(); // Must be manually synched by user! } + @DoesNotUnrefineReceiver("modifiability") @EnsuresNonEmpty("this") public boolean add(E e) { synchronized (mutex) {return c.add(e);} } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { synchronized (mutex) {return c.remove(o);} } @@ -2459,15 +2487,19 @@ public boolean remove(@UnknownSignedness Object o) { public boolean containsAll(Collection coll) { synchronized (mutex) {return c.containsAll(coll);} } + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection coll) { synchronized (mutex) {return c.addAll(coll);} } + @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection coll) { synchronized (mutex) {return c.removeAll(coll);} } + @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection coll) { synchronized (mutex) {return c.retainAll(coll);} } + @DoesNotUnrefineReceiver("modifiability") public void clear() { synchronized (mutex) {c.clear();} } @@ -2480,6 +2512,7 @@ public void forEach(Consumer consumer) { synchronized (mutex) {c.forEach(consumer);} } @Override + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { synchronized (mutex) {return c.removeIf(filter);} } @@ -2728,7 +2761,9 @@ static class SynchronizedNavigableSet public E floor(E e) { synchronized (mutex) {return ns.floor(e);} } public E ceiling(E e) { synchronized (mutex) {return ns.ceiling(e);} } public E higher(E e) { synchronized (mutex) {return ns.higher(e);} } + @DoesNotUnrefineReceiver("modifiability") public E pollFirst() { synchronized (mutex) {return ns.pollFirst();} } + @DoesNotUnrefineReceiver("modifiability") public E pollLast() { synchronized (mutex) {return ns.pollLast();} } public NavigableSet descendingSet() { @@ -2847,12 +2882,15 @@ public int hashCode() { public E get(int index) { synchronized (mutex) {return list.get(index);} } + @DoesNotUnrefineReceiver("modifiability") public E set(int index, E element) { synchronized (mutex) {return list.set(index, element);} } + @DoesNotUnrefineReceiver("modifiability") public void add(int index, E element) { synchronized (mutex) {list.add(index, element);} } + @DoesNotUnrefineReceiver("modifiability") public E remove(int index) { synchronized (mutex) {return list.remove(index);} } @@ -2864,6 +2902,7 @@ public int lastIndexOf(Object o) { synchronized (mutex) {return list.lastIndexOf(o);} } + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(int index, Collection c) { synchronized (mutex) {return list.addAll(index, c);} } @@ -2884,10 +2923,12 @@ public List subList(int fromIndex, int toIndex) { } @Override + @DoesNotUnrefineReceiver("modifiability") public void replaceAll(UnaryOperator operator) { synchronized (mutex) {list.replaceAll(operator);} } @Override + @DoesNotUnrefineReceiver("modifiability") public void sort(Comparator c) { synchronized (mutex) {list.sort(c);} } @@ -3028,16 +3069,20 @@ public V get(Object key) { synchronized (mutex) {return m.get(key);} } + @DoesNotUnrefineReceiver("modifiability") @EnsuresKeyFor(value={"#1"}, map={"this"}) public V put(K key, V value) { synchronized (mutex) {return m.put(key, value);} } + @DoesNotUnrefineReceiver("modifiability") public V remove(Object key) { synchronized (mutex) {return m.remove(key);} } + @DoesNotUnrefineReceiver("modifiability") public void putAll(Map map) { synchronized (mutex) {m.putAll(map);} } + @DoesNotUnrefineReceiver("modifiability") public void clear() { synchronized (mutex) {m.clear();} } @@ -3094,42 +3139,51 @@ public void forEach(BiConsumer action) { synchronized (mutex) {m.forEach(action);} } @Override + @DoesNotUnrefineReceiver("modifiability") public void replaceAll(BiFunction function) { synchronized (mutex) {m.replaceAll(function);} } + @DoesNotUnrefineReceiver("modifiability") @EnsuresKeyFor(value={"#1"}, map={"this"}) @Override public V putIfAbsent(K key, V value) { synchronized (mutex) {return m.putIfAbsent(key, value);} } @Override + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object key, @UnknownSignedness Object value) { synchronized (mutex) {return m.remove(key, value);} } @Override + @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { synchronized (mutex) {return m.replace(key, oldValue, newValue);} } @Override + @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { synchronized (mutex) {return m.replace(key, value);} } @Override + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V computeIfAbsent(K key, Function mappingFunction) { synchronized (mutex) {return m.computeIfAbsent(key, mappingFunction);} } @Override + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V computeIfPresent(K key, BiFunction remappingFunction) { synchronized (mutex) {return m.computeIfPresent(key, remappingFunction);} } @Override + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V compute(K key, BiFunction remappingFunction) { synchronized (mutex) {return m.compute(key, remappingFunction);} } @Override + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V merge(K key, @NonNull V value, BiFunction remappingFunction) { synchronized (mutex) {return m.merge(key, value, remappingFunction);} @@ -3339,8 +3393,10 @@ public Entry firstEntry() { synchronized (mutex) { return nm.firstEntry(); } } public Entry lastEntry() { synchronized (mutex) { return nm.lastEntry(); } } + @DoesNotUnrefineReceiver("modifiability") public Entry pollFirstEntry() { synchronized (mutex) { return nm.pollFirstEntry(); } } + @DoesNotUnrefineReceiver("modifiability") public Entry pollLastEntry() { synchronized (mutex) { return nm.pollLastEntry(); } } @@ -3532,16 +3588,20 @@ private String badElementMsg(Object o) { public @Nullable T[] toArray(@PolyNull T[] a) { return c.toArray(a); } public T[] toArray(IntFunction f) { return c.toArray(f); } public String toString() { return c.toString(); } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { return c.remove(o); } + @DoesNotUnrefineReceiver("modifiability") public void clear() { c.clear(); } @Pure public boolean containsAll(Collection coll) { return c.containsAll(coll); } + @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection coll) { return c.removeAll(coll); } + @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection coll) { return c.retainAll(coll); } @@ -3556,7 +3616,9 @@ public Iterator iterator() { @EnsuresNonEmptyIf(result = true, expression = "this") public boolean hasNext() { return it.hasNext(); } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(/*@NonEmpty Iterator this*/) { return it.next(); } + @DoesNotUnrefineReceiver("modifiability") public void remove() { it.remove(); } public void forEachRemaining(Consumer action) { it.forEachRemaining(action); @@ -3564,6 +3626,7 @@ public void forEachRemaining(Consumer action) { }; } + @DoesNotUnrefineReceiver("modifiability") @EnsuresNonEmpty("this") public boolean add(E e) { return c.add(typeCheck(e)); } @@ -3598,6 +3661,7 @@ Collection checkedCopyOf(Collection coll) { return (Collection) Arrays.asList(a); } + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection coll) { // Doing things this way insulates us from concurrent changes // in the contents of coll and provides all-or-nothing @@ -3610,6 +3674,7 @@ public boolean addAll(Collection coll) { @Override public void forEach(Consumer action) {c.forEach(action);} @Override + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { return c.removeIf(filter); } @@ -3677,8 +3742,11 @@ static class CheckedQueue public int hashCode() {return c.hashCode();} @Pure public E peek() {return queue.peek();} + @DoesNotUnrefineReceiver("modifiability") public E poll() {return queue.poll();} + @DoesNotUnrefineReceiver("modifiability") public E remove() {return queue.remove();} + @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) {return queue.offer(typeCheck(e));} } @@ -3930,18 +3998,22 @@ static class CheckedList public boolean equals(Object o) { return o == this || list.equals(o); } public int hashCode() { return list.hashCode(); } public E get(int index) { return list.get(index); } + @DoesNotUnrefineReceiver("modifiability") public E remove(int index) { return list.remove(index); } public int indexOf(Object o) { return list.indexOf(o); } public int lastIndexOf(Object o) { return list.lastIndexOf(o); } + @DoesNotUnrefineReceiver("modifiability") public E set(int index, E element) { return list.set(index, typeCheck(element)); } + @DoesNotUnrefineReceiver("modifiability") public void add(int index, E element) { list.add(index, typeCheck(element)); } + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(int index, Collection c) { return list.addAll(index, checkedCopyOf(c)); } @@ -3955,17 +4027,21 @@ public ListIterator listIterator(final int index) { @EnsuresNonEmptyIf(result = true, expression = "this") public boolean hasNext() { return i.hasNext(); } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(/*@NonEmpty ListIterator this*/) { return i.next(); } public boolean hasPrevious() { return i.hasPrevious(); } public E previous() { return i.previous(); } public int nextIndex() { return i.nextIndex(); } public int previousIndex() { return i.previousIndex(); } + @DoesNotUnrefineReceiver("modifiability") public void remove() { i.remove(); } + @DoesNotUnrefineReceiver("modifiability") public void set(E e) { i.set(typeCheck(e)); } + @DoesNotUnrefineReceiver("modifiability") public void add(E e) { i.add(typeCheck(e)); } @@ -3990,12 +4066,14 @@ public List subList(int fromIndex, int toIndex) { * already been replaced. */ @Override + @DoesNotUnrefineReceiver("modifiability") public void replaceAll(UnaryOperator operator) { Objects.requireNonNull(operator); list.replaceAll(e -> typeCheck(operator.apply(e))); } @Override + @DoesNotUnrefineReceiver("modifiability") public void sort(Comparator c) { list.sort(c); } @@ -4124,7 +4202,9 @@ private String badValueMsg(Object value) { @Pure public boolean containsValue(@UnknownSignedness Object v) { return m.containsValue(v); } public V get(Object key) { return m.get(key); } + @DoesNotUnrefineReceiver("modifiability") public V remove(Object key) { return m.remove(key); } + @DoesNotUnrefineReceiver("modifiability") public void clear() { m.clear(); } public Set keySet() { return m.keySet(); } public Collection values() { return m.values(); } @@ -4132,12 +4212,14 @@ private String badValueMsg(Object value) { public int hashCode() { return m.hashCode(); } public String toString() { return m.toString(); } + @DoesNotUnrefineReceiver("modifiability") @EnsuresKeyFor(value={"#1"}, map={"this"}) public V put(K key, V value) { typeCheck(key, value); return m.put(key, value); } + @DoesNotUnrefineReceiver("modifiability") @SuppressWarnings("unchecked") public void putAll(Map t) { // Satisfy the following goals: @@ -4175,10 +4257,12 @@ public void forEach(BiConsumer action) { } @Override + @DoesNotUnrefineReceiver("modifiability") public void replaceAll(BiFunction function) { m.replaceAll(typeCheck(function)); } + @DoesNotUnrefineReceiver("modifiability") @EnsuresKeyFor(value={"#1"}, map={"this"}) @Override public V putIfAbsent(K key, V value) { @@ -4187,23 +4271,27 @@ public V putIfAbsent(K key, V value) { } @Override + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object key, @UnknownSignedness Object value) { return m.remove(key, value); } @Override + @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { typeCheck(key, newValue); return m.replace(key, oldValue, newValue); } @Override + @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { typeCheck(key, value); return m.replace(key, value); } @Override + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V computeIfAbsent(K key, Function mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -4215,18 +4303,21 @@ public V replace(K key, V value) { } @Override + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V computeIfPresent(K key, BiFunction remappingFunction) { return m.computeIfPresent(key, typeCheck(remappingFunction)); } @Override + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V compute(K key, BiFunction remappingFunction) { return m.compute(key, typeCheck(remappingFunction)); } @Override + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V merge(K key, @NonNull V value, BiFunction remappingFunction) { Objects.requireNonNull(remappingFunction); @@ -4261,12 +4352,15 @@ static class CheckedEntrySet implements Set> { public boolean isEmpty() { return s.isEmpty(); } public String toString() { return s.toString(); } public int hashCode() { return s.hashCode(); } + @DoesNotUnrefineReceiver("modifiability") public void clear() { s.clear(); } + @DoesNotUnrefineReceiver("modifiability") @EnsuresNonEmpty("this") public boolean add(Map.Entry e) { throw new UnsupportedOperationException(); } + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection> coll) { throw new UnsupportedOperationException(); } @@ -4279,8 +4373,10 @@ public Iterator> iterator() { @EnsuresNonEmptyIf(result = true, expression = "this") public boolean hasNext() { return i.hasNext(); } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public void remove() { i.remove(); } + @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(/*@NonEmpty Iterator> this*/) { return checkedEntry(i.next(), valueType); } @@ -4356,6 +4452,7 @@ public boolean containsAll(Collection c) { return true; } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { if (!(o instanceof Map.Entry)) return false; @@ -4363,9 +4460,11 @@ public boolean remove(@UnknownSignedness Object o) { <>((Map.Entry)o)); } + @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { return batchRemove(c, false); } + @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { return batchRemove(c, true); } @@ -4632,6 +4731,7 @@ public Entry lastEntry() { : null; } + @DoesNotUnrefineReceiver("modifiability") public Entry pollFirstEntry() { Entry entry = nm.pollFirstEntry(); return (null == entry) @@ -4639,6 +4739,7 @@ public Entry pollFirstEntry() { : new CheckedMap.CheckedEntrySet.CheckedEntry<>(entry, valueType); } + @DoesNotUnrefineReceiver("modifiability") public Entry pollLastEntry() { Entry entry = nm.pollLastEntry(); return (null == entry) @@ -4735,7 +4836,9 @@ private static class EmptyIterator implements Iterator { @EnsuresNonEmptyIf(result = true, expression = "this") public boolean hasNext() { return false; } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty EmptyIterator this) { throw new NoSuchElementException(); } + @DoesNotUnrefineReceiver("modifiability") public void remove(@NonEmpty EmptyIterator this) { throw new IllegalStateException(); } @Override public void forEachRemaining(Consumer action) { @@ -4786,7 +4889,9 @@ private static class EmptyListIterator public E previous() { throw new NoSuchElementException(); } public int nextIndex() { return 0; } public int previousIndex() { return -1; } + @DoesNotUnrefineReceiver("modifiability") public void set(E e) { throw new IllegalStateException(); } + @DoesNotUnrefineReceiver("modifiability") public void add(E e) { throw new UnsupportedOperationException(); } } @@ -5203,6 +5308,7 @@ public void replaceAll(BiFunction function) { Objects.requireNonNull(function); } + @DoesNotUnrefineReceiver("modifiability") @EnsuresKeyFor(value={"#1"}, map={"this"}) @Override public V putIfAbsent(K key, V value) { @@ -5210,39 +5316,46 @@ public V putIfAbsent(K key, V value) { } @Override + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object key, @UnknownSignedness Object value) { throw new UnsupportedOperationException(); } @Override + @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { throw new UnsupportedOperationException(); } @Override + @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { throw new UnsupportedOperationException(); } @Override + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V computeIfAbsent(K key, Function mappingFunction) { throw new UnsupportedOperationException(); } @Override + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V computeIfPresent(K key, BiFunction remappingFunction) { throw new UnsupportedOperationException(); } @Override + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V compute(K key, BiFunction remappingFunction) { throw new UnsupportedOperationException(); } @Override + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V merge(K key, @NonNull V value, BiFunction remappingFunction) { throw new UnsupportedOperationException(); @@ -5278,6 +5391,7 @@ public boolean hasNext() { return hasNext; } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(/*@NonEmpty Iterator this*/) { if (hasNext) { hasNext = false; @@ -5285,6 +5399,7 @@ public E next(/*@NonEmpty Iterator this*/) { } throw new NoSuchElementException(); } + @DoesNotUnrefineReceiver("modifiability") public void remove() { throw new UnsupportedOperationException(); } @@ -5383,6 +5498,7 @@ public Spliterator spliterator() { return singletonSpliterator(element); } @Override + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { throw new UnsupportedOperationException(); } @@ -5446,10 +5562,12 @@ public void forEach(Consumer action) { action.accept(element); } @Override + @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { throw new UnsupportedOperationException(); } @Override + @DoesNotUnrefineReceiver("modifiability") public void replaceAll(UnaryOperator operator) { throw new UnsupportedOperationException(); } @@ -5551,10 +5669,12 @@ public void forEach(BiConsumer action) { } @Override + @DoesNotUnrefineReceiver("modifiability") public void replaceAll(BiFunction function) { throw new UnsupportedOperationException(); } + @DoesNotUnrefineReceiver("modifiability") @EnsuresKeyFor(value={"#1"}, map={"this"}) @Override public V putIfAbsent(K key, V value) { @@ -5562,39 +5682,46 @@ public V putIfAbsent(K key, V value) { } @Override + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object key, @UnknownSignedness Object value) { throw new UnsupportedOperationException(); } @Override + @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { throw new UnsupportedOperationException(); } @Override + @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { throw new UnsupportedOperationException(); } @Override + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V computeIfAbsent(K key, Function mappingFunction) { throw new UnsupportedOperationException(); } @Override + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V computeIfPresent(K key, BiFunction remappingFunction) { throw new UnsupportedOperationException(); } @Override + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V compute(K key, BiFunction remappingFunction) { throw new UnsupportedOperationException(); } @Override + @DoesNotUnrefineReceiver("modifiability") public @PolyNull V merge(K key, @NonNull V value, BiFunction remappingFunction) { throw new UnsupportedOperationException(); diff --git a/src/java.base/share/classes/java/util/EnumMap.java b/src/java.base/share/classes/java/util/EnumMap.java index 50baf7d331930..9beff052a8feb 100644 --- a/src/java.base/share/classes/java/util/EnumMap.java +++ b/src/java.base/share/classes/java/util/EnumMap.java @@ -433,11 +433,13 @@ public Iterator iterator() { public boolean contains(@Nullable @UnknownSignedness Object o) { return containsKey(o); } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { int oldSize = size; EnumMap.this.remove(o); return size != oldSize; } + @DoesNotUnrefineReceiver("modifiability") public void clear() { EnumMap.this.clear(); } @@ -476,6 +478,7 @@ public Iterator iterator() { public boolean contains(@Nullable @UnknownSignedness Object o) { return containsValue(o); } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { o = maskNull(o); @@ -488,6 +491,7 @@ public boolean remove(@Nullable @UnknownSignedness Object o) { } return false; } + @DoesNotUnrefineReceiver("modifiability") public void clear() { EnumMap.this.clear(); } @@ -523,6 +527,7 @@ public boolean contains(@Nullable @UnknownSignedness Object o) { return o instanceof Map.Entry entry && containsMapping(entry.getKey(), entry.getValue()); } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { return o instanceof Map.Entry entry && removeMapping(entry.getKey(), entry.getValue()); @@ -531,6 +536,7 @@ public boolean remove(@Nullable @UnknownSignedness Object o) { public @NonNegative int size() { return size; } + @DoesNotUnrefineReceiver("modifiability") public void clear() { EnumMap.this.clear(); } @@ -583,6 +589,7 @@ public boolean hasNext() { return index != vals.length; } + @DoesNotUnrefineReceiver("modifiability") public void remove() { checkLastReturnedIndex(); @@ -600,6 +607,7 @@ private void checkLastReturnedIndex() { } private class KeyIterator extends EnumMapIterator { + @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty KeyIterator this) { if (!hasNext()) throw new NoSuchElementException(); @@ -612,6 +620,7 @@ private class ValueIterator extends EnumMapIterator { @CFComment({"nullness: Value returned by unmaskNull", "will be of type V (not @Nullable V) for mapped value"}) @SuppressWarnings({"nullness:return"}) + @DoesNotUnrefineReceiver("modifiability") public V next(@NonEmpty ValueIterator this) { if (!hasNext()) throw new NoSuchElementException(); @@ -623,6 +632,7 @@ public V next(@NonEmpty ValueIterator this) { private class EntryIterator extends EnumMapIterator> { private Entry lastReturnedEntry; + @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(@NonEmpty EntryIterator this) { if (!hasNext()) throw new NoSuchElementException(); @@ -630,6 +640,7 @@ public Map.Entry next(@NonEmpty EntryIterator this) { return lastReturnedEntry; } + @DoesNotUnrefineReceiver("modifiability") public void remove() { lastReturnedIndex = ((null == lastReturnedEntry) ? -1 : lastReturnedEntry.index); diff --git a/src/java.base/share/classes/java/util/HashSet.java b/src/java.base/share/classes/java/util/HashSet.java index b7e766bc732d3..69e3196eb0e56 100644 --- a/src/java.base/share/classes/java/util/HashSet.java +++ b/src/java.base/share/classes/java/util/HashSet.java @@ -250,6 +250,7 @@ public boolean contains(@GuardSatisfied HashSet this, @GuardSatisfied @Nullab */ @SideEffectsOnly("this") @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") public boolean add(@GuardSatisfied HashSet this, E e) { return map.put(e, PRESENT)==null; } @@ -267,6 +268,7 @@ public boolean add(@GuardSatisfied HashSet this, E e) { * @return {@code true} if the set contained the specified element */ @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied HashSet this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { return map.remove(o)==PRESENT; } @@ -276,6 +278,7 @@ public boolean remove(@GuardSatisfied HashSet this, @GuardSatisfied @Nullable * The set will be empty after this call returns. */ @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied HashSet this) { map.clear(); } diff --git a/src/java.base/share/classes/java/util/Hashtable.java b/src/java.base/share/classes/java/util/Hashtable.java index 842476fd4b437..32bcf3d84f47c 100644 --- a/src/java.base/share/classes/java/util/Hashtable.java +++ b/src/java.base/share/classes/java/util/Hashtable.java @@ -1545,6 +1545,7 @@ public boolean hasMoreElements() { } @SuppressWarnings("unchecked") + @DoesNotUnrefineReceiver("modifiability") public T nextElement(@NonEmpty Enumerator this) { Entry et = entry; int i = index; @@ -1571,6 +1572,7 @@ public boolean hasNext() { } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public T next(@NonEmpty Enumerator this) { if (Hashtable.this.modCount != expectedModCount) throw new ConcurrentModificationException(); diff --git a/src/java.base/share/classes/java/util/IdentityHashMap.java b/src/java.base/share/classes/java/util/IdentityHashMap.java index 0b21d12952b82..ab875f1b85be1 100644 --- a/src/java.base/share/classes/java/util/IdentityHashMap.java +++ b/src/java.base/share/classes/java/util/IdentityHashMap.java @@ -881,6 +881,7 @@ public void remove() { private class KeyIterator extends IdentityHashMapIterator { @SuppressWarnings("unchecked") + @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty KeyIterator this) { return (K) unmaskNull(traversalTable[nextIndex()]); } @@ -888,6 +889,7 @@ public K next(@NonEmpty KeyIterator this) { private class ValueIterator extends IdentityHashMapIterator { @SuppressWarnings("unchecked") + @DoesNotUnrefineReceiver("modifiability") public V next(@NonEmpty ValueIterator this) { return (V) traversalTable[nextIndex() + 1]; } @@ -898,6 +900,7 @@ private class EntryIterator { private Entry lastReturnedEntry; + @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(@NonEmpty EntryIterator this) { lastReturnedEntry = new Entry(nextIndex()); return lastReturnedEntry; @@ -1455,6 +1458,7 @@ public void forEach(BiConsumer action) { @SuppressWarnings("unchecked") @Override + @DoesNotUnrefineReceiver("modifiability") public void replaceAll(BiFunction function) { Objects.requireNonNull(function); int expectedModCount = modCount; @@ -1482,6 +1486,7 @@ public void replaceAll(BiFunction function) { * {@code false}. */ @Override + @DoesNotUnrefineReceiver("modifiability") public boolean remove(Object key, Object value) { return removeMapping(key, value); } @@ -1496,6 +1501,7 @@ public boolean remove(Object key, Object value) { * otherwise it returns {@code false}. */ @Override + @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { Object k = maskNull(key); Object[] tab = table; diff --git a/src/java.base/share/classes/java/util/JumboEnumSet.java b/src/java.base/share/classes/java/util/JumboEnumSet.java index 21c9a851b21a0..cbe172a84e11d 100644 --- a/src/java.base/share/classes/java/util/JumboEnumSet.java +++ b/src/java.base/share/classes/java/util/JumboEnumSet.java @@ -157,6 +157,7 @@ public boolean hasNext() { @Override @SuppressWarnings("unchecked") @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty EnumSetIterator this) { if (!hasNext()) throw new NoSuchElementException(); @@ -168,6 +169,7 @@ public E next(@NonEmpty EnumSetIterator this) { } @Override + @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastReturned == 0) throw new IllegalStateException(); @@ -231,6 +233,7 @@ public boolean contains(@GuardSatisfied @Nullable @UnknownSignedness Object e) { * @throws NullPointerException if {@code e} is null */ @EnsuresNonEmpty("this") + @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { typeCheck(e); @@ -251,6 +254,7 @@ public boolean add(E e) { * @param e element to be removed from this set, if present * @return {@code true} if the set contained the specified element */ + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @Nullable @UnknownSignedness Object e) { if (e == null) return false; @@ -301,6 +305,7 @@ public boolean containsAll(Collection c) { * @throws NullPointerException if the specified collection or any of * its elements are null */ + @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { if (!(c instanceof JumboEnumSet es)) return super.addAll(c); @@ -326,6 +331,7 @@ public boolean addAll(Collection c) { * @return {@code true} if this set changed as a result of the call * @throws NullPointerException if the specified collection is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { if (!(c instanceof JumboEnumSet es)) return super.removeAll(c); @@ -346,6 +352,7 @@ public boolean removeAll(Collection c) { * @return {@code true} if this set changed as a result of the call * @throws NullPointerException if the specified collection is null */ + @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { if (!(c instanceof JumboEnumSet es)) return super.retainAll(c); @@ -364,6 +371,7 @@ public boolean retainAll(Collection c) { /** * Removes all of the elements from this set. */ + @DoesNotUnrefineReceiver("modifiability") public void clear() { Arrays.fill(elements, 0); size = 0; diff --git a/src/java.base/share/classes/java/util/LinkedHashMap.java b/src/java.base/share/classes/java/util/LinkedHashMap.java index 20459d97a5293..a27b527e68f68 100644 --- a/src/java.base/share/classes/java/util/LinkedHashMap.java +++ b/src/java.base/share/classes/java/util/LinkedHashMap.java @@ -837,6 +837,7 @@ final class LinkedValues extends AbstractCollection implements SequencedColle LinkedValues(boolean reversed) { this.reversed = reversed; } @Pure public final int size() { return size; } + @DoesNotUnrefineReceiver("modifiability") public final void clear() { LinkedHashMap.this.clear(); } @SideEffectFree public final Iterator iterator() { @@ -952,6 +953,7 @@ final class LinkedEntrySet extends AbstractSet> LinkedEntrySet(boolean reversed) { this.reversed = reversed; } @Pure public final int size() { return size; } + @DoesNotUnrefineReceiver("modifiability") public final void clear() { LinkedHashMap.this.clear(); } @SideEffectFree public final Iterator> iterator() { @@ -1100,18 +1102,21 @@ public final void remove() { final class LinkedKeyIterator extends LinkedHashIterator implements Iterator { LinkedKeyIterator(boolean reversed) { super(reversed); } + @DoesNotUnrefineReceiver("modifiability") public final K next(@NonEmpty LinkedKeyIterator this) { return nextNode().getKey(); } } final class LinkedValueIterator extends LinkedHashIterator implements Iterator { LinkedValueIterator(boolean reversed) { super(reversed); } + @DoesNotUnrefineReceiver("modifiability") public final V next(@NonEmpty LinkedValueIterator this) { return nextNode().value; } } final class LinkedEntryIterator extends LinkedHashIterator implements Iterator> { LinkedEntryIterator(boolean reversed) { super(reversed); } + @DoesNotUnrefineReceiver("modifiability") public final Map.Entry next(@NonEmpty LinkedEntryIterator this) { return nextNode(); } } diff --git a/src/java.base/share/classes/java/util/LinkedList.java b/src/java.base/share/classes/java/util/LinkedList.java index bb1111520f015..16b88a69c6a58 100644 --- a/src/java.base/share/classes/java/util/LinkedList.java +++ b/src/java.base/share/classes/java/util/LinkedList.java @@ -956,6 +956,7 @@ public boolean hasNext() { } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty ListItr this) { checkForComodification(); if (!hasNext()) @@ -1073,6 +1074,7 @@ public boolean hasNext() { return itr.hasPrevious(); } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty DescendingIterator this) { return itr.previous(); } diff --git a/src/java.base/share/classes/java/util/List.java b/src/java.base/share/classes/java/util/List.java index 9e59d0d3ad704..5c19bb1750b9f 100644 --- a/src/java.base/share/classes/java/util/List.java +++ b/src/java.base/share/classes/java/util/List.java @@ -41,12 +41,12 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; 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; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.function.UnaryOperator; @@ -300,6 +300,7 @@ public interface List extends SequencedCollection { */ @ReleasesNoLocks @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") @EnsuresNonEmpty("this") boolean add(@GuardSatisfied List this, E e); @@ -325,6 +326,7 @@ public interface List extends SequencedCollection { * is not supported by this list */ @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") boolean remove(@GuardSatisfied @CanShrink List this, @UnknownSignedness Object o); @@ -373,6 +375,7 @@ public interface List extends SequencedCollection { * @see #add(Object) */ @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") @EnsuresNonEmptyIf(result = true, expression = "this") boolean addAll(@GuardSatisfied List this, Collection c); @@ -404,6 +407,7 @@ public interface List extends SequencedCollection { * ({@code index < 0 || index > size()}) */ @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") @EnsuresNonEmptyIf(result = true, expression = "this") boolean addAll(@GuardSatisfied List this, @IndexOrHigh({"this"}) int index, Collection c); @@ -425,6 +429,8 @@ public interface List extends SequencedCollection { * @see #remove(Object) * @see #contains(Object) */ + @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") boolean removeAll(@GuardSatisfied @CanShrink List this, Collection c); /** @@ -447,6 +453,8 @@ public interface List extends SequencedCollection { * @see #remove(Object) * @see #contains(Object) */ + @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") boolean retainAll(@GuardSatisfied @CanShrink List this, Collection c); /** @@ -546,6 +554,8 @@ default void replaceAll(UnaryOperator operator) { * @since 1.8 */ @SuppressWarnings({"unchecked", "rawtypes"}) + @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") default void sort(Comparator c) { Object[] a = this.toArray(); Arrays.sort(a, (Comparator) c); @@ -563,6 +573,8 @@ default void sort(Comparator c) { * @throws UnsupportedOperationException if the {@code clear} operation * is not supported by this list */ + @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") void clear(@GuardSatisfied @CanShrink List this); @@ -637,6 +649,7 @@ default void sort(Comparator c) { * @throws IndexOutOfBoundsException if the index is out of range * ({@code index < 0 || index >= size()}) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E set(@GuardSatisfied List this, @IndexFor({"this"}) int index, E element); @@ -661,6 +674,7 @@ default void sort(Comparator c) { */ @ReleasesNoLocks @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") void add(@GuardSatisfied List this, @IndexOrHigh({"this"}) int index, E element); /** @@ -677,6 +691,8 @@ default void sort(Comparator c) { * ({@code index < 0 || index >= size()}) */ @ReleasesNoLocks + @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") E remove(@GuardSatisfied @CanShrink List this, @IndexFor({"this"}) int index); @@ -845,6 +861,8 @@ default Spliterator spliterator() { * @throws UnsupportedOperationException {@inheritDoc} * @since 21 */ + @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") default void addFirst(E e) { this.add(0, e); } @@ -859,6 +877,8 @@ default void addFirst(E e) { * @throws UnsupportedOperationException {@inheritDoc} * @since 21 */ + @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") default void addLast(E e) { this.add(e); } @@ -873,6 +893,7 @@ default void addLast(E e) { * @throws NoSuchElementException {@inheritDoc} * @since 21 */ + @Pure default E getFirst() { if (this.isEmpty()) { throw new NoSuchElementException(); @@ -891,6 +912,7 @@ default E getFirst() { * @throws NoSuchElementException {@inheritDoc} * @since 21 */ + @Pure default E getLast() { if (this.isEmpty()) { throw new NoSuchElementException(); @@ -910,6 +932,8 @@ default E getLast() { * @throws UnsupportedOperationException {@inheritDoc} * @since 21 */ + @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") default E removeFirst() { if (this.isEmpty()) { throw new NoSuchElementException(); @@ -929,6 +953,8 @@ default E removeFirst() { * @throws UnsupportedOperationException {@inheritDoc} * @since 21 */ + @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") default E removeLast() { if (this.isEmpty()) { throw new NoSuchElementException(); @@ -963,6 +989,7 @@ default List reversed() { * * @since 9 */ + @SideEffectFree @SuppressWarnings("unchecked") static List of() { return (List) ImmutableCollections.EMPTY_LIST; @@ -980,6 +1007,7 @@ static List of() { * * @since 9 */ + @SideEffectFree static @NonEmpty List of(E e1) { return new ImmutableCollections.List12<>(e1); } @@ -997,6 +1025,7 @@ static List of() { * * @since 9 */ + @SideEffectFree static @NonEmpty List of(E e1, E e2) { return new ImmutableCollections.List12<>(e1, e2); } @@ -1015,6 +1044,7 @@ static List of() { * * @since 9 */ + @SideEffectFree static @NonEmpty List of(E e1, E e2, E e3) { return ImmutableCollections.listFromTrustedArray(e1, e2, e3); } @@ -1034,6 +1064,7 @@ static List of() { * * @since 9 */ + @SideEffectFree static @NonEmpty List of(E e1, E e2, E e3, E e4) { return ImmutableCollections.listFromTrustedArray(e1, e2, e3, e4); } @@ -1054,6 +1085,7 @@ static List of() { * * @since 9 */ + @SideEffectFree static @NonEmpty List of(E e1, E e2, E e3, E e4, E e5) { return ImmutableCollections.listFromTrustedArray(e1, e2, e3, e4, e5); } @@ -1075,6 +1107,7 @@ static List of() { * * @since 9 */ + @SideEffectFree static @NonEmpty List of(E e1, E e2, E e3, E e4, E e5, E e6) { return ImmutableCollections.listFromTrustedArray(e1, e2, e3, e4, e5, e6); @@ -1098,6 +1131,7 @@ static List of() { * * @since 9 */ + @SideEffectFree static @NonEmpty List of(E e1, E e2, E e3, E e4, E e5, E e6, E e7) { return ImmutableCollections.listFromTrustedArray(e1, e2, e3, e4, e5, e6, e7); @@ -1122,6 +1156,7 @@ static List of() { * * @since 9 */ + @SideEffectFree static @NonEmpty List of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8) { return ImmutableCollections.listFromTrustedArray(e1, e2, e3, e4, e5, e6, e7, e8); @@ -1147,6 +1182,7 @@ static List of() { * * @since 9 */ + @SideEffectFree static @NonEmpty List of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9) { return ImmutableCollections.listFromTrustedArray(e1, e2, e3, e4, e5, e6, e7, e8, e9); @@ -1173,6 +1209,7 @@ static List of() { * * @since 9 */ + @SideEffectFree static @NonEmpty List of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10) { return ImmutableCollections.listFromTrustedArray(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10); @@ -1203,6 +1240,7 @@ static List of() { * * @since 9 */ + @SideEffectFree @SafeVarargs @SuppressWarnings("varargs") static @PolyNonEmpty List of(E @PolyNonEmpty... elements) { @@ -1236,6 +1274,7 @@ static List of() { * @throws NullPointerException if coll is null, or if it contains any nulls * @since 10 */ + @SideEffectFree static @PolyNonEmpty List copyOf(@PolyNonEmpty Collection coll) { return ImmutableCollections.listCopy(coll); } diff --git a/src/java.base/share/classes/java/util/PriorityQueue.java b/src/java.base/share/classes/java/util/PriorityQueue.java index 457babafd3556..db9a2eee59cae 100644 --- a/src/java.base/share/classes/java/util/PriorityQueue.java +++ b/src/java.base/share/classes/java/util/PriorityQueue.java @@ -551,6 +551,7 @@ public boolean hasNext() { } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty Itr this) { if (expectedModCount != modCount) throw new ConcurrentModificationException(); @@ -565,6 +566,7 @@ public E next(@NonEmpty Itr this) { throw new NoSuchElementException(); } + @DoesNotUnrefineReceiver("modifiability") public void remove() { if (expectedModCount != modCount) throw new ConcurrentModificationException(); diff --git a/src/java.base/share/classes/java/util/RegularEnumSet.java b/src/java.base/share/classes/java/util/RegularEnumSet.java index 0fe13bdab68c0..6c61c30a416ff 100644 --- a/src/java.base/share/classes/java/util/RegularEnumSet.java +++ b/src/java.base/share/classes/java/util/RegularEnumSet.java @@ -122,6 +122,7 @@ public boolean hasNext() { } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") @SuppressWarnings("unchecked") public E next(@NonEmpty EnumSetIterator this) { if (unseen == 0) diff --git a/src/java.base/share/classes/java/util/Scanner.java b/src/java.base/share/classes/java/util/Scanner.java index bf688f497b510..53366081d8ad0 100644 --- a/src/java.base/share/classes/java/util/Scanner.java +++ b/src/java.base/share/classes/java/util/Scanner.java @@ -41,6 +41,7 @@ import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.io.*; import java.math.*; @@ -1491,6 +1492,7 @@ public boolean hasNext(@GuardSatisfied Scanner this) { * @see java.util.Iterator */ @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public String next(@GuardSatisfied @NonEmpty Scanner this) { ensureOpen(); clearCaches(); @@ -1516,6 +1518,7 @@ public String next(@GuardSatisfied @NonEmpty Scanner this) { * @throws UnsupportedOperationException if this method is invoked. * @see java.util.Iterator */ + @DoesNotUnrefineReceiver("modifiability") public void remove(@GuardSatisfied Scanner this) { throw new UnsupportedOperationException(); } @@ -1554,6 +1557,7 @@ public boolean hasNext(@GuardSatisfied Scanner this, String pattern) { * @throws IllegalStateException if this scanner is closed */ @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public String next(@GuardSatisfied @NonEmpty Scanner this, String pattern) { return next(patternCache.forName(pattern)); } @@ -1605,6 +1609,7 @@ public boolean hasNext(@GuardSatisfied Scanner this, Pattern pattern) { * @throws IllegalStateException if this scanner is closed */ @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public String next(@GuardSatisfied @NonEmpty Scanner this, Pattern pattern) { ensureOpen(); if (pattern == null) diff --git a/src/java.base/share/classes/java/util/TreeMap.java b/src/java.base/share/classes/java/util/TreeMap.java index 4a19071d4d528..bb864ba367912 100644 --- a/src/java.base/share/classes/java/util/TreeMap.java +++ b/src/java.base/share/classes/java/util/TreeMap.java @@ -1341,6 +1341,7 @@ public SortedMap tailMap(@GuardSatisfied TreeMap this, K fromKey) { } @Override + @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { Entry p = getEntry(key); if (p!=null && Objects.equals(oldValue, p.value)) { @@ -1351,6 +1352,7 @@ public boolean replace(K key, V oldValue, V newValue) { } @Override + @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { Entry p = getEntry(key); if (p!=null) { @@ -1375,6 +1377,7 @@ public void forEach(BiConsumer action) { } @Override + @DoesNotUnrefineReceiver("modifiability") public void replaceAll(BiFunction function) { Objects.requireNonNull(function); int expectedModCount = modCount; @@ -1407,6 +1410,7 @@ public boolean contains(@UnknownSignedness Object o) { return TreeMap.this.containsValue(o); } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { for (Entry e = getFirstEntry(); e != null; e = successor(e)) { if (valEquals(e.getValue(), o)) { @@ -1417,6 +1421,7 @@ public boolean remove(@UnknownSignedness Object o) { return false; } + @DoesNotUnrefineReceiver("modifiability") public void clear() { TreeMap.this.clear(); } @@ -1443,6 +1448,7 @@ public boolean contains(@UnknownSignedness Object o) { return p != null && valEquals(p.getValue(), value); } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { if (!(o instanceof Map.Entry entry)) return false; @@ -1460,6 +1466,7 @@ public boolean remove(@UnknownSignedness Object o) { return TreeMap.this.size(); } + @DoesNotUnrefineReceiver("modifiability") public void clear() { TreeMap.this.clear(); } @@ -1513,6 +1520,7 @@ public Iterator descendingIterator() { @Pure @EnsuresNonEmptyIf(result = true, expression = "this") public boolean contains(@UnknownSignedness Object o) { return m.containsKey(o); } + @DoesNotUnrefineReceiver("modifiability") public void clear() { m.clear(); } public E lower(E e) { return m.lowerKey(e); } public E floor(E e) { return m.floorKey(e); } @@ -1529,6 +1537,7 @@ public E pollLast() { Map.Entry e = m.pollLastEntry(); return (e == null) ? null : e.getKey(); } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { int oldSize = size(); m.remove(o); @@ -1608,6 +1617,7 @@ final Entry prevEntry() { return e; } + @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastReturned == null) throw new IllegalStateException(); @@ -1626,6 +1636,7 @@ final class EntryIterator extends PrivateEntryIterator> { EntryIterator(Entry first) { super(first); } + @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(@NonEmpty EntryIterator this) { return nextEntry(); } @@ -1635,6 +1646,7 @@ final class ValueIterator extends PrivateEntryIterator { ValueIterator(Entry first) { super(first); } + @DoesNotUnrefineReceiver("modifiability") public V next(@NonEmpty ValueIterator this) { return nextEntry().value; } @@ -1644,6 +1656,7 @@ final class KeyIterator extends PrivateEntryIterator { KeyIterator(Entry first) { super(first); } + @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty KeyIterator this) { return nextEntry().key; } @@ -1653,9 +1666,11 @@ final class DescendingKeyIterator extends PrivateEntryIterator { DescendingKeyIterator(Entry first) { super(first); } + @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty DescendingKeyIterator this) { return prevEntry().key; } + @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastReturned == null) throw new IllegalStateException(); @@ -1904,24 +1919,28 @@ public final boolean containsKey(@UnknownSignedness Object key) { } @EnsuresKeyFor(value={"#1"}, map={"this"}) + @DoesNotUnrefineReceiver("modifiability") public final V put(K key, V value) { if (!inRange(key)) throw new IllegalArgumentException("key out of range"); return m.put(key, value); } + @DoesNotUnrefineReceiver("modifiability") public V putIfAbsent(K key, V value) { if (!inRange(key)) throw new IllegalArgumentException("key out of range"); return m.putIfAbsent(key, value); } + @DoesNotUnrefineReceiver("modifiability") public V merge(K key, V value, BiFunction remappingFunction) { if (!inRange(key)) throw new IllegalArgumentException("key out of range"); return m.merge(key, value, remappingFunction); } + @DoesNotUnrefineReceiver("modifiability") public V computeIfAbsent(K key, Function mappingFunction) { if (!inRange(key)) { // Do not throw if mapping function returns null @@ -1932,6 +1951,7 @@ public V computeIfAbsent(K key, Function mappingFunction return m.computeIfAbsent(key, mappingFunction); } + @DoesNotUnrefineReceiver("modifiability") public V compute(K key, BiFunction remappingFunction) { if (!inRange(key)) { // Do not throw if remapping function returns null @@ -1942,6 +1962,7 @@ public V compute(K key, BiFunction remappingF return m.compute(key, remappingFunction); } + @DoesNotUnrefineReceiver("modifiability") public V computeIfPresent(K key, BiFunction remappingFunction) { return !inRange(key) ? null : m.computeIfPresent(key, remappingFunction); } @@ -1950,6 +1971,7 @@ public final V get(Object key) { return !inRange(key) ? null : m.get(key); } + @DoesNotUnrefineReceiver("modifiability") public final V remove(Object key) { return !inRange(key) ? null : m.remove(key); } @@ -2095,6 +2117,7 @@ public boolean contains(@UnknownSignedness Object o) { valEquals(node.getValue(), entry.getValue()); } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { if (!(o instanceof Entry entry)) return false; @@ -2188,9 +2211,11 @@ final class SubMapEntryIterator extends SubMapIterator> { TreeMap.Entry fence) { super(first, fence); } + @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(@NonEmpty SubMapEntryIterator this) { return nextEntry(); } + @DoesNotUnrefineReceiver("modifiability") public void remove() { removeAscending(); } @@ -2202,9 +2227,11 @@ final class DescendingSubMapEntryIterator extends SubMapIterator> super(last, fence); } + @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(@NonEmpty DescendingSubMapEntryIterator this) { return prevEntry(); } + @DoesNotUnrefineReceiver("modifiability") public void remove() { removeDescending(); } @@ -2217,9 +2244,11 @@ final class SubMapKeyIterator extends SubMapIterator TreeMap.Entry fence) { super(first, fence); } + @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty SubMapKeyIterator this) { return nextEntry().key; } + @DoesNotUnrefineReceiver("modifiability") public void remove() { removeAscending(); } @@ -2255,9 +2284,11 @@ final class DescendingSubMapKeyIterator extends SubMapIterator TreeMap.Entry fence) { super(last, fence); } + @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty DescendingSubMapKeyIterator this) { return prevEntry().key; } + @DoesNotUnrefineReceiver("modifiability") public void remove() { removeDescending(); } diff --git a/src/java.base/share/classes/java/util/Vector.java b/src/java.base/share/classes/java/util/Vector.java index 3dc8ec166d3af..cc185bfae349d 100644 --- a/src/java.base/share/classes/java/util/Vector.java +++ b/src/java.base/share/classes/java/util/Vector.java @@ -1309,6 +1309,7 @@ public boolean hasNext() { } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty Itr this) { synchronized (Vector.this) { checkForComodification(); diff --git a/src/java.base/share/classes/java/util/WeakHashMap.java b/src/java.base/share/classes/java/util/WeakHashMap.java index e97c0c6c26c14..832b37d8d522f 100644 --- a/src/java.base/share/classes/java/util/WeakHashMap.java +++ b/src/java.base/share/classes/java/util/WeakHashMap.java @@ -875,18 +875,21 @@ public void remove() { } private class ValueIterator extends HashIterator { + @DoesNotUnrefineReceiver("modifiability") public V next(@NonEmpty ValueIterator this) { return nextEntry().value; } } private class KeyIterator extends HashIterator { + @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty KeyIterator this) { return nextEntry().getKey(); } } private class EntryIterator extends HashIterator> { + @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(@NonEmpty EntryIterator this) { return nextEntry(); } diff --git a/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java index 1500522d97dc9..866cc2fe11a9a 100644 --- a/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java @@ -1246,6 +1246,7 @@ private void noNext() { } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty Itr this) { final E e = nextItem; if (e == null) diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java index 5a17333b2e671..bc2aa9ab1d8f0 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java @@ -3511,6 +3511,7 @@ static final class KeyIterator extends BaseIterator super(tab, size, index, limit, map); } + @DoesNotUnrefineReceiver("modifiability") public final K next(@NonEmpty KeyIterator this) { Node p; if ((p = next) == null) @@ -3521,6 +3522,7 @@ public final K next(@NonEmpty KeyIterator this) { return k; } + @DoesNotUnrefineReceiver("modifiability") public final K nextElement(@NonEmpty KeyIterator this) { return next(); } } @@ -3531,6 +3533,7 @@ static final class ValueIterator extends BaseIterator super(tab, size, index, limit, map); } + @DoesNotUnrefineReceiver("modifiability") public final V next(@NonEmpty ValueIterator this) { Node p; if ((p = next) == null) @@ -3541,6 +3544,7 @@ public final V next(@NonEmpty ValueIterator this) { return v; } + @DoesNotUnrefineReceiver("modifiability") public final V nextElement(@NonEmpty ValueIterator this) { return next(); } } @@ -3551,6 +3555,7 @@ static final class EntryIterator extends BaseIterator super(tab, size, index, limit, map); } + @DoesNotUnrefineReceiver("modifiability") public final Map.Entry next(@NonEmpty EntryIterator this) { Node p; if ((p = next) == null) @@ -4894,6 +4899,7 @@ public boolean contains(@UnknownSignedness Object o) { (v == r || v.equals(r))); } + @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { Object k, v; Map.Entry e; return ((o instanceof Map.Entry) && diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java index 60e763281b85c..1c954fa07185e 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java @@ -1466,6 +1466,7 @@ public boolean hasNext() { } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty AbstractItr this) { E item = nextItem; if (item == null) throw new NoSuchElementException(); diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java index eabba33e783fe..131d03389196c 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java @@ -809,6 +809,7 @@ public boolean hasNext() { } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty Itr this) { final Node pred = nextNode; if (pred == null) throw new NoSuchElementException(); diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java index c477c5e819da8..416b19495c90c 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java @@ -2192,6 +2192,7 @@ public final void remove() { } final class ValueIterator extends Iter { + @DoesNotUnrefineReceiver("modifiability") public V next(@NonEmpty ValueIterator this) { V v; if ((v = nextValue) == null) @@ -2202,6 +2203,7 @@ public V next(@NonEmpty ValueIterator this) { } final class KeyIterator extends Iter { + @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty KeyIterator this) { Node n; if ((n = next) == null) @@ -2213,6 +2215,7 @@ public K next(@NonEmpty KeyIterator this) { } final class EntryIterator extends Iter> { + @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(@NonEmpty EntryIterator this) { Node n; if ((n = next) == null) @@ -3106,6 +3109,7 @@ public long estimateSize() { } final class SubMapValueIterator extends SubMapIter { + @DoesNotUnrefineReceiver("modifiability") public V next(@NonEmpty SubMapValueIterator this) { V v = nextValue; advance(); @@ -3117,6 +3121,7 @@ public int characteristics() { } final class SubMapKeyIterator extends SubMapIter { + @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty SubMapKeyIterator this) { Node n = next; advance(); @@ -3132,6 +3137,7 @@ public final Comparator getComparator() { } final class SubMapEntryIterator extends SubMapIter> { + @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(@NonEmpty SubMapEntryIterator this) { Node n = next; V v = nextValue; diff --git a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java index 4809969f14b02..1232f004e21ae 100644 --- a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java +++ b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java @@ -1228,6 +1228,7 @@ public boolean hasPrevious() { @SuppressWarnings("unchecked") @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty COWIterator this) { if (! hasNext()) throw new NoSuchElementException(); @@ -1757,6 +1758,7 @@ public boolean hasNext() { } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty COWSubListIterator this) { if (hasNext()) return it.next(); @@ -1839,6 +1841,7 @@ class DescendingIterator implements Iterator { } } public boolean hasNext() { return it.hasPrevious(); } + @DoesNotUnrefineReceiver("modifiability") public E next() { return it.previous(); } @DoesNotUnrefineReceiver("modifiability") public void remove() { it.remove(); } @@ -1861,6 +1864,7 @@ public boolean hasNext() { return it.hasPrevious(); } + @DoesNotUnrefineReceiver("modifiability") public E next() { return it.previous(); } @@ -1881,14 +1885,17 @@ public int previousIndex() { return nextIndex() - 1; } + @DoesNotUnrefineReceiver("modifiability") public void remove() { throw new UnsupportedOperationException(); } + @DoesNotUnrefineReceiver("modifiability") public void set(E e) { throw new UnsupportedOperationException(); } + @DoesNotUnrefineReceiver("modifiability") public void add(E e) { throw new UnsupportedOperationException(); } diff --git a/src/java.base/share/classes/java/util/concurrent/DelayQueue.java b/src/java.base/share/classes/java/util/concurrent/DelayQueue.java index b4d263d97f0b3..13c3544958ffd 100644 --- a/src/java.base/share/classes/java/util/concurrent/DelayQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/DelayQueue.java @@ -597,6 +597,7 @@ public boolean hasNext() { @SuppressWarnings("unchecked") @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty Itr this) { if (cursor >= array.length) throw new NoSuchElementException(); diff --git a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java index 686521594f7d2..0c44380329959 100644 --- a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java +++ b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java @@ -1144,6 +1144,7 @@ public boolean hasNext() { } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty AbstractItr this) { Node p; if ((p = next) == null) diff --git a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java index 1b2ffa1766d1c..ad5ed1b667712 100644 --- a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java @@ -820,6 +820,7 @@ public boolean hasNext() { } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty Itr this) { Node p; if ((p = next) == null) diff --git a/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java b/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java index 592377b9775e2..0b02f6cee7b31 100644 --- a/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java @@ -925,6 +925,7 @@ public final boolean hasNext() { } @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public final E next(@NonEmpty Itr this) { final Node p; if ((p = nextNode) == null) throw new NoSuchElementException(); diff --git a/src/java.base/share/classes/java/util/jar/Attributes.java b/src/java.base/share/classes/java/util/jar/Attributes.java index 02c4f6c37edfb..4630b1e44b571 100644 --- a/src/java.base/share/classes/java/util/jar/Attributes.java +++ b/src/java.base/share/classes/java/util/jar/Attributes.java @@ -34,6 +34,7 @@ import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; @@ -174,6 +175,7 @@ public String getValue(Name name) { * @throws ClassCastException if the name is not a Attributes.Name * or the value is not a String */ + @DoesNotUnrefineReceiver("modifiability") public Object put(Object name, Object value) { return map.put((Attributes.Name)name, (String)value); } @@ -205,6 +207,7 @@ public String putValue(String name, String value) { * @param name attribute name * @return the previous value of the attribute, or null if none */ + @DoesNotUnrefineReceiver("modifiability") public Object remove(@GuardSatisfied @Nullable @UnknownSignedness Object name) { return map.remove(name); } @@ -240,6 +243,7 @@ public boolean containsKey(@GuardSatisfied @Nullable @UnknownSignedness Object n * @param attr the Attributes to be stored in this map * @throws ClassCastException if attr is not an Attributes */ + @DoesNotUnrefineReceiver("modifiability") public void putAll(Map attr) { // ## javac bug? if (!Attributes.class.isInstance(attr)) @@ -251,6 +255,7 @@ public void putAll(Map attr) { /** * Removes all attributes from this Map. */ + @DoesNotUnrefineReceiver("modifiability") public void clear() { map.clear(); } diff --git a/src/java.base/share/classes/jdk/internal/org/objectweb/asm/tree/InsnList.java b/src/java.base/share/classes/jdk/internal/org/objectweb/asm/tree/InsnList.java index c81d8775f6705..a6038701a7242 100644 --- a/src/java.base/share/classes/jdk/internal/org/objectweb/asm/tree/InsnList.java +++ b/src/java.base/share/classes/jdk/internal/org/objectweb/asm/tree/InsnList.java @@ -60,6 +60,7 @@ package jdk.internal.org.objectweb.asm.tree; import org.checkerframework.dataflow.qual.Pure; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.ListIterator; import java.util.NoSuchElementException; import jdk.internal.org.objectweb.asm.MethodVisitor; @@ -543,6 +544,7 @@ public boolean hasNext() { } @Override + @DoesNotUnrefineReceiver("modifiability") public Object next() { if (nextInsn == null) { throw new NoSuchElementException(); @@ -555,6 +557,7 @@ public Object next() { } @Override + @DoesNotUnrefineReceiver("modifiability") public void remove() { if (remove != null) { if (remove == nextInsn) { @@ -609,6 +612,7 @@ public int previousIndex() { } @Override + @DoesNotUnrefineReceiver("modifiability") public void add(final Object o) { if (nextInsn != null) { InsnList.this.insertBefore(nextInsn, (AbstractInsnNode) o); @@ -622,6 +626,7 @@ public void add(final Object o) { } @Override + @DoesNotUnrefineReceiver("modifiability") public void set(final Object o) { if (remove != null) { InsnList.this.set(remove, (AbstractInsnNode) o); diff --git a/src/java.base/share/classes/sun/net/www/HeaderParser.java b/src/java.base/share/classes/sun/net/www/HeaderParser.java index ec69c47f035f3..2dc8d09fa18ac 100644 --- a/src/java.base/share/classes/sun/net/www/HeaderParser.java +++ b/src/java.base/share/classes/sun/net/www/HeaderParser.java @@ -27,6 +27,7 @@ import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.Iterator; import java.util.Locale; @@ -209,9 +210,11 @@ public boolean hasNext () { return index Date: Tue, 19 May 2026 09:02:05 -0700 Subject: [PATCH 06/15] More annotations --- .../share/classes/java/nio/file/Files.java | 2 +- .../classes/java/util/AbstractCollection.java | 8 +- .../share/classes/java/util/AbstractList.java | 20 ++- .../share/classes/java/util/AbstractMap.java | 18 ++- .../classes/java/util/AbstractQueue.java | 6 +- .../java/util/AbstractSequentialList.java | 6 +- .../share/classes/java/util/AbstractSet.java | 3 +- .../share/classes/java/util/ArrayDeque.java | 26 +++- .../share/classes/java/util/ArrayList.java | 30 ++++- .../share/classes/java/util/Collection.java | 9 +- .../share/classes/java/util/Collections.java | 127 +++++++++++++++++- .../share/classes/java/util/Deque.java | 26 +++- .../share/classes/java/util/EnumMap.java | 17 ++- .../share/classes/java/util/EnumSet.java | 6 +- .../share/classes/java/util/HashMap.java | 20 ++- .../share/classes/java/util/HashSet.java | 4 +- .../share/classes/java/util/Hashtable.java | 19 ++- .../classes/java/util/IdentityHashMap.java | 22 ++- .../share/classes/java/util/Iterator.java | 3 +- .../share/classes/java/util/JumboEnumSet.java | 12 +- .../classes/java/util/LinkedHashMap.java | 32 ++++- .../classes/java/util/LinkedHashSet.java | 8 +- .../share/classes/java/util/LinkedList.java | 57 +++++++- .../share/classes/java/util/ListIterator.java | 6 +- .../share/classes/java/util/Map.java | 11 +- .../share/classes/java/util/NavigableMap.java | 4 +- .../share/classes/java/util/NavigableSet.java | 9 +- .../classes/java/util/PrimitiveIterator.java | 8 +- .../classes/java/util/PriorityQueue.java | 11 +- .../share/classes/java/util/Properties.java | 18 ++- .../share/classes/java/util/Queue.java | 7 +- .../classes/java/util/RegularEnumSet.java | 12 +- .../share/classes/java/util/Scanner.java | 1 + .../java/util/SequencedCollection.java | 5 + .../share/classes/java/util/SequencedMap.java | 8 ++ .../share/classes/java/util/SequencedSet.java | 1 + .../share/classes/java/util/SortedMap.java | 5 +- .../share/classes/java/util/SortedSet.java | 8 +- .../share/classes/java/util/Stack.java | 4 +- .../share/classes/java/util/TreeMap.java | 40 +++++- .../share/classes/java/util/TreeSet.java | 13 +- .../share/classes/java/util/Vector.java | 24 +++- .../share/classes/java/util/WeakHashMap.java | 16 ++- .../util/concurrent/ArrayBlockingQueue.java | 17 ++- .../java/util/concurrent/BlockingDeque.java | 26 +++- .../java/util/concurrent/BlockingQueue.java | 11 +- .../util/concurrent/ConcurrentHashMap.java | 33 ++++- .../concurrent/ConcurrentLinkedDeque.java | 25 +++- .../concurrent/ConcurrentLinkedQueue.java | 12 +- .../java/util/concurrent/ConcurrentMap.java | 8 +- .../concurrent/ConcurrentSkipListMap.java | 39 +++++- .../concurrent/ConcurrentSkipListSet.java | 8 +- .../util/concurrent/CopyOnWriteArrayList.java | 61 ++++++++- .../util/concurrent/CopyOnWriteArraySet.java | 9 +- .../java/util/concurrent/DelayQueue.java | 15 ++- .../util/concurrent/LinkedBlockingDeque.java | 39 +++++- .../util/concurrent/LinkedBlockingQueue.java | 16 ++- .../util/concurrent/LinkedTransferQueue.java | 20 ++- .../concurrent/PriorityBlockingQueue.java | 17 ++- .../util/concurrent/SynchronousQueue.java | 14 +- .../classes/java/util/jar/Attributes.java | 4 + 61 files changed, 1008 insertions(+), 58 deletions(-) diff --git a/src/java.base/share/classes/java/nio/file/Files.java b/src/java.base/share/classes/java/nio/file/Files.java index be49e03ea0b7c..829edd4b494c6 100644 --- a/src/java.base/share/classes/java/nio/file/Files.java +++ b/src/java.base/share/classes/java/nio/file/Files.java @@ -30,13 +30,13 @@ import org.checkerframework.checker.mustcall.qual.MustCall; import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf; import org.checkerframework.checker.nonempty.qual.NonEmpty; +import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.PolySigned; 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.DoesNotUnrefineReceiver; -import org.checkerframework.checker.nullness.qual.Nullable; import java.io.BufferedReader; import java.io.BufferedWriter; diff --git a/src/java.base/share/classes/java/util/AbstractCollection.java b/src/java.base/share/classes/java/util/AbstractCollection.java index 5a67a347ba449..5e168fd6153bc 100644 --- a/src/java.base/share/classes/java/util/AbstractCollection.java +++ b/src/java.base/share/classes/java/util/AbstractCollection.java @@ -35,11 +35,11 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import jdk.internal.util.ArraysSupport; @@ -276,6 +276,7 @@ private static T[] finishToArray(T[] r, Iterator it) { * @throws IllegalArgumentException {@inheritDoc} * @throws IllegalStateException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(@GuardSatisfied AbstractCollection this, E e) { throw new UnsupportedOperationException(); @@ -298,6 +299,7 @@ public boolean add(@GuardSatisfied AbstractCollection this, E e) { * @throws ClassCastException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @CanShrink AbstractCollection this, @GuardSatisfied @UnknownSignedness Object o) { Iterator it = iterator(); @@ -362,6 +364,7 @@ public boolean containsAll(@GuardSatisfied AbstractCollection this, @GuardSat * * @see #add(Object) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@GuardSatisfied AbstractCollection this, Collection c) { boolean modified = false; @@ -393,6 +396,7 @@ public boolean addAll(@GuardSatisfied AbstractCollection this, Collection this, Collection c) { Objects.requireNonNull(c); @@ -429,6 +433,7 @@ public boolean removeAll(@GuardSatisfied @CanShrink AbstractCollection this, * @see #remove(Object) * @see #contains(Object) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(@GuardSatisfied @CanShrink AbstractCollection this, Collection c) { Objects.requireNonNull(c); @@ -459,6 +464,7 @@ public boolean retainAll(@GuardSatisfied @CanShrink AbstractCollection this, * * @throws UnsupportedOperationException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink AbstractCollection this) { Iterator it = iterator(); diff --git a/src/java.base/share/classes/java/util/AbstractList.java b/src/java.base/share/classes/java/util/AbstractList.java index 25c5017e2128a..a3a5164664790 100644 --- a/src/java.base/share/classes/java/util/AbstractList.java +++ b/src/java.base/share/classes/java/util/AbstractList.java @@ -37,12 +37,12 @@ import org.checkerframework.checker.nonempty.qual.PolyNonEmpty; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; 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; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.function.Consumer; @@ -132,6 +132,7 @@ protected AbstractList() { * prevents it from being added to this list */ @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(@GuardSatisfied AbstractList this, E e) { add(size(), e); @@ -159,6 +160,7 @@ public boolean add(@GuardSatisfied AbstractList this, E e) { * @throws IllegalArgumentException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E set(@GuardSatisfied AbstractList this, @IndexFor({"this"}) int index, E element) { throw new UnsupportedOperationException(); @@ -177,6 +179,7 @@ public E set(@GuardSatisfied AbstractList this, @IndexFor({"this"}) int index * @throws IllegalArgumentException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(@GuardSatisfied AbstractList this, @IndexOrHigh({"this"}) int index, E element) { throw new UnsupportedOperationException(); @@ -192,6 +195,7 @@ public void add(@GuardSatisfied AbstractList this, @IndexOrHigh({"this"}) int * @throws UnsupportedOperationException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @CanShrink AbstractList this, @IndexFor({"this"}) int index) { throw new UnsupportedOperationException(); @@ -271,6 +275,7 @@ public E remove(@GuardSatisfied @CanShrink AbstractList this, @IndexFor({"thi * @throws UnsupportedOperationException if the {@code clear} operation * is not supported by this list */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink AbstractList this) { removeRange(0, size()); @@ -296,6 +301,7 @@ public void clear(@GuardSatisfied @CanShrink AbstractList this) { * @throws IllegalArgumentException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@GuardSatisfied AbstractList this, @IndexOrHigh({"this"}) int index, Collection c) { rangeCheckForAdd(index); @@ -417,6 +423,7 @@ public E next(@NonEmpty Itr this) { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastRet < 0) @@ -470,6 +477,7 @@ public int previousIndex() { return cursor-1; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void set(E e) { if (lastRet < 0) @@ -484,6 +492,7 @@ public void set(E e) { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(E e) { checkForComodification(); @@ -636,6 +645,7 @@ public int hashCode(@GuardSatisfied AbstractList this) { * @param fromIndex index of first element to be removed * @param toIndex index after last element to be removed */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") protected void removeRange(@GuardSatisfied @CanShrink AbstractList this, @IndexOrHigh({"this"}) int fromIndex, @IndexOrHigh({"this"}) int toIndex) { ListIterator it = listIterator(fromIndex); @@ -820,6 +830,7 @@ protected SubList(SubList parent, int fromIndex, int toIndex) { this.modCount = root.modCount; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E set(int index, E element) { Objects.checkIndex(index, size); @@ -839,6 +850,7 @@ public int size() { return size; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(int index, E element) { rangeCheckForAdd(index); @@ -847,6 +859,7 @@ public void add(int index, E element) { updateSizeAndModCount(1); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(int index) { Objects.checkIndex(index, size); @@ -862,11 +875,13 @@ protected void removeRange(int fromIndex, int toIndex) { updateSizeAndModCount(fromIndex - toIndex); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { return addAll(size, c); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(int index, Collection c) { rangeCheckForAdd(index); @@ -929,17 +944,20 @@ public int previousIndex() { return i.previousIndex() - offset; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { i.remove(); updateSizeAndModCount(-1); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void set(E e) { i.set(e); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(E e) { i.add(e); diff --git a/src/java.base/share/classes/java/util/AbstractMap.java b/src/java.base/share/classes/java/util/AbstractMap.java index 9a2da50fbb0e0..96141b8ee8dfd 100644 --- a/src/java.base/share/classes/java/util/AbstractMap.java +++ b/src/java.base/share/classes/java/util/AbstractMap.java @@ -35,12 +35,12 @@ import org.checkerframework.checker.nullness.qual.KeyFor; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; 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; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.stream.Stream; import java.util.function.Consumer; @@ -238,6 +238,7 @@ public boolean containsKey(@GuardSatisfied AbstractMap this, @GuardSatisfi */ @ReleasesNoLocks @EnsuresKeyFor(value={"#1"}, map={"this"}) + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V put(@GuardSatisfied AbstractMap this, K key, V value) { throw new UnsupportedOperationException(); @@ -265,6 +266,7 @@ public boolean containsKey(@GuardSatisfied AbstractMap this, @GuardSatisfi * @throws ClassCastException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V remove(@GuardSatisfied AbstractMap this, @GuardSatisfied @UnknownSignedness Object key) { Iterator> i = entrySet().iterator(); @@ -311,6 +313,7 @@ public boolean containsKey(@GuardSatisfied AbstractMap this, @GuardSatisfi * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putAll(@GuardSatisfied AbstractMap this, Map m) { for (Map.Entry e : m.entrySet()) @@ -329,6 +332,7 @@ public void putAll(@GuardSatisfied AbstractMap this, Map this) { entrySet().clear(); @@ -401,6 +405,7 @@ public K next(/*@NonEmpty Iterator this*/) { return i.next().getKey(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { i.remove(); @@ -419,6 +424,7 @@ public boolean isEmpty() { return AbstractMap.this.isEmpty(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { AbstractMap.this.clear(); @@ -471,6 +477,7 @@ public V next(/*@NonEmpty Iterator this*/) { return i.next().getValue(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { i.remove(); @@ -489,6 +496,7 @@ public boolean isEmpty() { return AbstractMap.this.isEmpty(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { AbstractMap.this.clear(); @@ -729,6 +737,7 @@ public V getValue(AbstractMap.@GuardSatisfied SimpleEntry this) { * @param value new value to be stored in this entry * @return the old value corresponding to the entry */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V setValue(AbstractMap.@GuardSatisfied SimpleEntry this, V value) { V oldValue = this.value; @@ -973,10 +982,13 @@ public String toString(AbstractMap.@GuardSatisfied SimpleImmutableEntry th UnsupportedOperationException uoe() { return new UnsupportedOperationException(); } abstract Collection view(); + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E t) { throw uoe(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { throw uoe(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { view().clear(); } public boolean contains(Object o) { return view().contains(o); } @@ -985,12 +997,16 @@ public String toString(AbstractMap.@GuardSatisfied SimpleImmutableEntry th public boolean isEmpty() { return view().isEmpty(); } public Iterator iterator() { return view().iterator(); } public Stream parallelStream() { return view().parallelStream(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(Object o) { return view().remove(o); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { return view().removeAll(c); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { return view().removeIf(filter); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { return view().retainAll(c); } public int size() { return view().size(); } diff --git a/src/java.base/share/classes/java/util/AbstractQueue.java b/src/java.base/share/classes/java/util/AbstractQueue.java index 8afc291dcb068..7f487df7ff363 100644 --- a/src/java.base/share/classes/java/util/AbstractQueue.java +++ b/src/java.base/share/classes/java/util/AbstractQueue.java @@ -39,8 +39,8 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nonempty.qual.EnsuresNonEmpty; import org.checkerframework.checker.nonempty.qual.NonEmpty; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; /** * This class provides skeletal implementations of some {@link Queue} @@ -100,6 +100,7 @@ protected AbstractQueue() { * prevents it from being added to this queue */ @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(@GuardSatisfied AbstractQueue this, E e) { if (offer(e)) @@ -119,6 +120,7 @@ public boolean add(@GuardSatisfied AbstractQueue this, E e) { * @return the head of this queue * @throws NoSuchElementException if this queue is empty */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @NonEmpty @CanShrink AbstractQueue this) { E x = poll(); @@ -154,6 +156,7 @@ public E element(@GuardSatisfied @NonEmpty AbstractQueue this) { *

This implementation repeatedly invokes {@link #poll poll} until it * returns {@code null}. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink AbstractQueue this) { while (poll() != null) @@ -189,6 +192,7 @@ public void clear(@GuardSatisfied @CanShrink AbstractQueue this) { * this time due to insertion restrictions * @see #add(Object) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@GuardSatisfied AbstractQueue this, Collection c) { if (c == null) diff --git a/src/java.base/share/classes/java/util/AbstractSequentialList.java b/src/java.base/share/classes/java/util/AbstractSequentialList.java index 1a00705398f3d..865cca704a925 100644 --- a/src/java.base/share/classes/java/util/AbstractSequentialList.java +++ b/src/java.base/share/classes/java/util/AbstractSequentialList.java @@ -29,11 +29,11 @@ import org.checkerframework.checker.index.qual.PolyGrowShrink; import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nonempty.qual.PolyNonEmpty; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; /** * This class provides a skeletal implementation of the {@code List} @@ -125,6 +125,7 @@ public E get(@GuardSatisfied AbstractSequentialList this, int index) { * @throws IllegalArgumentException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E set(@GuardSatisfied AbstractSequentialList this, int index, E element) { try { @@ -157,6 +158,7 @@ public E set(@GuardSatisfied AbstractSequentialList this, int index, E elemen * @throws IllegalArgumentException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(@GuardSatisfied AbstractSequentialList this, int index, E element) { try { @@ -183,6 +185,7 @@ public void add(@GuardSatisfied AbstractSequentialList this, int index, E ele * @throws UnsupportedOperationException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @CanShrink AbstractSequentialList this, int index) { try { @@ -227,6 +230,7 @@ public E remove(@GuardSatisfied @CanShrink AbstractSequentialList this, int i * @throws IllegalArgumentException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@GuardSatisfied AbstractSequentialList this, int index, Collection c) { try { diff --git a/src/java.base/share/classes/java/util/AbstractSet.java b/src/java.base/share/classes/java/util/AbstractSet.java index 3438244dd7a31..ce10698e69de6 100644 --- a/src/java.base/share/classes/java/util/AbstractSet.java +++ b/src/java.base/share/classes/java/util/AbstractSet.java @@ -28,10 +28,10 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; /** * This class provides a skeletal implementation of the {@code Set} @@ -175,6 +175,7 @@ public int hashCode(@GuardSatisfied AbstractSet this) { * @see #remove(Object) * @see #contains(Object) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(@GuardSatisfied AbstractSet this, Collection c) { Objects.requireNonNull(c); diff --git a/src/java.base/share/classes/java/util/ArrayDeque.java b/src/java.base/share/classes/java/util/ArrayDeque.java index a66c580f0b128..e611f0ba13360 100644 --- a/src/java.base/share/classes/java/util/ArrayDeque.java +++ b/src/java.base/share/classes/java/util/ArrayDeque.java @@ -48,11 +48,11 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; 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.DoesNotUnrefineReceiver; import java.io.Serializable; import java.util.function.Consumer; @@ -302,6 +302,7 @@ static final E nonNullElementAt(@PolyNull @PolySigned Object[] es, int i) { * @param e the element to add * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addFirst(@GuardSatisfied ArrayDeque this, E e) { if (e == null) @@ -320,6 +321,7 @@ public void addFirst(@GuardSatisfied ArrayDeque this, E e) { * @param e the element to add * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addLast(@GuardSatisfied ArrayDeque this, E e) { if (e == null) @@ -340,6 +342,7 @@ public void addLast(@GuardSatisfied ArrayDeque this, E e) { * @throws NullPointerException if the specified collection or any * of its elements are null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { final int s, needed; @@ -360,6 +363,7 @@ private void copyElements(Collection c) { * @return {@code true} (as specified by {@link Deque#offerFirst}) * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offerFirst(E e) { addFirst(e); @@ -373,6 +377,7 @@ public boolean offerFirst(E e) { * @return {@code true} (as specified by {@link Deque#offerLast}) * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offerLast(E e) { addLast(e); @@ -382,6 +387,7 @@ public boolean offerLast(E e) { /** * @throws NoSuchElementException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeFirst(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { E e = pollFirst(); @@ -393,6 +399,7 @@ public E removeFirst(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { /** * @throws NoSuchElementException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeLast(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { E e = pollLast(); @@ -401,6 +408,7 @@ public E removeLast(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { return e; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollFirst(@GuardSatisfied @CanShrink ArrayDeque this) { final Object[] es; @@ -413,6 +421,7 @@ public E removeLast(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { return e; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollLast(@GuardSatisfied @CanShrink ArrayDeque this) { final Object[] es; @@ -467,6 +476,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 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeFirstOccurrence(@GuardSatisfied @CanShrink ArrayDeque this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { if (o != null) { @@ -496,6 +506,7 @@ public boolean removeFirstOccurrence(@GuardSatisfied @CanShrink ArrayDeque th * @param o element to be removed from this deque, if present * @return {@code true} if the deque contained the specified element */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeLastOccurrence(@GuardSatisfied @CanShrink ArrayDeque this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { if (o != null) { @@ -525,6 +536,7 @@ public boolean removeLastOccurrence(@GuardSatisfied @CanShrink ArrayDeque thi * @throws NullPointerException if the specified element is null */ @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(@GuardSatisfied ArrayDeque this, E e) { addLast(e); @@ -540,6 +552,7 @@ public boolean add(@GuardSatisfied ArrayDeque this, E e) { * @return {@code true} (as specified by {@link Queue#offer}) * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(@GuardSatisfied ArrayDeque this, E e) { return offerLast(e); @@ -556,6 +569,7 @@ public boolean offer(@GuardSatisfied ArrayDeque this, E e) { * @return the head of the queue represented by this deque * @throws NoSuchElementException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { return removeFirst(); @@ -571,6 +585,7 @@ public E remove(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { * @return the head of the queue represented by this deque, or * {@code null} if this deque is empty */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink ArrayDeque this) { return pollFirst(); @@ -615,6 +630,7 @@ public E element(@GuardSatisfied @NonEmpty ArrayDeque this) { * @param e the element to push * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void push(@GuardSatisfied ArrayDeque this, E e) { addFirst(e); @@ -630,6 +646,7 @@ public void push(@GuardSatisfied ArrayDeque this, E e) { * of the stack represented by this deque) * @throws NoSuchElementException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E pop(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { return removeFirst(); @@ -759,6 +776,7 @@ void postDelete(boolean leftShifted) { cursor = dec(cursor, elements.length); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void remove() { if (lastRet < 0) @@ -793,6 +811,7 @@ public void forEachRemaining(Consumer action) { private class DescendingIterator extends DeqIterator { DescendingIterator() { cursor = dec(tail, elements.length); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final E next(@NonEmpty DescendingIterator this) { if (remaining <= 0) @@ -949,6 +968,7 @@ public void forEach(Consumer action) { /** * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink ArrayDeque this, Predicate filter) { Objects.requireNonNull(filter); @@ -958,6 +978,7 @@ public boolean removeIf(@CanShrink ArrayDeque this, Predicate filt /** * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(@CanShrink ArrayDeque this, Collection c) { Objects.requireNonNull(c); @@ -967,6 +988,7 @@ public boolean removeAll(@CanShrink ArrayDeque this, Collection this, Collection c) { Objects.requireNonNull(c); @@ -1084,6 +1106,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 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @CanShrink ArrayDeque this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { return removeFirstOccurrence(o); @@ -1093,6 +1116,7 @@ public boolean remove(@GuardSatisfied @CanShrink ArrayDeque this, @GuardSatis * Removes all of the elements from this deque. * The deque will be empty after this call returns. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink ArrayDeque this) { circularClear(elements, head, tail); diff --git a/src/java.base/share/classes/java/util/ArrayList.java b/src/java.base/share/classes/java/util/ArrayList.java index 38dc47cd960ec..1594dbae39c07 100644 --- a/src/java.base/share/classes/java/util/ArrayList.java +++ b/src/java.base/share/classes/java/util/ArrayList.java @@ -40,12 +40,12 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; 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; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.function.Consumer; import java.util.function.Predicate; @@ -534,6 +534,7 @@ private void add(E e, Object[] elementData, int s) { */ @SideEffectsOnly("this") @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(@GuardSatisfied ArrayList this, E e) { modCount++; @@ -571,6 +572,7 @@ public void add(@GuardSatisfied ArrayList this, @NonNegative int index, E ele * * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addFirst(E element) { add(0, element); @@ -581,6 +583,7 @@ public void addFirst(E element) { * * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addLast(E element) { add(element); @@ -595,6 +598,7 @@ public void addLast(E element) { * @return the element that was removed from the list * @throws IndexOutOfBoundsException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @CanShrink ArrayList this, @NonNegative int index) { Objects.checkIndex(index, size); @@ -612,6 +616,7 @@ public E remove(@GuardSatisfied @CanShrink ArrayList this, @NonNegative int i * @throws NoSuchElementException {@inheritDoc} * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeFirst() { if (size == 0) { @@ -630,6 +635,7 @@ public E removeFirst() { * @throws NoSuchElementException {@inheritDoc} * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeLast() { int last = size - 1; @@ -745,6 +751,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 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @CanShrink ArrayList this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { final Object[] es = elementData; @@ -782,6 +789,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. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink ArrayList this) { modCount++; @@ -928,6 +936,7 @@ private static String outOfBoundsMsg(int fromIndex, int toIndex) { * or if the specified collection is null * @see Collection#contains(Object) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(@CanShrink ArrayList this, Collection c) { return batchRemove(c, false, 0, size); @@ -949,6 +958,7 @@ public boolean removeAll(@CanShrink ArrayList this, Collection this, Collection c) { return batchRemove(c, true, 0, size); @@ -1123,6 +1133,7 @@ public E next(@NonEmpty Itr this) { return (E) elementData[lastRet = i]; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastRet < 0) @@ -1177,17 +1188,20 @@ public boolean hasPrevious() { return cursor != 0; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int nextIndex() { return cursor; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int previousIndex() { return cursor - 1; } @SuppressWarnings("unchecked") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E previous() { checkForComodification(); @@ -1201,6 +1215,7 @@ public E previous() { return (E) elementData[lastRet = i]; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void set(E e) { if (lastRet < 0) @@ -1214,6 +1229,7 @@ public void set(E e) { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(E e) { checkForComodification(); @@ -1259,6 +1275,7 @@ public void add(E e) { * @throws IndexOutOfBoundsException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @PolyGrowShrink List subList(@GuardSatisfied @PolyGrowShrink ArrayList this, @NonNegative int fromIndex, @NonNegative int toIndex) { subListRangeCheck(fromIndex, toIndex, size); @@ -1293,6 +1310,7 @@ private SubList(SubList parent, int fromIndex, int toIndex) { this.modCount = parent.modCount; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E set(@NonNegative int index, E element) { Objects.checkIndex(index, size); @@ -1314,6 +1332,7 @@ public E get(@NonNegative int index) { return size; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(@NonNegative int index, E element) { rangeCheckForAdd(index); @@ -1322,6 +1341,7 @@ public void add(@NonNegative int index, E element) { updateSizeAndModCount(1); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(@NonNegative int index) { Objects.checkIndex(index, size); @@ -1331,6 +1351,7 @@ public E remove(@NonNegative int index) { return result; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") protected void removeRange(int fromIndex, int toIndex) { checkForComodification(); @@ -1338,11 +1359,13 @@ protected void removeRange(int fromIndex, int toIndex) { updateSizeAndModCount(fromIndex - toIndex); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { return addAll(this.size, c); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@NonNegative int index, Collection c) { rangeCheckForAdd(index); @@ -1360,11 +1383,13 @@ public void replaceAll(UnaryOperator operator) { root.replaceAllRange(operator, offset, offset + size); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { return batchRemove(c, false); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { return batchRemove(c, true); @@ -1380,6 +1405,7 @@ private boolean batchRemove(Collection c, boolean complement) { return modified; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { checkForComodification(); @@ -1831,6 +1857,7 @@ private static boolean isClear(long[] bits, int i) { * @throws NullPointerException {@inheritDoc} */ @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink ArrayList this, Predicate filter) { return removeIf(filter, 0, size); @@ -1894,6 +1921,7 @@ private void replaceAllRange(UnaryOperator operator, int i, int end) { @Override @SuppressWarnings("unchecked") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void sort(Comparator c) { final int expectedModCount = modCount; diff --git a/src/java.base/share/classes/java/util/Collection.java b/src/java.base/share/classes/java/util/Collection.java index ec63a3537ca0e..ad33f9063f9ca 100644 --- a/src/java.base/share/classes/java/util/Collection.java +++ b/src/java.base/share/classes/java/util/Collection.java @@ -37,11 +37,11 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.function.IntFunction; import java.util.function.Predicate; @@ -489,6 +489,7 @@ default T[] toArray(IntFunction generator) { * time due to insertion restrictions */ @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean add(@GuardSatisfied Collection this, E e); @@ -512,6 +513,7 @@ default T[] toArray(IntFunction generator) { * @throws UnsupportedOperationException if the {@code remove} operation * is not supported by this collection */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean remove(@GuardSatisfied @CanShrink Collection this, @UnknownSignedness Object o); @@ -565,6 +567,7 @@ default T[] toArray(IntFunction generator) { * this time due to insertion restrictions * @see #add(Object) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean addAll(@GuardSatisfied Collection this, Collection c); @@ -591,6 +594,7 @@ default T[] toArray(IntFunction generator) { * @see #remove(Object) * @see #contains(Object) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean removeAll(@GuardSatisfied @CanShrink Collection this, Collection c); @@ -616,6 +620,7 @@ default T[] toArray(IntFunction generator) { * supported. * @since 1.8 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default boolean removeIf(@CanShrink Collection this, Predicate filter) { Objects.requireNonNull(filter); @@ -652,6 +657,7 @@ default boolean removeIf(@CanShrink Collection this, Predicate fil * @see #remove(Object) * @see #contains(Object) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean retainAll(@GuardSatisfied @CanShrink Collection this, Collection c); @@ -662,6 +668,7 @@ default boolean removeIf(@CanShrink Collection this, Predicate fil * @throws UnsupportedOperationException if the {@code clear} operation * is not supported by this collection */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void clear(@GuardSatisfied @CanShrink Collection this); diff --git a/src/java.base/share/classes/java/util/Collections.java b/src/java.base/share/classes/java/util/Collections.java index 9cebd4abae61f..ac24514affeff 100644 --- a/src/java.base/share/classes/java/util/Collections.java +++ b/src/java.base/share/classes/java/util/Collections.java @@ -43,12 +43,12 @@ import org.checkerframework.common.value.qual.ArrayLen; import org.checkerframework.common.value.qual.MinLen; import org.checkerframework.common.value.qual.StaticallyExecutable; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; 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; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.io.IOException; import java.io.ObjectInputStream; @@ -1126,6 +1126,7 @@ static class UnmodifiableCollection implements Collection, Serializable { @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(/*@NonEmpty Iterator this*/) {return i.next();} + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { throw new UnsupportedOperationException(); @@ -1139,11 +1140,13 @@ public void forEachRemaining(Consumer action) { }; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresNonEmpty("this") public boolean add(E e) { throw new UnsupportedOperationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { throw new UnsupportedOperationException(); @@ -1153,18 +1156,22 @@ public boolean remove(@UnknownSignedness Object o) { public boolean containsAll(Collection coll) { return c.containsAll(coll); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection coll) { throw new UnsupportedOperationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection coll) { throw new UnsupportedOperationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection coll) { throw new UnsupportedOperationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { throw new UnsupportedOperationException(); @@ -1177,6 +1184,7 @@ public void forEach(Consumer action) { c.forEach(action); } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { throw new UnsupportedOperationException(); @@ -1189,12 +1197,14 @@ public Spliterator spliterator() { } @SuppressWarnings("unchecked") @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Stream stream() { return (Stream)c.stream(); } @SuppressWarnings("unchecked") @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Stream parallelStream() { return (Stream)c.parallelStream(); @@ -1253,16 +1263,19 @@ private SequencedCollection sc() { // Even though this wrapper class is serializable, the reversed view is effectively // not serializable because it points to the reversed collection view, which usually isn't // serializable. + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public SequencedCollection reversed() { return new UnmodifiableSequencedCollection<>(sc().reversed()); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { throw new UnsupportedOperationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { throw new UnsupportedOperationException(); @@ -1276,11 +1289,13 @@ public E getLast() { return sc().getLast(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeFirst() { throw new UnsupportedOperationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeLast() { throw new UnsupportedOperationException(); @@ -1369,6 +1384,7 @@ private SequencedSet ss() { // Even though this wrapper class is serializable, the reversed view is effectively // not serializable because it points to the reversed set view, which usually isn't // serializable. + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public SequencedSet reversed() { return new UnmodifiableSequencedSet<>(ss().reversed()); @@ -1415,14 +1431,17 @@ static class UnmodifiableSortedSet public Comparator comparator() {return ss.comparator();} + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public SortedSet subSet(E fromElement, E toElement) { return new UnmodifiableSortedSet<>(ss.subSet(fromElement,toElement)); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public SortedSet headSet(E toElement) { return new UnmodifiableSortedSet<>(ss.headSet(toElement)); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public SortedSet tailSet(E fromElement) { return new UnmodifiableSortedSet<>(ss.tailSet(fromElement)); @@ -1505,29 +1524,36 @@ public EmptyNavigableSet() { public E floor(E e) { return ns.floor(e); } public E ceiling(E e) { return ns.ceiling(e); } public E higher(E e) { return ns.higher(e); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E pollFirst() { throw new UnsupportedOperationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E pollLast() { throw new UnsupportedOperationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public NavigableSet descendingSet() { return new UnmodifiableNavigableSet<>(ns.descendingSet()); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Iterator descendingIterator() { return descendingSet().iterator(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public NavigableSet subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive) { return new UnmodifiableNavigableSet<>( ns.subSet(fromElement, fromInclusive, toElement, toInclusive)); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public NavigableSet headSet(E toElement, boolean inclusive) { return new UnmodifiableNavigableSet<>( ns.headSet(toElement, inclusive)); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public NavigableSet tailSet(E fromElement, boolean inclusive) { return new UnmodifiableNavigableSet<>( @@ -1582,20 +1608,24 @@ static class UnmodifiableList extends UnmodifiableCollection public int hashCode() {return list.hashCode();} public E get(int index) {return list.get(index);} + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E set(int index, E element) { throw new UnsupportedOperationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(int index, E element) { throw new UnsupportedOperationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(int index) { throw new UnsupportedOperationException(); } public int indexOf(Object o) {return list.indexOf(o);} public int lastIndexOf(Object o) {return list.lastIndexOf(o);} + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(int index, Collection c) { throw new UnsupportedOperationException(); @@ -1607,6 +1637,7 @@ public void replaceAll(UnaryOperator operator) { throw new UnsupportedOperationException(); } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void sort(Comparator c) { throw new UnsupportedOperationException(); @@ -1614,6 +1645,7 @@ public void sort(Comparator c) { public @PolyGrowShrink @PolyNonEmpty ListIterator listIterator(@PolyGrowShrink @PolyNonEmpty UnmodifiableList this) {return listIterator(0);} + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public ListIterator listIterator(final int index) { return new ListIterator<>() { @@ -1633,14 +1665,17 @@ public ListIterator listIterator(final int index) { public int nextIndex() {return i.nextIndex();} public int previousIndex() {return i.previousIndex();} + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { throw new UnsupportedOperationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void set(E e) { throw new UnsupportedOperationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(E e) { throw new UnsupportedOperationException(); @@ -1760,19 +1795,23 @@ private static class UnmodifiableMap implements Map, Serializable { public boolean containsValue(@UnknownSignedness Object val) {return m.containsValue(val);} public V get(Object key) {return m.get(key);} + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresKeyFor(value={"#1"}, map={"this"}) public V put(K key, V value) { throw new UnsupportedOperationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V remove(Object key) { throw new UnsupportedOperationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putAll(Map m) { throw new UnsupportedOperationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { throw new UnsupportedOperationException(); @@ -1825,6 +1864,7 @@ public void replaceAll(BiFunction function) { throw new UnsupportedOperationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresKeyFor(value={"#1"}, map={"this"}) @Override @@ -1833,18 +1873,21 @@ public V putIfAbsent(K key, V value) { } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object key, @UnknownSignedness Object value) { throw new UnsupportedOperationException(); } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { throw new UnsupportedOperationException(); } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { throw new UnsupportedOperationException(); @@ -1989,6 +2032,7 @@ public boolean hasNext() { public Map.Entry next(/*@NonEmpty Iterator> this*/) { return new UnmodifiableEntry<>(i.next()); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { throw new UnsupportedOperationException(); @@ -2143,21 +2187,25 @@ public SequencedMap reversed() { return new UnmodifiableSequencedMap<>(sm().reversed()); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Entry pollFirstEntry() { throw new UnsupportedOperationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Entry pollLastEntry() { throw new UnsupportedOperationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putFirst(K k, V v) { throw new UnsupportedOperationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putLast(K k, V v) { throw new UnsupportedOperationException(); @@ -2347,9 +2395,11 @@ public Entry lastEntry() { : null; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Entry pollFirstEntry() { throw new UnsupportedOperationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Entry pollLastEntry() { throw new UnsupportedOperationException(); } @@ -2473,11 +2523,13 @@ public Iterator iterator() { return c.iterator(); // Must be manually synched by user! } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresNonEmpty("this") public boolean add(E e) { synchronized (mutex) {return c.add(e);} } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { synchronized (mutex) {return c.remove(o);} @@ -2487,18 +2539,22 @@ public boolean remove(@UnknownSignedness Object o) { public boolean containsAll(Collection coll) { synchronized (mutex) {return c.containsAll(coll);} } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection coll) { synchronized (mutex) {return c.addAll(coll);} } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection coll) { synchronized (mutex) {return c.removeAll(coll);} } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection coll) { synchronized (mutex) {return c.retainAll(coll);} } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { synchronized (mutex) {c.clear();} @@ -2512,6 +2568,7 @@ public void forEach(Consumer consumer) { synchronized (mutex) {c.forEach(consumer);} } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { synchronized (mutex) {return c.removeIf(filter);} @@ -2761,8 +2818,10 @@ static class SynchronizedNavigableSet public E floor(E e) { synchronized (mutex) {return ns.floor(e);} } public E ceiling(E e) { synchronized (mutex) {return ns.ceiling(e);} } public E higher(E e) { synchronized (mutex) {return ns.higher(e);} } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E pollFirst() { synchronized (mutex) {return ns.pollFirst();} } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E pollLast() { synchronized (mutex) {return ns.pollLast();} } @@ -2882,14 +2941,17 @@ public int hashCode() { public E get(int index) { synchronized (mutex) {return list.get(index);} } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E set(int index, E element) { synchronized (mutex) {return list.set(index, element);} } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(int index, E element) { synchronized (mutex) {list.add(index, element);} } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(int index) { synchronized (mutex) {return list.remove(index);} @@ -2902,6 +2964,7 @@ public int lastIndexOf(Object o) { synchronized (mutex) {return list.lastIndexOf(o);} } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(int index, Collection c) { synchronized (mutex) {return list.addAll(index, c);} @@ -2928,6 +2991,7 @@ public void replaceAll(UnaryOperator operator) { synchronized (mutex) {list.replaceAll(operator);} } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void sort(Comparator c) { synchronized (mutex) {list.sort(c);} @@ -3069,19 +3133,23 @@ public V get(Object key) { synchronized (mutex) {return m.get(key);} } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresKeyFor(value={"#1"}, map={"this"}) public V put(K key, V value) { synchronized (mutex) {return m.put(key, value);} } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V remove(Object key) { synchronized (mutex) {return m.remove(key);} } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putAll(Map map) { synchronized (mutex) {m.putAll(map);} } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { synchronized (mutex) {m.clear();} @@ -3143,6 +3211,7 @@ public void forEach(BiConsumer action) { public void replaceAll(BiFunction function) { synchronized (mutex) {m.replaceAll(function);} } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresKeyFor(value={"#1"}, map={"this"}) @Override @@ -3150,16 +3219,19 @@ public V putIfAbsent(K key, V value) { synchronized (mutex) {return m.putIfAbsent(key, value);} } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object key, @UnknownSignedness Object value) { synchronized (mutex) {return m.remove(key, value);} } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { synchronized (mutex) {return m.replace(key, oldValue, newValue);} } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { synchronized (mutex) {return m.replace(key, value);} @@ -3393,9 +3465,11 @@ public Entry firstEntry() { synchronized (mutex) { return nm.firstEntry(); } } public Entry lastEntry() { synchronized (mutex) { return nm.lastEntry(); } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Entry pollFirstEntry() { synchronized (mutex) { return nm.pollFirstEntry(); } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Entry pollLastEntry() { synchronized (mutex) { return nm.pollLastEntry(); } } @@ -3588,8 +3662,10 @@ private String badElementMsg(Object o) { public @Nullable T[] toArray(@PolyNull T[] a) { return c.toArray(a); } public T[] toArray(IntFunction f) { return c.toArray(f); } public String toString() { return c.toString(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { return c.remove(o); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { c.clear(); } @@ -3597,10 +3673,12 @@ private String badElementMsg(Object o) { public boolean containsAll(Collection coll) { return c.containsAll(coll); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection coll) { return c.removeAll(coll); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection coll) { return c.retainAll(coll); @@ -3618,6 +3696,7 @@ public Iterator iterator() { @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(/*@NonEmpty Iterator this*/) { return it.next(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { it.remove(); } public void forEachRemaining(Consumer action) { @@ -3626,6 +3705,7 @@ public void forEachRemaining(Consumer action) { }; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresNonEmpty("this") public boolean add(E e) { return c.add(typeCheck(e)); } @@ -3661,6 +3741,7 @@ Collection checkedCopyOf(Collection coll) { return (Collection) Arrays.asList(a); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection coll) { // Doing things this way insulates us from concurrent changes @@ -3674,6 +3755,7 @@ public boolean addAll(Collection coll) { @Override public void forEach(Consumer action) {c.forEach(action);} @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { return c.removeIf(filter); @@ -3742,10 +3824,13 @@ static class CheckedQueue public int hashCode() {return c.hashCode();} @Pure public E peek() {return queue.peek();} + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E poll() {return queue.poll();} + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove() {return queue.remove();} + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) {return queue.offer(typeCheck(e));} } @@ -3998,21 +4083,25 @@ static class CheckedList public boolean equals(Object o) { return o == this || list.equals(o); } public int hashCode() { return list.hashCode(); } public E get(int index) { return list.get(index); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(int index) { return list.remove(index); } public int indexOf(Object o) { return list.indexOf(o); } public int lastIndexOf(Object o) { return list.lastIndexOf(o); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E set(int index, E element) { return list.set(index, typeCheck(element)); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(int index, E element) { list.add(index, typeCheck(element)); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(int index, Collection c) { return list.addAll(index, checkedCopyOf(c)); @@ -4033,14 +4122,17 @@ public ListIterator listIterator(final int index) { public E previous() { return i.previous(); } public int nextIndex() { return i.nextIndex(); } public int previousIndex() { return i.previousIndex(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { i.remove(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void set(E e) { i.set(typeCheck(e)); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(E e) { i.add(typeCheck(e)); @@ -4073,6 +4165,7 @@ public void replaceAll(UnaryOperator operator) { } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void sort(Comparator c) { list.sort(c); @@ -4202,8 +4295,10 @@ private String badValueMsg(Object value) { @Pure public boolean containsValue(@UnknownSignedness Object v) { return m.containsValue(v); } public V get(Object key) { return m.get(key); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V remove(Object key) { return m.remove(key); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { m.clear(); } public Set keySet() { return m.keySet(); } @@ -4212,6 +4307,7 @@ private String badValueMsg(Object value) { public int hashCode() { return m.hashCode(); } public String toString() { return m.toString(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresKeyFor(value={"#1"}, map={"this"}) public V put(K key, V value) { @@ -4219,6 +4315,7 @@ public V put(K key, V value) { return m.put(key, value); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @SuppressWarnings("unchecked") public void putAll(Map t) { @@ -4262,6 +4359,7 @@ public void replaceAll(BiFunction function) { m.replaceAll(typeCheck(function)); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresKeyFor(value={"#1"}, map={"this"}) @Override @@ -4271,12 +4369,14 @@ public V putIfAbsent(K key, V value) { } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object key, @UnknownSignedness Object value) { return m.remove(key, value); } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { typeCheck(key, newValue); @@ -4284,6 +4384,7 @@ public boolean replace(K key, V oldValue, V newValue) { } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { typeCheck(key, value); @@ -4310,7 +4411,6 @@ public V replace(K key, V value) { } @Override - @DoesNotUnrefineReceiver("modifiability") public @PolyNull V compute(K key, BiFunction remappingFunction) { return m.compute(key, typeCheck(remappingFunction)); @@ -4352,14 +4452,17 @@ static class CheckedEntrySet implements Set> { public boolean isEmpty() { return s.isEmpty(); } public String toString() { return s.toString(); } public int hashCode() { return s.hashCode(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { s.clear(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresNonEmpty("this") public boolean add(Map.Entry e) { throw new UnsupportedOperationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection> coll) { throw new UnsupportedOperationException(); @@ -4376,6 +4479,7 @@ public Iterator> iterator() { @DoesNotUnrefineReceiver("modifiability") public void remove() { i.remove(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(/*@NonEmpty Iterator> this*/) { return checkedEntry(i.next(), valueType); @@ -4452,6 +4556,7 @@ public boolean containsAll(Collection c) { return true; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { if (!(o instanceof Map.Entry)) @@ -4460,10 +4565,12 @@ public boolean remove(@UnknownSignedness Object o) { <>((Map.Entry)o)); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { return batchRemove(c, false); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { return batchRemove(c, true); @@ -4731,6 +4838,7 @@ public Entry lastEntry() { : null; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Entry pollFirstEntry() { Entry entry = nm.pollFirstEntry(); @@ -4739,6 +4847,7 @@ public Entry pollFirstEntry() { : new CheckedMap.CheckedEntrySet.CheckedEntry<>(entry, valueType); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Entry pollLastEntry() { Entry entry = nm.pollLastEntry(); @@ -4838,6 +4947,7 @@ private static class EmptyIterator implements Iterator { @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty EmptyIterator this) { throw new NoSuchElementException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove(@NonEmpty EmptyIterator this) { throw new IllegalStateException(); } @Override @@ -4889,8 +4999,10 @@ private static class EmptyListIterator public E previous() { throw new NoSuchElementException(); } public int nextIndex() { return 0; } public int previousIndex() { return -1; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void set(E e) { throw new IllegalStateException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(E e) { throw new UnsupportedOperationException(); } } @@ -5308,6 +5420,7 @@ public void replaceAll(BiFunction function) { Objects.requireNonNull(function); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresKeyFor(value={"#1"}, map={"this"}) @Override @@ -5316,18 +5429,21 @@ public V putIfAbsent(K key, V value) { } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object key, @UnknownSignedness Object value) { throw new UnsupportedOperationException(); } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { throw new UnsupportedOperationException(); } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { throw new UnsupportedOperationException(); @@ -5399,6 +5515,7 @@ public E next(/*@NonEmpty Iterator this*/) { } throw new NoSuchElementException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { throw new UnsupportedOperationException(); @@ -5498,6 +5615,7 @@ public Spliterator spliterator() { return singletonSpliterator(element); } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { throw new UnsupportedOperationException(); @@ -5562,6 +5680,7 @@ public void forEach(Consumer action) { action.accept(element); } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { throw new UnsupportedOperationException(); @@ -5674,6 +5793,7 @@ public void replaceAll(BiFunction function) { throw new UnsupportedOperationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresKeyFor(value={"#1"}, map={"this"}) @Override @@ -5682,18 +5802,21 @@ public V putIfAbsent(K key, V value) { } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object key, @UnknownSignedness Object value) { throw new UnsupportedOperationException(); } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { throw new UnsupportedOperationException(); } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { throw new UnsupportedOperationException(); diff --git a/src/java.base/share/classes/java/util/Deque.java b/src/java.base/share/classes/java/util/Deque.java index 2ff8351cdd270..ecac591a51941 100644 --- a/src/java.base/share/classes/java/util/Deque.java +++ b/src/java.base/share/classes/java/util/Deque.java @@ -45,11 +45,11 @@ import org.checkerframework.checker.nonempty.qual.PolyNonEmpty; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; /** * A linear collection that supports element insertion and removal at @@ -238,6 +238,7 @@ public interface Deque extends Queue, SequencedCollection { * element prevents it from being added to this deque */ @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void addFirst(@GuardSatisfied Deque this, E e); @@ -261,6 +262,7 @@ public interface Deque extends Queue, SequencedCollection { * element prevents it from being added to this deque */ @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void addLast(@GuardSatisfied Deque this, E e); @@ -280,6 +282,7 @@ public interface Deque extends Queue, SequencedCollection { * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean offerFirst(E e); @@ -299,6 +302,7 @@ public interface Deque extends Queue, SequencedCollection { * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean offerLast(E e); @@ -310,6 +314,7 @@ public interface Deque extends Queue, SequencedCollection { * @return the head of this deque * @throws NoSuchElementException if this deque is empty */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E removeFirst(@GuardSatisfied @NonEmpty @CanShrink Deque this); @@ -321,6 +326,7 @@ public interface Deque extends Queue, SequencedCollection { * @return the tail of this deque * @throws NoSuchElementException if this deque is empty */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E removeLast(@GuardSatisfied @NonEmpty @CanShrink Deque this); @@ -330,6 +336,7 @@ public interface Deque extends Queue, SequencedCollection { * * @return the head of this deque, or {@code null} if this deque is empty */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E pollFirst(@GuardSatisfied @CanShrink Deque this); @@ -339,6 +346,7 @@ public interface Deque extends Queue, SequencedCollection { * * @return the tail of this deque, or {@code null} if this deque is empty */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E pollLast(@GuardSatisfied @CanShrink Deque this); @@ -371,6 +379,7 @@ public interface Deque extends Queue, SequencedCollection { * * @return the head of this deque, or {@code null} if this deque is empty */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E peekFirst(); @@ -380,6 +389,7 @@ public interface Deque extends Queue, SequencedCollection { * * @return the tail of this deque, or {@code null} if this deque is empty */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E peekLast(); @@ -400,6 +410,7 @@ public interface Deque extends Queue, SequencedCollection { * deque does not permit null elements * ({@linkplain Collection##optional-restrictions optional}) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean removeFirstOccurrence(@GuardSatisfied @CanShrink Deque this, Object o); @@ -420,6 +431,7 @@ public interface Deque extends Queue, SequencedCollection { * deque does not permit null elements * ({@linkplain Collection##optional-restrictions optional}) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean removeLastOccurrence(@GuardSatisfied @CanShrink Deque this, Object o); @@ -448,6 +460,7 @@ public interface Deque extends Queue, SequencedCollection { * element prevents it from being added to this deque */ @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean add(@GuardSatisfied Deque this, E e); @@ -472,6 +485,7 @@ public interface Deque extends Queue, SequencedCollection { * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean offer(E e); @@ -486,6 +500,7 @@ public interface Deque extends Queue, SequencedCollection { * @return the head of the queue represented by this deque * @throws NoSuchElementException if this deque is empty */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E remove(@GuardSatisfied @NonEmpty @CanShrink Deque this); @@ -499,6 +514,7 @@ public interface Deque extends Queue, SequencedCollection { * @return the first element of this deque, or {@code null} if * this deque is empty */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E poll(@GuardSatisfied @CanShrink Deque this); @@ -513,6 +529,7 @@ public interface Deque extends Queue, SequencedCollection { * @return the head of the queue represented by this deque * @throws NoSuchElementException if this deque is empty */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E element(@GuardSatisfied @NonEmpty Deque this); @@ -526,6 +543,7 @@ public interface Deque extends Queue, SequencedCollection { * @return the head of the queue represented by this deque, or * {@code null} if this deque is empty */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E peek(); @@ -553,6 +571,7 @@ public interface Deque extends Queue, SequencedCollection { * @throws IllegalArgumentException if some property of an element of the * specified collection prevents it from being added to this deque */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean addAll(Collection c); @@ -576,6 +595,7 @@ public interface Deque extends Queue, SequencedCollection { * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void push(@GuardSatisfied Deque this, E e); @@ -589,6 +609,7 @@ public interface Deque extends Queue, SequencedCollection { * of the stack represented by this deque) * @throws NoSuchElementException if this deque is empty */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E pop(@GuardSatisfied @NonEmpty @CanShrink Deque this); @@ -614,6 +635,7 @@ public interface Deque extends Queue, SequencedCollection { * deque does not permit null elements * ({@linkplain Collection##optional-restrictions optional}) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean remove(@GuardSatisfied @CanShrink Deque this, @UnknownSignedness Object o); @@ -660,6 +682,7 @@ public interface Deque extends Queue, SequencedCollection { * @return an iterator over the elements in this deque in reverse * sequence */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") Iterator descendingIterator(); @@ -673,6 +696,7 @@ public interface Deque extends Queue, SequencedCollection { * @return a reverse-ordered view of this collection, as a {@code Deque} * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default Deque reversed() { return ReverseOrderDequeView.of(this); diff --git a/src/java.base/share/classes/java/util/EnumMap.java b/src/java.base/share/classes/java/util/EnumMap.java index 9beff052a8feb..cf7d7956c7895 100644 --- a/src/java.base/share/classes/java/util/EnumMap.java +++ b/src/java.base/share/classes/java/util/EnumMap.java @@ -37,11 +37,11 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.nullness.qual.RequiresNonNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import jdk.internal.access.SharedSecrets; @@ -287,6 +287,7 @@ private boolean containsMapping(@GuardSatisfied @UnknownSignedness Object key, @ * @throws NullPointerException if the specified key is null */ @EnsuresKeyFor(value={"#1"}, map={"this"}) + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V put(K key, V value) { typeCheck(key); @@ -308,6 +309,7 @@ private boolean containsMapping(@GuardSatisfied @UnknownSignedness Object key, @ * return can also indicate that the map previously associated * {@code null} with the specified key.) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V remove(@GuardSatisfied @UnknownSignedness Object key) { if (!isValidKey(key)) @@ -361,6 +363,7 @@ private boolean isValidKey(@GuardSatisfied @UnknownSignedness Object key) { "and vals are private class members for EnumMap and are absent in AbstractMap."}) @SuppressWarnings({"nullness:contracts.precondition.override.invalid"}) @RequiresNonNull({"keyUniverse", "vals"}) + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putAll(@UnknownInitialization EnumMap this, Map m) { if (m instanceof EnumMap em) { @@ -386,6 +389,7 @@ public void putAll(@UnknownInitialization EnumMap this, Map iterator() { public boolean contains(@Nullable @UnknownSignedness Object o) { return containsKey(o); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { int oldSize = size; EnumMap.this.remove(o); return size != oldSize; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { EnumMap.this.clear(); @@ -478,6 +484,7 @@ public Iterator iterator() { public boolean contains(@Nullable @UnknownSignedness Object o) { return containsValue(o); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { o = maskNull(o); @@ -491,6 +498,7 @@ public boolean remove(@Nullable @UnknownSignedness Object o) { } return false; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { EnumMap.this.clear(); @@ -527,6 +535,7 @@ public boolean contains(@Nullable @UnknownSignedness Object o) { return o instanceof Map.Entry entry && containsMapping(entry.getKey(), entry.getValue()); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { return o instanceof Map.Entry entry @@ -536,6 +545,7 @@ public boolean remove(@Nullable @UnknownSignedness Object o) { public @NonNegative int size() { return size; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { EnumMap.this.clear(); @@ -589,6 +599,7 @@ public boolean hasNext() { return index != vals.length; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { checkLastReturnedIndex(); @@ -607,6 +618,7 @@ private void checkLastReturnedIndex() { } private class KeyIterator extends EnumMapIterator { + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty KeyIterator this) { if (!hasNext()) @@ -620,6 +632,7 @@ private class ValueIterator extends EnumMapIterator { @CFComment({"nullness: Value returned by unmaskNull", "will be of type V (not @Nullable V) for mapped value"}) @SuppressWarnings({"nullness:return"}) + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V next(@NonEmpty ValueIterator this) { if (!hasNext()) @@ -632,6 +645,7 @@ public V next(@NonEmpty ValueIterator this) { private class EntryIterator extends EnumMapIterator> { private Entry lastReturnedEntry; + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(@NonEmpty EntryIterator this) { if (!hasNext()) @@ -640,6 +654,7 @@ public Map.Entry next(@NonEmpty EntryIterator this) { return lastReturnedEntry; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { lastReturnedIndex = diff --git a/src/java.base/share/classes/java/util/EnumSet.java b/src/java.base/share/classes/java/util/EnumSet.java index 1abbfa1b40db5..c9df90a2e86b9 100644 --- a/src/java.base/share/classes/java/util/EnumSet.java +++ b/src/java.base/share/classes/java/util/EnumSet.java @@ -26,8 +26,8 @@ package java.util; import org.checkerframework.checker.nullness.qual.Nullable; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import jdk.internal.access.SharedSecrets; @@ -145,6 +145,7 @@ public static > EnumSet allOf(Class elementType) { * Adds all of the elements from the appropriate enum type to this enum * set, which is empty prior to the call. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") abstract void addAll(); @@ -377,6 +378,7 @@ public static > EnumSet range(E from, E to) { * Adds the specified range to this enum set, which is empty prior * to the call. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") abstract void addRange(E from, E to); @@ -386,6 +388,7 @@ public static > EnumSet range(E from, E to) { * @return a copy of this set */ @SuppressWarnings("unchecked") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public EnumSet clone() { try { @@ -398,6 +401,7 @@ public EnumSet clone() { /** * Complements the contents of this enum set. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") abstract void complement(); diff --git a/src/java.base/share/classes/java/util/HashMap.java b/src/java.base/share/classes/java/util/HashMap.java index 20d58faf38ab2..f0cd011923ee3 100644 --- a/src/java.base/share/classes/java/util/HashMap.java +++ b/src/java.base/share/classes/java/util/HashMap.java @@ -37,12 +37,12 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; 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; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.io.IOException; import java.io.InvalidObjectException; @@ -319,6 +319,7 @@ public final int hashCode() { return Objects.hashCode(key) ^ Objects.hashCode(value); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final V setValue(V newValue) { V oldValue = value; @@ -642,6 +643,7 @@ public boolean containsKey(@GuardSatisfied HashMap this, @GuardSatisfied @ * previously associated {@code null} with {@code key}.) */ @EnsuresKeyFor(value={"#1"}, map={"this"}) + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V put(@GuardSatisfied HashMap this, K key, V value) { return putVal(hash(key), key, value, false, true); @@ -817,6 +819,7 @@ else if ((e = tab[index = (n - 1) & hash]) != null) { * @param m mappings to be stored in this map * @throws NullPointerException if the specified map is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putAll(@GuardSatisfied HashMap this, Map m) { putMapEntries(m, true); @@ -831,6 +834,7 @@ public void putAll(@GuardSatisfied HashMap this, Map this, @GuardSatisfied @Nullable @UnknownSignedness Object key) { Node e; @@ -893,6 +897,7 @@ else if (node == p) * Removes all of the mappings from this map. * The map will be empty after this call returns. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied HashMap this) { Node[] tab; @@ -1023,6 +1028,7 @@ T[] valuesToArray(T[] a) { final class KeySet extends AbstractSet { @Pure public final @NonNegative int size() { return size; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void clear() { HashMap.this.clear(); } @SideEffectFree @@ -1030,6 +1036,7 @@ final class KeySet extends AbstractSet { @Pure @EnsuresNonEmptyIf(result = true, expression = "this") public final boolean contains(@Nullable @UnknownSignedness Object o) { return containsKey(o); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final boolean remove(@Nullable @UnknownSignedness Object key) { return removeNode(hash(key), key, null, false, true) != null; @@ -1092,6 +1099,7 @@ public Collection values(@GuardSatisfied HashMap this) { final class Values extends AbstractCollection { @Pure public final @NonNegative int size() { return size; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void clear() { HashMap.this.clear(); } @SideEffectFree @@ -1153,6 +1161,7 @@ public final void forEach(Consumer action) { final class EntrySet extends AbstractSet> { @Pure public final @NonNegative int size() { return size; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void clear() { HashMap.this.clear(); } @SideEffectFree @@ -1168,6 +1177,7 @@ public final boolean contains(@Nullable @UnknownSignedness Object o) { Node candidate = getNode(key); return candidate != null && candidate.equals(e); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final boolean remove(@Nullable @UnknownSignedness Object o) { if (o instanceof Map.Entry e) { @@ -1209,18 +1219,21 @@ public V getOrDefault(@GuardSatisfied @Nullable @UnknownSignedness Object key, V @EnsuresKeyFor(value={"#1"}, map={"this"}) @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V putIfAbsent(K key, V value) { return putVal(hash(key), key, value, true, true); } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @Nullable @UnknownSignedness Object key, @GuardSatisfied @Nullable @UnknownSignedness Object value) { return removeNode(hash(key), key, value, true, true) != null; } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { Node e; V v; @@ -1234,6 +1247,7 @@ public boolean replace(K key, V oldValue, V newValue) { } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V replace(K key, V value) { Node e; @@ -1686,6 +1700,7 @@ final Node nextNode(@NonEmpty HashIterator this) { return e; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void remove() { Node p = current; @@ -1701,18 +1716,21 @@ public final void remove() { final class KeyIterator extends HashIterator implements Iterator { + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final K next(@NonEmpty KeyIterator this) { return nextNode().key; } } final class ValueIterator extends HashIterator implements Iterator { + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final V next(@NonEmpty ValueIterator this) { return nextNode().value; } } final class EntryIterator extends HashIterator implements Iterator> { + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final Map.Entry next(@NonEmpty EntryIterator this) { return nextNode(); } } diff --git a/src/java.base/share/classes/java/util/HashSet.java b/src/java.base/share/classes/java/util/HashSet.java index 69e3196eb0e56..57d49ac0d8937 100644 --- a/src/java.base/share/classes/java/util/HashSet.java +++ b/src/java.base/share/classes/java/util/HashSet.java @@ -35,11 +35,11 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; 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.DoesNotUnrefineReceiver; import java.io.InvalidObjectException; import jdk.internal.access.SharedSecrets; @@ -250,6 +250,7 @@ public boolean contains(@GuardSatisfied HashSet this, @GuardSatisfied @Nullab */ @SideEffectsOnly("this") @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(@GuardSatisfied HashSet this, E e) { return map.put(e, PRESENT)==null; @@ -398,6 +399,7 @@ private void readObject(java.io.ObjectInputStream s) * @return a {@code Spliterator} over the elements in this set * @since 1.8 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Spliterator spliterator() { return new HashMap.KeySpliterator<>(map, 0, -1, 0, 0); diff --git a/src/java.base/share/classes/java/util/Hashtable.java b/src/java.base/share/classes/java/util/Hashtable.java index 32bcf3d84f47c..9c0a8c135e8c7 100644 --- a/src/java.base/share/classes/java/util/Hashtable.java +++ b/src/java.base/share/classes/java/util/Hashtable.java @@ -37,12 +37,12 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; 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; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.io.*; import java.util.function.BiConsumer; @@ -501,6 +501,7 @@ private void addEntry(int hash, K key, V value, int index) { * @see #get(Object) */ @EnsuresKeyFor(value={"#1"}, map={"this"}) + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized @Nullable V put(@GuardSatisfied Hashtable this, K key, V value) { // Make sure the value is not null @@ -535,6 +536,7 @@ private void addEntry(int hash, K key, V value, int index) { * or {@code null} if the key did not have a mapping * @throws NullPointerException if the key is {@code null} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized @Nullable V remove(@GuardSatisfied Hashtable this, @GuardSatisfied @UnknownSignedness Object key) { Entry tab[] = table; @@ -568,6 +570,7 @@ private void addEntry(int hash, K key, V value, int index) { * @throws NullPointerException if the specified map is null * @since 1.2 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized void putAll(@GuardSatisfied Hashtable this, Map t) { for (Map.Entry e : t.entrySet()) @@ -577,6 +580,7 @@ public synchronized void putAll(@GuardSatisfied Hashtable this, Map this) { Entry tab[] = table; @@ -715,10 +719,12 @@ public Iterator iterator() { public boolean contains(@UnknownSignedness Object o) { return containsKey(o); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { return Hashtable.this.remove(o) != null; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { Hashtable.this.clear(); @@ -755,6 +761,7 @@ public Iterator> iterator() { } @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(Map.Entry o) { return super.add(o); @@ -776,6 +783,7 @@ public boolean contains(@UnknownSignedness Object o) { return false; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { if (!(o instanceof Map.Entry entry)) @@ -808,6 +816,7 @@ public boolean remove(@UnknownSignedness Object o) { return count; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { Hashtable.this.clear(); @@ -851,6 +860,7 @@ public Iterator iterator() { public boolean contains(@UnknownSignedness Object o) { return containsValue(o); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { Hashtable.this.clear(); @@ -986,6 +996,7 @@ public synchronized void replaceAll(BiFunction this) { Entry et = entry; @@ -1579,6 +1595,7 @@ public T next(@NonEmpty Enumerator this) { return nextElement(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (!iterator) diff --git a/src/java.base/share/classes/java/util/IdentityHashMap.java b/src/java.base/share/classes/java/util/IdentityHashMap.java index ab875f1b85be1..2f1598b507c4e 100644 --- a/src/java.base/share/classes/java/util/IdentityHashMap.java +++ b/src/java.base/share/classes/java/util/IdentityHashMap.java @@ -35,12 +35,12 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; 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; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; @@ -458,6 +458,7 @@ private boolean containsMapping(@UnknownSignedness @GuardSatisfied @Nullable Obj * @see #containsKey(Object) */ @EnsuresKeyFor(value={"#1"}, map={"this"}) + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V put(@GuardSatisfied IdentityHashMap this, K key, V value) { final Object k = maskNull(key); @@ -540,6 +541,7 @@ private boolean resize(int newCapacity) { * @param m mappings to be stored in this map * @throws NullPointerException if the specified map is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putAll(@GuardSatisfied IdentityHashMap this, Map m) { int n = m.size(); @@ -563,6 +565,7 @@ public void putAll(@GuardSatisfied IdentityHashMap this, Map this, @GuardSatisfied @Nullable @UnknownSignedness Object key) { Object k = maskNull(key); @@ -660,6 +663,7 @@ private void closeDeletion(int d) { * Removes all of the mappings from this map. * The map will be empty after this call returns. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied IdentityHashMap this) { modCount++; @@ -800,6 +804,7 @@ protected int nextIndex(@NonEmpty IdentityHashMapIterator this) { return lastReturnedIndex; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastReturnedIndex == -1) @@ -881,6 +886,7 @@ public void remove() { private class KeyIterator extends IdentityHashMapIterator { @SuppressWarnings("unchecked") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty KeyIterator this) { return (K) unmaskNull(traversalTable[nextIndex()]); @@ -889,6 +895,7 @@ public K next(@NonEmpty KeyIterator this) { private class ValueIterator extends IdentityHashMapIterator { @SuppressWarnings("unchecked") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V next(@NonEmpty ValueIterator this) { return (V) traversalTable[nextIndex() + 1]; @@ -900,12 +907,14 @@ private class EntryIterator { private Entry lastReturnedEntry; + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(@NonEmpty EntryIterator this) { lastReturnedEntry = new Entry(nextIndex()); return lastReturnedEntry; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { lastReturnedIndex = @@ -935,6 +944,7 @@ public V getValue() { } @SuppressWarnings("unchecked") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V setValue(V value) { checkIndexForEntryUse(); @@ -1049,6 +1059,7 @@ public Iterator iterator() { public boolean contains(@Nullable @UnknownSignedness Object o) { return containsKey(o); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { int oldSize = size; @@ -1060,6 +1071,7 @@ public boolean remove(@Nullable @UnknownSignedness Object o) { * the former contains an optimization that results in incorrect * behavior when c is a smaller "normal" (non-identity-based) Set. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { Objects.requireNonNull(c); @@ -1072,6 +1084,7 @@ public boolean removeAll(Collection c) { } return modified; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { IdentityHashMap.this.clear(); @@ -1166,6 +1179,7 @@ public Iterator iterator() { public boolean contains(@Nullable @UnknownSignedness Object o) { return containsValue(o); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { for (Iterator i = iterator(); i.hasNext(); ) { @@ -1176,6 +1190,7 @@ public boolean remove(@Nullable @UnknownSignedness Object o) { } return false; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { IdentityHashMap.this.clear(); @@ -1279,6 +1294,7 @@ public boolean contains(@Nullable @UnknownSignedness Object o) { return o instanceof Entry entry && containsMapping(entry.getKey(), entry.getValue()); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { return o instanceof Entry entry @@ -1288,6 +1304,7 @@ public boolean remove(@Nullable @UnknownSignedness Object o) { public @NonNegative int size() { return size; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { IdentityHashMap.this.clear(); @@ -1297,6 +1314,7 @@ public void clear() { * the former contains an optimization that results in incorrect * behavior when c is a smaller "normal" (non-identity-based) Set. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { Objects.requireNonNull(c); @@ -1486,6 +1504,7 @@ public void replaceAll(BiFunction function) { * {@code false}. */ @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(Object key, Object value) { return removeMapping(key, value); @@ -1501,6 +1520,7 @@ public boolean remove(Object key, Object value) { * otherwise it returns {@code false}. */ @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { Object k = maskNull(key); diff --git a/src/java.base/share/classes/java/util/Iterator.java b/src/java.base/share/classes/java/util/Iterator.java index baa55eeb009b2..04e99e4cedc45 100644 --- a/src/java.base/share/classes/java/util/Iterator.java +++ b/src/java.base/share/classes/java/util/Iterator.java @@ -29,12 +29,12 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf; import org.checkerframework.checker.nonempty.qual.NonEmpty; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; import org.checkerframework.framework.qual.Covariant; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.function.Consumer; @@ -118,6 +118,7 @@ public interface Iterator { * been called after the last call to the {@code next} * method */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default void remove(@GuardSatisfied @CanShrink Iterator this) { throw new UnsupportedOperationException("remove"); diff --git a/src/java.base/share/classes/java/util/JumboEnumSet.java b/src/java.base/share/classes/java/util/JumboEnumSet.java index cbe172a84e11d..3ed6211bf416f 100644 --- a/src/java.base/share/classes/java/util/JumboEnumSet.java +++ b/src/java.base/share/classes/java/util/JumboEnumSet.java @@ -35,10 +35,10 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.checker.index.qual.NonNegative; import org.checkerframework.dataflow.qual.Pure; @@ -72,6 +72,7 @@ final class JumboEnumSet> extends EnumSet { elements = new long[(universe.length + 63) >>> 6]; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void addRange(E from, E to) { int fromIndex = from.ordinal() >>> 6; @@ -89,6 +90,7 @@ void addRange(E from, E to) { size = to.ordinal() - from.ordinal() + 1; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void addAll() { for (int i = 0; i < elements.length; i++) @@ -97,6 +99,7 @@ void addAll() { size = universe.length; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void complement() { for (int i = 0; i < elements.length; i++) @@ -169,6 +172,7 @@ public E next(@NonEmpty EnumSetIterator this) { } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastReturned == 0) @@ -233,6 +237,7 @@ public boolean contains(@GuardSatisfied @Nullable @UnknownSignedness Object e) { * @throws NullPointerException if {@code e} is null */ @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { typeCheck(e); @@ -254,6 +259,7 @@ public boolean add(E e) { * @param e element to be removed from this set, if present * @return {@code true} if the set contained the specified element */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @Nullable @UnknownSignedness Object e) { if (e == null) @@ -305,6 +311,7 @@ public boolean containsAll(Collection c) { * @throws NullPointerException if the specified collection or any of * its elements are null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { if (!(c instanceof JumboEnumSet es)) @@ -331,6 +338,7 @@ public boolean addAll(Collection c) { * @return {@code true} if this set changed as a result of the call * @throws NullPointerException if the specified collection is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { if (!(c instanceof JumboEnumSet es)) @@ -352,6 +360,7 @@ public boolean removeAll(Collection c) { * @return {@code true} if this set changed as a result of the call * @throws NullPointerException if the specified collection is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { if (!(c instanceof JumboEnumSet es)) @@ -371,6 +380,7 @@ public boolean retainAll(Collection c) { /** * Removes all of the elements from this set. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { Arrays.fill(elements, 0); diff --git a/src/java.base/share/classes/java/util/LinkedHashMap.java b/src/java.base/share/classes/java/util/LinkedHashMap.java index a27b527e68f68..674c9a2ab3873 100644 --- a/src/java.base/share/classes/java/util/LinkedHashMap.java +++ b/src/java.base/share/classes/java/util/LinkedHashMap.java @@ -34,11 +34,11 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; 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.DoesNotUnrefineReceiver; import java.util.function.Consumer; import java.util.function.BiConsumer; @@ -405,6 +405,7 @@ void afterNodeAccess(Node e) { * * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putFirst(K k, V v) { try { @@ -423,6 +424,7 @@ public V putFirst(K k, V v) { * * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putLast(K k, V v) { try { @@ -576,6 +578,7 @@ public V getOrDefault(@Nullable Object key, V defaultValue) { /** * {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied LinkedHashMap this) { super.clear(); @@ -719,6 +722,7 @@ final class LinkedKeySet extends AbstractSet implements SequencedSet { LinkedKeySet(boolean reversed) { this.reversed = reversed; } @Pure public final int size() { return size; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void clear() { LinkedHashMap.this.clear(); } @SideEffectFree @@ -728,6 +732,7 @@ public final Iterator iterator() { @Pure @EnsuresNonEmptyIf(result = true, expression = "this") public final boolean contains(@Nullable @UnknownSignedness Object o) { return containsKey(o); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final boolean remove(@Nullable @UnknownSignedness Object key) { return removeNode(hash(key), key, null, false, true) != null; @@ -766,12 +771,14 @@ public final void forEach(Consumer action) { public final void addLast(K k) { throw new UnsupportedOperationException(); } public final K getFirst() { return nsee(reversed ? tail : head).key; } public final K getLast() { return nsee(reversed ? head : tail).key; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final K removeFirst() { var node = nsee(reversed ? tail : head); removeNode(node.hash, node.key, null, false, false); return node.key; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final K removeLast() { var node = nsee(reversed ? head : tail); @@ -837,6 +844,7 @@ final class LinkedValues extends AbstractCollection implements SequencedColle LinkedValues(boolean reversed) { this.reversed = reversed; } @Pure public final int size() { return size; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void clear() { LinkedHashMap.this.clear(); } @SideEffectFree @@ -879,12 +887,14 @@ public final void forEach(Consumer action) { public final void addLast(V v) { throw new UnsupportedOperationException(); } public final V getFirst() { return nsee(reversed ? tail : head).value; } public final V getLast() { return nsee(reversed ? head : tail).value; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final V removeFirst() { var node = nsee(reversed ? tail : head); removeNode(node.hash, node.key, null, false, false); return node.value; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final V removeLast() { var node = nsee(reversed ? head : tail); @@ -953,6 +963,7 @@ final class LinkedEntrySet extends AbstractSet> LinkedEntrySet(boolean reversed) { this.reversed = reversed; } @Pure public final int size() { return size; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void clear() { LinkedHashMap.this.clear(); } @SideEffectFree @@ -968,6 +979,7 @@ public final boolean contains(@Nullable @UnknownSignedness Object o) { Node candidate = getNode(key); return candidate != null && candidate.equals(e); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final boolean remove(@Nullable @UnknownSignedness Object o) { if (o instanceof Map.Entry e) { @@ -1008,12 +1020,14 @@ final Node nsee(Node e) { public final void addLast(Map.Entry e) { throw new UnsupportedOperationException(); } public final Map.Entry getFirst() { return nsee(reversed ? tail : head); } public final Map.Entry getLast() { return nsee(reversed ? head : tail); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final Map.Entry removeFirst() { var node = nsee(reversed ? tail : head); removeNode(node.hash, node.key, null, false, false); return node; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final Map.Entry removeLast() { var node = nsee(reversed ? head : tail); @@ -1086,6 +1100,7 @@ final LinkedHashMap.Entry nextNode(@NonEmpty LinkedHashIterator this) { return e; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void remove() { Node p = current; @@ -1102,6 +1117,7 @@ public final void remove() { final class LinkedKeyIterator extends LinkedHashIterator implements Iterator { LinkedKeyIterator(boolean reversed) { super(reversed); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final K next(@NonEmpty LinkedKeyIterator this) { return nextNode().getKey(); } } @@ -1109,6 +1125,7 @@ final class LinkedKeyIterator extends LinkedHashIterator final class LinkedValueIterator extends LinkedHashIterator implements Iterator { LinkedValueIterator(boolean reversed) { super(reversed); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final V next(@NonEmpty LinkedValueIterator this) { return nextNode().value; } } @@ -1116,6 +1133,7 @@ final class LinkedValueIterator extends LinkedHashIterator final class LinkedEntryIterator extends LinkedHashIterator implements Iterator> { LinkedEntryIterator(boolean reversed) { super(reversed); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final Map.Entry next(@NonEmpty LinkedEntryIterator this) { return nextNode(); } } @@ -1197,21 +1215,25 @@ public V get(Object key) { return base.get(key); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V put(K key, V value) { return base.put(key, value); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V remove(Object key) { return base.remove(key); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putAll(Map m) { base.putAll(m); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { base.clear(); @@ -1255,21 +1277,25 @@ public void replaceAll(BiFunction function) { throw new ConcurrentModificationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putIfAbsent(K key, V value) { return base.putIfAbsent(key, value); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(Object key, Object value) { return base.remove(key, value); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { return base.replace(key, oldValue, newValue); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { return base.replace(key, value); @@ -1309,21 +1335,25 @@ public Entry lastEntry() { return base.firstEntry(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Entry pollFirstEntry() { return base.pollLastEntry(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Entry pollLastEntry() { return base.pollFirstEntry(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putFirst(K k, V v) { return base.putLast(k, v); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putLast(K k, V v) { return base.putFirst(k, v); diff --git a/src/java.base/share/classes/java/util/LinkedHashSet.java b/src/java.base/share/classes/java/util/LinkedHashSet.java index 24415b0ec9215..ff58254266339 100644 --- a/src/java.base/share/classes/java/util/LinkedHashSet.java +++ b/src/java.base/share/classes/java/util/LinkedHashSet.java @@ -26,10 +26,10 @@ package java.util; import org.checkerframework.dataflow.qual.Deterministic; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; /** *

Hash table and linked list implementation of the {@code Set} interface, @@ -210,6 +210,7 @@ public LinkedHashSet(Collection c) { * @since 1.8 */ @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Spliterator spliterator() { return Spliterators.spliterator(this, Spliterator.DISTINCT | Spliterator.ORDERED); @@ -248,6 +249,7 @@ LinkedHashMap map() { * * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { map().putFirst(e, PRESENT); @@ -261,6 +263,7 @@ public void addFirst(E e) { * * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { map().putLast(e, PRESENT); @@ -294,6 +297,7 @@ public E getLast() { * @throws NoSuchElementException {@inheritDoc} * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeFirst() { return map().sequencedKeySet().removeFirst(); @@ -305,6 +309,7 @@ public E removeFirst() { * @throws NoSuchElementException {@inheritDoc} * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeLast() { return map().sequencedKeySet().removeLast(); @@ -319,6 +324,7 @@ public E removeLast() { * @return {@inheritDoc} * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public SequencedSet reversed() { class ReverseLinkedHashSetView extends AbstractSet implements SequencedSet { diff --git a/src/java.base/share/classes/java/util/LinkedList.java b/src/java.base/share/classes/java/util/LinkedList.java index 16b88a69c6a58..77506ec454152 100644 --- a/src/java.base/share/classes/java/util/LinkedList.java +++ b/src/java.base/share/classes/java/util/LinkedList.java @@ -39,12 +39,12 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; 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; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.io.IOException; import java.io.ObjectInput; @@ -298,6 +298,7 @@ public E getLast(@GuardSatisfied @NonEmpty LinkedList this) { * @return the first element from this list * @throws NoSuchElementException if this list is empty */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeFirst(@GuardSatisfied @NonEmpty @CanShrink LinkedList this) { final Node f = first; @@ -312,6 +313,7 @@ public E removeFirst(@GuardSatisfied @NonEmpty @CanShrink LinkedList this) { * @return the last element from this list * @throws NoSuchElementException if this list is empty */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeLast(@GuardSatisfied @NonEmpty @CanShrink LinkedList this) { final Node l = last; @@ -325,6 +327,7 @@ public E removeLast(@GuardSatisfied @NonEmpty @CanShrink LinkedList this) { * * @param e the element to add */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addFirst(@GuardSatisfied LinkedList this, E e) { linkFirst(e); @@ -337,6 +340,7 @@ public void addFirst(@GuardSatisfied LinkedList this, E e) { * * @param e the element to add */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addLast(@GuardSatisfied LinkedList this, E e) { linkLast(e); @@ -377,6 +381,7 @@ public boolean contains(@GuardSatisfied LinkedList this, @GuardSatisfied @Nul */ @ReleasesNoLocks @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(@GuardSatisfied LinkedList this, E e) { linkLast(e); @@ -397,6 +402,7 @@ public boolean add(@GuardSatisfied LinkedList this, E e) { * @return {@code true} if this list contained the specified element */ @ReleasesNoLocks + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @CanShrink LinkedList this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { if (o == null) { @@ -429,6 +435,7 @@ public boolean remove(@GuardSatisfied @CanShrink LinkedList this, @GuardSatis * @return {@code true} if this list changed as a result of the call * @throws NullPointerException if the specified collection is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@GuardSatisfied LinkedList this, Collection c) { return addAll(size, c); @@ -449,6 +456,7 @@ public boolean addAll(@GuardSatisfied LinkedList this, Collection this, @NonNegative int index, Collection c) { checkPositionIndex(index); @@ -493,6 +501,7 @@ public boolean addAll(@GuardSatisfied LinkedList this, @NonNegative int index * Removes all of the elements from this list. * The list will be empty after this call returns. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink LinkedList this) { // Clearing all of the links between nodes is "unnecessary", but: @@ -536,6 +545,7 @@ public E get(@GuardSatisfied LinkedList this, @NonNegative int index) { * @return the element previously at the specified position * @throws IndexOutOfBoundsException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E set(@GuardSatisfied LinkedList this, @NonNegative int index, E element) { checkElementIndex(index); @@ -554,6 +564,7 @@ public E set(@GuardSatisfied LinkedList this, @NonNegative int index, E eleme * @param element element to be inserted * @throws IndexOutOfBoundsException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(@GuardSatisfied LinkedList this, @NonNegative int index, E element) { checkPositionIndex(index); @@ -573,6 +584,7 @@ public void add(@GuardSatisfied LinkedList this, @NonNegative int index, E el * @return the element previously at the specified position * @throws IndexOutOfBoundsException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @CanShrink LinkedList this, @NonNegative int index) { checkElementIndex(index); @@ -725,6 +737,7 @@ public E element(@GuardSatisfied @NonEmpty LinkedList this) { * @return the head of this list, or {@code null} if this list is empty * @since 1.5 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink LinkedList this) { final Node f = first; @@ -738,6 +751,7 @@ public E element(@GuardSatisfied @NonEmpty LinkedList this) { * @throws NoSuchElementException if this list is empty * @since 1.5 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @NonEmpty @CanShrink LinkedList this) { return removeFirst(); @@ -750,6 +764,7 @@ public E remove(@GuardSatisfied @NonEmpty @CanShrink LinkedList this) { * @return {@code true} (as specified by {@link Queue#offer}) * @since 1.5 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { return add(e); @@ -763,6 +778,7 @@ public boolean offer(E e) { * @return {@code true} (as specified by {@link Deque#offerFirst}) * @since 1.6 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offerFirst(E e) { addFirst(e); @@ -776,6 +792,7 @@ public boolean offerFirst(E e) { * @return {@code true} (as specified by {@link Deque#offerLast}) * @since 1.6 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offerLast(E e) { addLast(e); @@ -818,6 +835,7 @@ public boolean offerLast(E e) { * this list is empty * @since 1.6 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollFirst(@GuardSatisfied @CanShrink LinkedList this) { final Node f = first; @@ -832,6 +850,7 @@ public boolean offerLast(E e) { * this list is empty * @since 1.6 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollLast(@GuardSatisfied @CanShrink LinkedList this) { final Node l = last; @@ -847,6 +866,7 @@ public boolean offerLast(E e) { * @param e the element to push * @since 1.6 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void push(@GuardSatisfied LinkedList this, E e) { addFirst(e); @@ -863,6 +883,7 @@ public void push(@GuardSatisfied LinkedList this, E e) { * @throws NoSuchElementException if this list is empty * @since 1.6 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E pop(@GuardSatisfied @NonEmpty @CanShrink LinkedList this) { return removeFirst(); @@ -877,6 +898,7 @@ public E pop(@GuardSatisfied @NonEmpty @CanShrink LinkedList this) { * @return {@code true} if the list contained the specified element * @since 1.6 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeFirstOccurrence(@GuardSatisfied @CanShrink LinkedList this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { return remove(o); @@ -891,6 +913,7 @@ public boolean removeFirstOccurrence(@GuardSatisfied @CanShrink LinkedList th * @return {@code true} if the list contained the specified element * @since 1.6 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeLastOccurrence(@GuardSatisfied @CanShrink LinkedList this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { if (o == null) { @@ -972,6 +995,7 @@ public boolean hasPrevious() { return nextIndex > 0; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E previous() { checkForComodification(); @@ -991,6 +1015,7 @@ public int previousIndex() { return nextIndex - 1; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { checkForComodification(); @@ -1007,6 +1032,7 @@ public void remove() { expectedModCount++; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void set(E e) { if (lastReturned == null) @@ -1015,6 +1041,7 @@ public void set(E e) { lastReturned.item = e; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(E e) { checkForComodification(); @@ -1078,6 +1105,7 @@ public boolean hasNext() { public E next(@NonEmpty DescendingIterator this) { return itr.previous(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { itr.remove(); @@ -1379,11 +1407,13 @@ public String toString() { return rlist.toString(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { return rlist.retainAll(c); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { return rlist.removeAll(c); @@ -1405,6 +1435,7 @@ public Stream stream() { return rlist.stream(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { return rlist.removeIf(filter); @@ -1438,6 +1469,7 @@ public ListIterator listIterator() { return rlist.listIterator(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void sort(Comparator c) { rlist.sort(c); @@ -1472,31 +1504,37 @@ public ListIterator listIterator(int index) { return rlist.listIterator(index); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeLastOccurrence(Object o) { return rdeque.removeLastOccurrence(o); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeFirstOccurrence(Object o) { return rdeque.removeFirstOccurrence(o); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E pop() { return rdeque.pop(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void push(E e) { rdeque.push(e); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E pollLast() { return rdeque.pollLast(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E pollFirst() { return rdeque.pollFirst(); @@ -1510,26 +1548,31 @@ public E peekFirst() { return rdeque.peekFirst(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offerLast(E e) { return rdeque.offerLast(e); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offerFirst(E e) { return rdeque.offerFirst(e); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { return rdeque.offer(e); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove() { return rdeque.remove(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E poll() { return rdeque.poll(); @@ -1551,16 +1594,19 @@ public int indexOf(Object o) { return rlist.indexOf(o); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(int index) { return rlist.remove(index); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(int index, E element) { rlist.add(index, element); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E set(int index, E element) { return rlist.set(index, element); @@ -1570,26 +1616,31 @@ public E get(int index) { return rlist.get(index); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { rlist.clear(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(int index, Collection c) { return rlist.addAll(index, c); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { return rlist.addAll(c); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(Object o) { return rlist.remove(o); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { return rlist.add(e); @@ -1603,21 +1654,25 @@ public boolean contains(Object o) { return rlist.contains(o); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { rdeque.addLast(e); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { rdeque.addFirst(e); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeLast() { return rdeque.removeLast(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeFirst() { return rdeque.removeFirst(); diff --git a/src/java.base/share/classes/java/util/ListIterator.java b/src/java.base/share/classes/java/util/ListIterator.java index e2b3c8bf01e73..83bf5f586c182 100644 --- a/src/java.base/share/classes/java/util/ListIterator.java +++ b/src/java.base/share/classes/java/util/ListIterator.java @@ -30,11 +30,11 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf; import org.checkerframework.checker.nonempty.qual.NonEmpty; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; /** * An iterator for lists that allows the programmer @@ -125,6 +125,7 @@ public interface ListIterator extends Iterator { * @throws NoSuchElementException if the iteration has no previous * element */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E previous(@GuardSatisfied ListIterator this); @@ -169,6 +170,7 @@ public interface ListIterator extends Iterator { * {@code add} have been called after the last call to * {@code next} or {@code previous} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void remove(@GuardSatisfied ListIterator this); @@ -192,6 +194,7 @@ public interface ListIterator extends Iterator { * {@code add} have been called after the last call to * {@code next} or {@code previous} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void set(@GuardSatisfied ListIterator this, E e); @@ -215,6 +218,7 @@ public interface ListIterator extends Iterator { * @throws IllegalArgumentException if some aspect of this element * prevents it from being added to this list */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void add(@GuardSatisfied ListIterator this, E e); } diff --git a/src/java.base/share/classes/java/util/Map.java b/src/java.base/share/classes/java/util/Map.java index 1d6c6261cf101..794bcaaf2b441 100644 --- a/src/java.base/share/classes/java/util/Map.java +++ b/src/java.base/share/classes/java/util/Map.java @@ -40,12 +40,12 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; import org.checkerframework.common.aliasing.qual.NonLeaked; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; import org.checkerframework.framework.qual.Covariant; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.function.BiConsumer; import java.util.function.BiFunction; @@ -303,6 +303,7 @@ public interface Map { @ReleasesNoLocks @EnsuresKeyFor(value={"#1"}, map={"this"}) @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable V put(@GuardSatisfied Map this, K key, V value); @@ -335,6 +336,7 @@ public interface Map { * map does not permit null keys ({@linkplain Collection##optional-restrictions optional}) */ @CFComment("nullness: key is not @Nullable because this map might not permit null values") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable V remove(@GuardSatisfied Map this, @GuardSatisfied @UnknownSignedness Object key); @@ -362,6 +364,7 @@ public interface Map { * @throws IllegalArgumentException if some property of a key or value in * the specified map prevents it from being stored in this map */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void putAll(@GuardSatisfied Map this, Map m); @@ -372,6 +375,7 @@ public interface Map { * @throws UnsupportedOperationException if the {@code clear} operation * is not supported by this map */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void clear(@GuardSatisfied Map this); @@ -537,6 +541,7 @@ interface Entry { * required to, throw this exception if the entry has been * removed from the backing map. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") V setValue(Map.@GuardSatisfied Entry this, V value); @@ -893,6 +898,7 @@ default void replaceAll(BiFunction function) * @since 1.8 */ @EnsuresKeyFor(value={"#1"}, map={"this"}) + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default @Nullable V putIfAbsent(K key, V value) { V v = get(key); @@ -938,6 +944,7 @@ default void replaceAll(BiFunction function) * @since 1.8 */ @CFComment("nullness: key and value are not @Nullable because this map might not permit null values") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default boolean remove(@GuardSatisfied @UnknownSignedness Object key, @GuardSatisfied @UnknownSignedness Object value) { Object curValue = get(key); @@ -989,6 +996,7 @@ default boolean remove(@GuardSatisfied @UnknownSignedness Object key, @GuardSati * or value prevents it from being stored in this map * @since 1.8 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default boolean replace(K key, V oldValue, V newValue) { Object curValue = get(key); @@ -1038,6 +1046,7 @@ default boolean replace(K key, V oldValue, V newValue) { * or value prevents it from being stored in this map * @since 1.8 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default @Nullable V replace(K key, V value) { V curValue; diff --git a/src/java.base/share/classes/java/util/NavigableMap.java b/src/java.base/share/classes/java/util/NavigableMap.java index 44e774ffac482..a2501ee26b397 100644 --- a/src/java.base/share/classes/java/util/NavigableMap.java +++ b/src/java.base/share/classes/java/util/NavigableMap.java @@ -38,10 +38,10 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nullness.qual.KeyFor; import org.checkerframework.checker.nullness.qual.Nullable; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; /** * A {@link SortedMap} extended with navigation methods returning the @@ -252,6 +252,7 @@ public interface NavigableMap extends SortedMap { * @return the removed first entry of this map, * or {@code null} if this map is empty */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") Map.@Nullable Entry pollFirstEntry(@GuardSatisfied NavigableMap this); @@ -262,6 +263,7 @@ public interface NavigableMap extends SortedMap { * @return the removed last entry of this map, * or {@code null} if this map is empty */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") Map.@Nullable Entry pollLastEntry(@GuardSatisfied NavigableMap this); diff --git a/src/java.base/share/classes/java/util/NavigableSet.java b/src/java.base/share/classes/java/util/NavigableSet.java index 9a16eb7eaf837..170ffdb1b0ddf 100644 --- a/src/java.base/share/classes/java/util/NavigableSet.java +++ b/src/java.base/share/classes/java/util/NavigableSet.java @@ -39,10 +39,10 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nonempty.qual.PolyNonEmpty; import org.checkerframework.checker.nullness.qual.Nullable; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; /** * A {@link SortedSet} extended with navigation methods reporting @@ -161,6 +161,7 @@ public interface NavigableSet extends SortedSet { * * @return the first element, or {@code null} if this set is empty */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E pollFirst(@GuardSatisfied NavigableSet this); @@ -170,6 +171,7 @@ public interface NavigableSet extends SortedSet { * * @return the last element, or {@code null} if this set is empty */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E pollLast(@GuardSatisfied NavigableSet this); @@ -196,6 +198,7 @@ public interface NavigableSet extends SortedSet { * * @return a reverse order view of this set */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") NavigableSet descendingSet(); @@ -205,6 +208,7 @@ public interface NavigableSet extends SortedSet { * * @return an iterator over the elements in this set, in descending order */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") Iterator descendingIterator(); @@ -354,6 +358,7 @@ NavigableSet subSet(@GuardSatisfied NavigableSet this, @GuardSatisfied E f * @throws UnsupportedOperationException {@inheritDoc} * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default E removeFirst() { if (this.isEmpty()) { @@ -374,6 +379,7 @@ default E removeFirst() { * @throws UnsupportedOperationException {@inheritDoc} * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default E removeLast() { if (this.isEmpty()) { @@ -395,6 +401,7 @@ default E removeLast() { * @return a reverse-ordered view of this collection, as a {@code NavigableSet} * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default NavigableSet reversed() { return this.descendingSet(); diff --git a/src/java.base/share/classes/java/util/PrimitiveIterator.java b/src/java.base/share/classes/java/util/PrimitiveIterator.java index 5536b06b2c73c..58c31aa7d44a7 100644 --- a/src/java.base/share/classes/java/util/PrimitiveIterator.java +++ b/src/java.base/share/classes/java/util/PrimitiveIterator.java @@ -26,8 +26,8 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nonempty.qual.NonEmpty; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.function.Consumer; import java.util.function.DoubleConsumer; @@ -107,6 +107,7 @@ public static interface OfInt extends PrimitiveIterator { * @return the next {@code int} element in the iteration * @throws NoSuchElementException if the iteration has no more elements */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") int nextInt(@NonEmpty OfInt this); @@ -133,6 +134,7 @@ default void forEachRemaining(IntConsumer action) { * {@link #nextInt()}, and returns that boxed result. */ @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default Integer next(PrimitiveIterator.@GuardSatisfied OfInt this) { if (Tripwire.ENABLED) @@ -179,6 +181,7 @@ public static interface OfLong extends PrimitiveIterator { * @return the next {@code long} element in the iteration * @throws NoSuchElementException if the iteration has no more elements */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") long nextLong(@NonEmpty OfLong this); @@ -205,6 +208,7 @@ default void forEachRemaining(LongConsumer action) { * {@link #nextLong()}, and returns that boxed result. */ @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default Long next(PrimitiveIterator.@GuardSatisfied OfLong this) { if (Tripwire.ENABLED) @@ -250,6 +254,7 @@ public static interface OfDouble extends PrimitiveIterator this, E e) { return offer(e); @@ -345,6 +346,7 @@ public boolean add(@GuardSatisfied PriorityQueue this, E e) { * according to the priority queue's ordering * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { if (e == null) @@ -384,6 +386,7 @@ private int indexOf(@GuardSatisfied @Nullable @UnknownSignedness Object o) { * @param o element to be removed from this queue, if present * @return {@code true} if this queue changed as a result of the call */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @CanShrink PriorityQueue this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { int i = indexOf(o); @@ -566,6 +569,7 @@ public E next(@NonEmpty Itr this) { throw new NoSuchElementException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (expectedModCount != modCount) @@ -599,6 +603,7 @@ public void remove() { * Removes all of the elements from this priority queue. * The queue will be empty after this call returns. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink PriorityQueue this) { modCount++; @@ -608,6 +613,7 @@ public void clear(@GuardSatisfied @CanShrink PriorityQueue this) { size = 0; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink PriorityQueue this) { final Object[] es; @@ -932,6 +938,7 @@ public int characteristics() { /** * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@GuardSatisfied @CanShrink PriorityQueue this, Predicate filter) { Objects.requireNonNull(filter); @@ -941,6 +948,7 @@ public boolean removeIf(@GuardSatisfied @CanShrink PriorityQueue this, Predic /** * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(@GuardSatisfied @CanShrink PriorityQueue this, Collection c) { Objects.requireNonNull(c); @@ -950,6 +958,7 @@ public boolean removeAll(@GuardSatisfied @CanShrink PriorityQueue this, Colle /** * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(@GuardSatisfied @CanShrink PriorityQueue this, Collection c) { Objects.requireNonNull(c); diff --git a/src/java.base/share/classes/java/util/Properties.java b/src/java.base/share/classes/java/util/Properties.java index b492991de4c30..4e79a37752023 100644 --- a/src/java.base/share/classes/java/util/Properties.java +++ b/src/java.base/share/classes/java/util/Properties.java @@ -32,10 +32,10 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.propkey.qual.PropertyKey; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.io.IOException; import java.io.PrintStream; @@ -239,6 +239,7 @@ private Properties(Properties defaults, int initialCapacity) { * @see #getProperty * @since 1.2 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized @Nullable Object setProperty(@GuardSatisfied Properties this, @PropertyKey String key, String value) { return put(key, value); @@ -1365,24 +1366,28 @@ public boolean containsKey(@GuardSatisfied @Nullable @UnknownSignedness Object k } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized Object put(Object key, Object value) { return map.put(key, value); } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized Object remove(@GuardSatisfied @Nullable @UnknownSignedness Object key) { return map.remove(key); } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized void putAll(Map t) { map.putAll(t); } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized void clear() { map.clear(); @@ -1430,8 +1435,10 @@ private EntrySet(Set> entrySet) { @Override public boolean contains(@UnknownSignedness Object o) { return entrySet.contains(o); } @Override public Object[] toArray() { return entrySet.toArray(); } @Override public @Nullable T[] toArray(@PolyNull T[] a) { return entrySet.toArray(a); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Override public void clear() { entrySet.clear(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Override public boolean remove(@UnknownSignedness Object o) { return entrySet.remove(o); } @@ -1467,12 +1474,14 @@ public String toString() { } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { return entrySet.removeAll(c); } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { return entrySet.retainAll(c); @@ -1513,30 +1522,35 @@ public synchronized void replaceAll(BiFunction mappingFunction) { @@ -1544,6 +1558,7 @@ public synchronized Object replace(Object key, Object value) { } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized @PolyNull Object computeIfPresent(Object key, BiFunction remappingFunction) { @@ -1551,6 +1566,7 @@ public synchronized Object replace(Object key, Object value) { } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized @PolyNull Object compute(Object key, BiFunction remappingFunction) { diff --git a/src/java.base/share/classes/java/util/Queue.java b/src/java.base/share/classes/java/util/Queue.java index d4f567a30282b..0ba979fe5b785 100644 --- a/src/java.base/share/classes/java/util/Queue.java +++ b/src/java.base/share/classes/java/util/Queue.java @@ -41,10 +41,10 @@ import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf; import org.checkerframework.checker.nonempty.qual.NonEmpty; import org.checkerframework.checker.nullness.qual.Nullable; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; /** * A collection designed for holding elements prior to processing. @@ -167,6 +167,7 @@ public interface Queue extends Collection { * prevents it from being added to this queue */ @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean add(@GuardSatisfied Queue this, E e); @@ -187,6 +188,7 @@ public interface Queue extends Collection { * @throws IllegalArgumentException if some property of this element * prevents it from being added to this queue */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean offer(E e); @@ -198,6 +200,7 @@ public interface Queue extends Collection { * @return the head of this queue * @throws NoSuchElementException if this queue is empty */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E remove(@GuardSatisfied @NonEmpty @CanShrink Queue this); @@ -207,6 +210,7 @@ public interface Queue extends Collection { * * @return the head of this queue, or {@code null} if this queue is empty */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E poll(@GuardSatisfied @CanShrink Queue this); @@ -226,6 +230,7 @@ public interface Queue extends Collection { * * @return the head of this queue, or {@code null} if this queue is empty */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E peek(); } diff --git a/src/java.base/share/classes/java/util/RegularEnumSet.java b/src/java.base/share/classes/java/util/RegularEnumSet.java index 6c61c30a416ff..9ecfbde70a4cd 100644 --- a/src/java.base/share/classes/java/util/RegularEnumSet.java +++ b/src/java.base/share/classes/java/util/RegularEnumSet.java @@ -36,11 +36,11 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; 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.DoesNotUnrefineReceiver; /** * Private implementation class for EnumSet, for "regular sized" enum types @@ -64,17 +64,20 @@ final class RegularEnumSet> extends EnumSet { super(elementType, universe); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void addRange(E from, E to) { elements = (-1L >>> (from.ordinal() - to.ordinal() - 1)) << from.ordinal(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void addAll() { if (universe.length != 0) elements = -1L >>> -universe.length; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void complement() { if (universe.length != 0) { @@ -132,6 +135,7 @@ public E next(@NonEmpty EnumSetIterator this) { return (E) universe[Long.numberOfTrailingZeros(lastReturned)]; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastReturned == 0) @@ -191,6 +195,7 @@ public boolean contains(@GuardSatisfied @Nullable @UnknownSignedness Object e) { * @throws NullPointerException if {@code e} is null */ @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { typeCheck(e); @@ -206,6 +211,7 @@ public boolean add(E e) { * @param e element to be removed from this set, if present * @return {@code true} if the set contained the specified element */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @Nullable @UnknownSignedness Object e) { if (e == null) @@ -249,6 +255,7 @@ public boolean containsAll(Collection c) { * @throws NullPointerException if the specified collection or any * of its elements are null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { if (!(c instanceof RegularEnumSet es)) @@ -275,6 +282,7 @@ public boolean addAll(Collection c) { * @return {@code true} if this set changed as a result of the call * @throws NullPointerException if the specified collection is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { if (!(c instanceof RegularEnumSet es)) @@ -296,6 +304,7 @@ public boolean removeAll(Collection c) { * @return {@code true} if this set changed as a result of the call * @throws NullPointerException if the specified collection is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { if (!(c instanceof RegularEnumSet es)) @@ -315,6 +324,7 @@ public boolean retainAll(Collection c) { /** * Removes all of the elements from this set. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { elements = 0; diff --git a/src/java.base/share/classes/java/util/Scanner.java b/src/java.base/share/classes/java/util/Scanner.java index 53366081d8ad0..6d70a6e416fb4 100644 --- a/src/java.base/share/classes/java/util/Scanner.java +++ b/src/java.base/share/classes/java/util/Scanner.java @@ -1518,6 +1518,7 @@ public String next(@GuardSatisfied @NonEmpty Scanner this) { * @throws UnsupportedOperationException if this method is invoked. * @see java.util.Iterator */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove(@GuardSatisfied Scanner this) { throw new UnsupportedOperationException(); diff --git a/src/java.base/share/classes/java/util/SequencedCollection.java b/src/java.base/share/classes/java/util/SequencedCollection.java index 2e7c94dc442eb..5f208d9701866 100644 --- a/src/java.base/share/classes/java/util/SequencedCollection.java +++ b/src/java.base/share/classes/java/util/SequencedCollection.java @@ -89,6 +89,7 @@ public interface SequencedCollection extends Collection { * * @return a reverse-ordered view of this collection */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") SequencedCollection reversed(); @@ -106,6 +107,7 @@ public interface SequencedCollection extends Collection { * @throws UnsupportedOperationException if this collection implementation * does not support this operation */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default void addFirst(E e) { throw new UnsupportedOperationException(); @@ -125,6 +127,7 @@ default void addFirst(E e) { * @throws UnsupportedOperationException if this collection implementation * does not support this operation */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default void addLast(E e) { throw new UnsupportedOperationException(); @@ -177,6 +180,7 @@ default E getLast() { * @throws UnsupportedOperationException if this collection implementation * does not support this operation */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default E removeFirst() { var it = this.iterator(); @@ -200,6 +204,7 @@ default E removeFirst() { * @throws UnsupportedOperationException if this collection implementation * does not support this operation */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default E removeLast() { var it = this.reversed().iterator(); diff --git a/src/java.base/share/classes/java/util/SequencedMap.java b/src/java.base/share/classes/java/util/SequencedMap.java index 9881328c6db35..cae0db2912404 100644 --- a/src/java.base/share/classes/java/util/SequencedMap.java +++ b/src/java.base/share/classes/java/util/SequencedMap.java @@ -136,6 +136,7 @@ public interface SequencedMap extends Map { * * @return a reverse-ordered view of this map */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") SequencedMap reversed(); @@ -187,6 +188,7 @@ default Map.Entry lastEntry() { * @throws UnsupportedOperationException if this collection implementation does not * support this operation */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default Map.Entry pollFirstEntry() { var it = entrySet().iterator(); @@ -213,6 +215,7 @@ default Map.Entry pollFirstEntry() { * @throws UnsupportedOperationException if this collection implementation does not * support this operation */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default Map.Entry pollLastEntry() { var it = reversed().entrySet().iterator(); @@ -240,6 +243,7 @@ default Map.Entry pollLastEntry() { * @throws UnsupportedOperationException if this collection implementation does not * support this operation */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default V putFirst(K k, V v) { throw new UnsupportedOperationException(); @@ -260,6 +264,7 @@ default V putFirst(K k, V v) { * @throws UnsupportedOperationException if this collection implementation does not * support this operation */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default V putLast(K k, V v) { throw new UnsupportedOperationException(); @@ -279,6 +284,7 @@ default V putLast(K k, V v) { * * @return a {@code SequencedSet} view of this map's {@code keySet} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default SequencedSet sequencedKeySet() { class SeqKeySet extends AbstractMap.ViewCollection implements SequencedSet { @@ -313,6 +319,7 @@ public int hashCode() { * * @return a {@code SequencedCollection} view of this map's {@code values} collection */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default SequencedCollection sequencedValues() { class SeqValues extends AbstractMap.ViewCollection implements SequencedCollection { @@ -340,6 +347,7 @@ public SequencedCollection reversed() { * * @return a {@code SequencedSet} view of this map's {@code entrySet} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default SequencedSet> sequencedEntrySet() { class SeqEntrySet extends AbstractMap.ViewCollection> diff --git a/src/java.base/share/classes/java/util/SequencedSet.java b/src/java.base/share/classes/java/util/SequencedSet.java index c4fa139e9e418..5bae493f95f6c 100644 --- a/src/java.base/share/classes/java/util/SequencedSet.java +++ b/src/java.base/share/classes/java/util/SequencedSet.java @@ -56,6 +56,7 @@ public interface SequencedSet extends SequencedCollection, Set { * * @return a reverse-ordered view of this collection, as a {@code SequencedSet} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") SequencedSet reversed(); } diff --git a/src/java.base/share/classes/java/util/SortedMap.java b/src/java.base/share/classes/java/util/SortedMap.java index 706bc2fd501b4..eb3a7110df2e1 100644 --- a/src/java.base/share/classes/java/util/SortedMap.java +++ b/src/java.base/share/classes/java/util/SortedMap.java @@ -29,11 +29,11 @@ import org.checkerframework.checker.nonempty.qual.NonEmpty; import org.checkerframework.checker.nullness.qual.KeyFor; import org.checkerframework.checker.nullness.qual.Nullable; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; /** * A {@link Map} that further provides a total ordering on its keys. @@ -314,6 +314,7 @@ public interface SortedMap extends SequencedMap { * @throws UnsupportedOperationException always * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default V putFirst(K k, V v) { throw new UnsupportedOperationException(); @@ -330,6 +331,7 @@ default V putFirst(K k, V v) { * @throws UnsupportedOperationException always * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default V putLast(K k, V v) { throw new UnsupportedOperationException(); @@ -345,6 +347,7 @@ default V putLast(K k, V v) { * @return a reverse-ordered view of this map, as a {@code SortedMap} * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default SortedMap reversed() { return ReverseOrderSortedMapView.of(this); diff --git a/src/java.base/share/classes/java/util/SortedSet.java b/src/java.base/share/classes/java/util/SortedSet.java index eb8dfa734365e..699b52fc394a0 100644 --- a/src/java.base/share/classes/java/util/SortedSet.java +++ b/src/java.base/share/classes/java/util/SortedSet.java @@ -28,11 +28,11 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nonempty.qual.NonEmpty; import org.checkerframework.checker.nullness.qual.Nullable; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; /** * A {@link Set} that further provides a total ordering on its elements. @@ -269,6 +269,7 @@ public interface SortedSet extends Set, SequencedSet { * @since 1.8 */ @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default Spliterator spliterator() { return new Spliterators.IteratorSpliterator( @@ -293,6 +294,7 @@ public Comparator getComparator() { * @throws UnsupportedOperationException always * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default void addFirst(E e) { throw new UnsupportedOperationException(); @@ -309,6 +311,7 @@ default void addFirst(E e) { * @throws UnsupportedOperationException always * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default void addLast(E e) { throw new UnsupportedOperationException(); @@ -352,6 +355,7 @@ default E getLast() { * @throws UnsupportedOperationException {@inheritDoc} * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default E removeFirst() { E e = this.first(); @@ -371,6 +375,7 @@ default E removeFirst() { * @throws UnsupportedOperationException {@inheritDoc} * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default E removeLast() { E e = this.last(); @@ -388,6 +393,7 @@ default E removeLast() { * @return a reverse-ordered view of this collection, as a {@code SortedSet} * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default SortedSet reversed() { return ReverseOrderSortedSetView.of(this); diff --git a/src/java.base/share/classes/java/util/Stack.java b/src/java.base/share/classes/java/util/Stack.java index f8d3256a08adc..ad74f5c9d75ab 100644 --- a/src/java.base/share/classes/java/util/Stack.java +++ b/src/java.base/share/classes/java/util/Stack.java @@ -29,11 +29,11 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf; import org.checkerframework.checker.nonempty.qual.NonEmpty; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; /** * The {@code Stack} class represents a last-in-first-out @@ -76,6 +76,7 @@ public Stack() { * @return the {@code item} argument. * @see java.util.Vector#addElement */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E push(@GuardSatisfied Stack this, E item) { addElement(item); @@ -91,6 +92,7 @@ public E push(@GuardSatisfied Stack this, E item) { * of the {@code Vector} object). * @throws EmptyStackException if this stack is empty. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized E pop(@GuardSatisfied @NonEmpty @CanShrink Stack this) { E obj; diff --git a/src/java.base/share/classes/java/util/TreeMap.java b/src/java.base/share/classes/java/util/TreeMap.java index bb864ba367912..58d1a5706ae52 100644 --- a/src/java.base/share/classes/java/util/TreeMap.java +++ b/src/java.base/share/classes/java/util/TreeMap.java @@ -36,12 +36,12 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; 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; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.io.Serializable; import java.util.function.BiConsumer; @@ -310,6 +310,7 @@ public boolean containsValue(@GuardSatisfied TreeMap this, @GuardSatisfied * and this map uses natural ordering, or its comparator * does not permit null keys */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V get(@GuardSatisfied TreeMap this, @UnknownSignedness @GuardSatisfied Object key) { Entry p = getEntry(key); @@ -343,6 +344,7 @@ public boolean containsValue(@GuardSatisfied TreeMap this, @GuardSatisfied * @throws UnsupportedOperationException always * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putFirst(K k, V v) { throw new UnsupportedOperationException(); @@ -356,6 +358,7 @@ public V putFirst(K k, V v) { * @throws UnsupportedOperationException always * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putLast(K k, V v) { throw new UnsupportedOperationException(); @@ -373,6 +376,7 @@ public V putLast(K k, V v) { * the specified map contains a null key and this map does not * permit null keys */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putAll(@GuardSatisfied TreeMap this, Map map) { int mapSize = map.size(); @@ -595,12 +599,14 @@ final Entry getLowerEntry(K key) { * does not permit null keys */ @EnsuresKeyFor(value={"#1"}, map={"this"}) + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V put(@GuardSatisfied TreeMap this, K key, V value) { return put(key, value, true); } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putIfAbsent(K key, V value) { return put(key, value, false); @@ -948,6 +954,7 @@ private V mergeValue(Entry t, V value, BiFunction this, @GuardSatisfied @UnknownSignedness Object key) { Entry p = getEntry(key); @@ -963,6 +970,7 @@ private V mergeValue(Entry t, V value, BiFunction this) { modCount++; @@ -976,6 +984,7 @@ public void clear(@GuardSatisfied TreeMap this) { * * @return a shallow copy of this map */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Object clone(@GuardSatisfied TreeMap this) { TreeMap clone; @@ -1021,6 +1030,7 @@ public Object clone(@GuardSatisfied TreeMap this) { /** * @since 1.6 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.@Nullable Entry pollFirstEntry(@GuardSatisfied TreeMap this) { Entry p = getFirstEntry(); @@ -1033,6 +1043,7 @@ public Object clone(@GuardSatisfied TreeMap this) { /** * @since 1.6 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.@Nullable Entry pollLastEntry(@GuardSatisfied TreeMap this) { Entry p = getLastEntry(); @@ -1166,6 +1177,7 @@ public Object clone(@GuardSatisfied TreeMap this) { * operations. It does not support the {@code add} or {@code addAll} * operations. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Set<@KeyFor({"this"}) K> keySet(@GuardSatisfied TreeMap this) { return navigableKeySet(); @@ -1341,6 +1353,7 @@ public SortedMap tailMap(@GuardSatisfied TreeMap this, K fromKey) { } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { Entry p = getEntry(key); @@ -1352,6 +1365,7 @@ public boolean replace(K key, V oldValue, V newValue) { } @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { Entry p = getEntry(key); @@ -1410,6 +1424,7 @@ public boolean contains(@UnknownSignedness Object o) { return TreeMap.this.containsValue(o); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { for (Entry e = getFirstEntry(); e != null; e = successor(e)) { @@ -1421,6 +1436,7 @@ public boolean remove(@UnknownSignedness Object o) { return false; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { TreeMap.this.clear(); @@ -1448,6 +1464,7 @@ public boolean contains(@UnknownSignedness Object o) { return p != null && valEquals(p.getValue(), value); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { if (!(o instanceof Map.Entry entry)) @@ -1466,6 +1483,7 @@ public boolean remove(@UnknownSignedness Object o) { return TreeMap.this.size(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { TreeMap.this.clear(); @@ -1520,6 +1538,7 @@ public Iterator descendingIterator() { @Pure @EnsuresNonEmptyIf(result = true, expression = "this") public boolean contains(@UnknownSignedness Object o) { return m.containsKey(o); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { m.clear(); } public E lower(E e) { return m.lowerKey(e); } @@ -1537,6 +1556,7 @@ public E pollLast() { Map.Entry e = m.pollLastEntry(); return (e == null) ? null : e.getKey(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { int oldSize = size(); @@ -1617,6 +1637,7 @@ final Entry prevEntry() { return e; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastReturned == null) @@ -1636,6 +1657,7 @@ final class EntryIterator extends PrivateEntryIterator> { EntryIterator(Entry first) { super(first); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(@NonEmpty EntryIterator this) { return nextEntry(); @@ -1646,6 +1668,7 @@ final class ValueIterator extends PrivateEntryIterator { ValueIterator(Entry first) { super(first); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V next(@NonEmpty ValueIterator this) { return nextEntry().value; @@ -1656,6 +1679,7 @@ final class KeyIterator extends PrivateEntryIterator { KeyIterator(Entry first) { super(first); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty KeyIterator this) { return nextEntry().key; @@ -1666,10 +1690,12 @@ final class DescendingKeyIterator extends PrivateEntryIterator { DescendingKeyIterator(Entry first) { super(first); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty DescendingKeyIterator this) { return prevEntry().key; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastReturned == null) @@ -1919,6 +1945,7 @@ public final boolean containsKey(@UnknownSignedness Object key) { } @EnsuresKeyFor(value={"#1"}, map={"this"}) + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final V put(K key, V value) { if (!inRange(key)) @@ -1926,6 +1953,7 @@ public final V put(K key, V value) { return m.put(key, value); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putIfAbsent(K key, V value) { if (!inRange(key)) @@ -1971,6 +1999,7 @@ public final V get(Object key) { return !inRange(key) ? null : m.get(key); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final V remove(Object key) { return !inRange(key) ? null : m.remove(key); @@ -2117,6 +2146,7 @@ public boolean contains(@UnknownSignedness Object o) { valEquals(node.getValue(), entry.getValue()); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { if (!(o instanceof Entry entry)) @@ -2211,10 +2241,12 @@ final class SubMapEntryIterator extends SubMapIterator> { TreeMap.Entry fence) { super(first, fence); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(@NonEmpty SubMapEntryIterator this) { return nextEntry(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { removeAscending(); @@ -2227,10 +2259,12 @@ final class DescendingSubMapEntryIterator extends SubMapIterator> super(last, fence); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(@NonEmpty DescendingSubMapEntryIterator this) { return prevEntry(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { removeDescending(); @@ -2244,10 +2278,12 @@ final class SubMapKeyIterator extends SubMapIterator TreeMap.Entry fence) { super(first, fence); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty SubMapKeyIterator this) { return nextEntry().key; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { removeAscending(); @@ -2284,10 +2320,12 @@ final class DescendingSubMapKeyIterator extends SubMapIterator TreeMap.Entry fence) { super(last, fence); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty DescendingSubMapKeyIterator this) { return prevEntry().key; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { removeDescending(); diff --git a/src/java.base/share/classes/java/util/TreeSet.java b/src/java.base/share/classes/java/util/TreeSet.java index d9f6109f653fd..d3a076c8fed2a 100644 --- a/src/java.base/share/classes/java/util/TreeSet.java +++ b/src/java.base/share/classes/java/util/TreeSet.java @@ -35,11 +35,11 @@ import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; /** * A {@link NavigableSet} implementation based on a {@link TreeMap}. @@ -210,6 +210,7 @@ public TreeSet(@Nullable Comparator comparator) { * @return an iterator over the elements in this set in descending order * @since 1.6 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @PolyGrowShrink @PolyNonEmpty Iterator descendingIterator(@PolyGrowShrink @PolyNonEmpty TreeSet this) { return m.descendingKeySet().iterator(); @@ -218,6 +219,7 @@ public TreeSet(@Nullable Comparator comparator) { /** * @since 1.6 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public NavigableSet descendingSet() { return new TreeSet<>(m.descendingMap()); @@ -283,6 +285,7 @@ public boolean contains(@GuardSatisfied TreeSet this, @GuardSatisfied @Unknow * does not permit null elements */ @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(@GuardSatisfied TreeSet this, E e) { return m.put(e, PRESENT)==null; @@ -305,6 +308,7 @@ public boolean add(@GuardSatisfied TreeSet this, E e) { * and this set uses natural ordering, or its comparator * does not permit null elements */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied TreeSet this, @GuardSatisfied @UnknownSignedness Object o) { return m.remove(o)==PRESENT; @@ -314,6 +318,7 @@ public boolean remove(@GuardSatisfied TreeSet this, @GuardSatisfied @UnknownS * Removes all of the elements from this set. * The set will be empty after this call returns. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied TreeSet this) { m.clear(); @@ -330,6 +335,7 @@ public void clear(@GuardSatisfied TreeSet this) { * if any element is null and this set uses natural ordering, or * its comparator does not permit null elements */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@GuardSatisfied TreeSet this, Collection c) { // Use linear-time version if applicable @@ -492,6 +498,7 @@ public E last(@GuardSatisfied @NonEmpty TreeSet this) { /** * @since 1.6 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollFirst(@GuardSatisfied TreeSet this) { Map.Entry e = m.pollFirstEntry(); @@ -501,6 +508,7 @@ public E last(@GuardSatisfied @NonEmpty TreeSet this) { /** * @since 1.6 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollLast(@GuardSatisfied TreeSet this) { Map.Entry e = m.pollLastEntry(); @@ -515,6 +523,7 @@ public E last(@GuardSatisfied @NonEmpty TreeSet this) { * @throws UnsupportedOperationException always * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { throw new UnsupportedOperationException(); @@ -528,6 +537,7 @@ public void addFirst(E e) { * @throws UnsupportedOperationException always * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { throw new UnsupportedOperationException(); @@ -625,6 +635,7 @@ private void readObject(java.io.ObjectInputStream s) * @return a {@code Spliterator} over the elements in this set * @since 1.8 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Spliterator spliterator() { return TreeMap.keySpliteratorFor(m); diff --git a/src/java.base/share/classes/java/util/Vector.java b/src/java.base/share/classes/java/util/Vector.java index cc185bfae349d..dc94c56fcbaac 100644 --- a/src/java.base/share/classes/java/util/Vector.java +++ b/src/java.base/share/classes/java/util/Vector.java @@ -38,12 +38,12 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; 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; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.io.IOException; import java.io.ObjectInputStream; @@ -549,6 +549,7 @@ public synchronized E lastElement(@NonEmpty Vector this) { * @throws ArrayIndexOutOfBoundsException if the index is out of range * ({@code index < 0 || index >= size()}) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized void setElementAt(@GuardSatisfied Vector this, E obj, @NonNegative int index) { if (index >= elementCount) { @@ -577,6 +578,7 @@ public synchronized void setElementAt(@GuardSatisfied Vector this, E obj, @No * @throws ArrayIndexOutOfBoundsException if the index is out of range * ({@code index < 0 || index >= size()}) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized void removeElementAt(@GuardSatisfied @CanShrink Vector this, @NonNegative int index) { if (index >= elementCount) { @@ -618,6 +620,7 @@ else if (index < 0) { * @throws ArrayIndexOutOfBoundsException if the index is out of range * ({@code index < 0 || index > size()}) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized void insertElementAt(@GuardSatisfied Vector this, E obj, @NonNegative int index) { if (index > elementCount) { @@ -647,6 +650,7 @@ public synchronized void insertElementAt(@GuardSatisfied Vector this, E obj, * * @param obj the component to be added */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized void addElement(@GuardSatisfied Vector this, E obj) { modCount++; @@ -668,6 +672,7 @@ public synchronized void addElement(@GuardSatisfied Vector this, E obj) { * @return {@code true} if the argument was a component of this * vector; {@code false} otherwise. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized boolean removeElement(@GuardSatisfied @CanShrink Vector this, Object obj) { modCount++; @@ -685,6 +690,7 @@ public synchronized boolean removeElement(@GuardSatisfied @CanShrink Vector t *

This method is identical in functionality to the {@link #clear} * method (which is part of the {@link List} interface). */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized void removeAllElements(@GuardSatisfied @CanShrink Vector this) { final Object[] es = elementData; @@ -805,6 +811,7 @@ public synchronized E get(@GuardSatisfied Vector this, @NonNegative int index * ({@code index < 0 || index >= size()}) * @since 1.2 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized E set(@GuardSatisfied Vector this, @NonNegative int index, E element) { if (index >= elementCount) @@ -836,6 +843,7 @@ private void add(E e, Object[] elementData, int s) { */ @SideEffectsOnly("this") @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized boolean add(@GuardSatisfied Vector this, E e) { modCount++; @@ -854,6 +862,7 @@ public synchronized boolean add(@GuardSatisfied Vector this, E e) { * @return true if the Vector contained the specified element * @since 1.2 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @CanShrink Vector this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { return removeElement(o); @@ -870,6 +879,7 @@ public boolean remove(@GuardSatisfied @CanShrink Vector this, @GuardSatisfied * ({@code index < 0 || index > size()}) * @since 1.2 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(@GuardSatisfied Vector this, @NonNegative int index, E element) { insertElementAt(element, index); @@ -886,6 +896,7 @@ public void add(@GuardSatisfied Vector this, @NonNegative int index, E elemen * ({@code index < 0 || index >= size()}) * @since 1.2 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized E remove(@GuardSatisfied @CanShrink Vector this, @NonNegative int index) { modCount++; @@ -908,6 +919,7 @@ public synchronized E remove(@GuardSatisfied @CanShrink Vector this, @NonNega * * @since 1.2 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink Vector this) { removeAllElements(); @@ -943,6 +955,7 @@ public synchronized boolean containsAll(@GuardSatisfied Vector this, @GuardSa * @throws NullPointerException if the specified collection is null * @since 1.2 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@GuardSatisfied Vector this, Collection c) { Object[] a = c.toArray(); @@ -978,6 +991,7 @@ public boolean addAll(@GuardSatisfied Vector this, Collection c) * or if the specified collection is null * @since 1.2 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(@GuardSatisfied @CanShrink Vector this, Collection c) { Objects.requireNonNull(c); @@ -1003,6 +1017,7 @@ public boolean removeAll(@GuardSatisfied @CanShrink Vector this, Collection this, Collection c) { Objects.requireNonNull(c); @@ -1014,6 +1029,7 @@ public boolean retainAll(@GuardSatisfied @CanShrink Vector this, Collection this, Predicate filter) { Objects.requireNonNull(filter); @@ -1084,6 +1100,7 @@ private synchronized boolean bulkRemove(Predicate filter) { * @throws NullPointerException if the specified collection is null * @since 1.2 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized boolean addAll(@GuardSatisfied Vector this, @NonNegative int index, Collection c) { if (index < 0 || index > elementCount) @@ -1190,6 +1207,7 @@ public synchronized String toString(@GuardSatisfied Vector this) { * This call shortens the list by {@code (toIndex - fromIndex)} elements. * (If {@code toIndex==fromIndex}, this operation has no effect.) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") protected synchronized void removeRange(@GuardSatisfied @CanShrink Vector this, int fromIndex, int toIndex) { modCount++; @@ -1321,6 +1339,7 @@ public E next(@NonEmpty Itr this) { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastRet == -1) @@ -1393,6 +1412,7 @@ public E previous() { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void set(E e) { if (lastRet == -1) @@ -1403,6 +1423,7 @@ public void set(E e) { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(E e) { int i = cursor; @@ -1453,6 +1474,7 @@ public synchronized void replaceAll(UnaryOperator operator) { @SuppressWarnings("unchecked") @Override + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized void sort(Comparator c) { final int expectedModCount = modCount; diff --git a/src/java.base/share/classes/java/util/WeakHashMap.java b/src/java.base/share/classes/java/util/WeakHashMap.java index 832b37d8d522f..7e8d3a46edade 100644 --- a/src/java.base/share/classes/java/util/WeakHashMap.java +++ b/src/java.base/share/classes/java/util/WeakHashMap.java @@ -36,12 +36,12 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; 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; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.lang.ref.WeakReference; import java.lang.ref.ReferenceQueue; @@ -483,6 +483,7 @@ Entry getEntry(Object key) { * previously associated {@code null} with {@code key}.) */ @EnsuresKeyFor(value={"#1"}, map={"this"}) + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V put(@GuardSatisfied WeakHashMap this, K key, V value) { Object k = maskNull(key); @@ -576,6 +577,7 @@ private void transfer(Entry[] src, Entry[] dest) { * @param m mappings to be stored in this map. * @throws NullPointerException if the specified map is null. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putAll(@GuardSatisfied WeakHashMap this, Map m) { int numKeysToBeAdded = m.size(); @@ -626,6 +628,7 @@ public void putAll(@GuardSatisfied WeakHashMap this, Map this, @GuardSatisfied @Nullable @UnknownSignedness Object key) { Object k = maskNull(key); @@ -686,6 +689,7 @@ boolean removeMapping(Object o) { * Removes all of the mappings from this map. * The map will be empty after this call returns. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied WeakHashMap this) { // clear out ref queue. We don't need to expunge entries @@ -767,6 +771,7 @@ public V getValue() { return value; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V setValue(V newValue) { V oldValue = value; @@ -859,6 +864,7 @@ protected Entry nextEntry() { return lastReturned; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastReturned == null) @@ -875,6 +881,7 @@ public void remove() { } private class ValueIterator extends HashIterator { + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V next(@NonEmpty ValueIterator this) { return nextEntry().value; @@ -882,6 +889,7 @@ public V next(@NonEmpty ValueIterator this) { } private class KeyIterator extends HashIterator { + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty KeyIterator this) { return nextEntry().getKey(); @@ -889,6 +897,7 @@ public K next(@NonEmpty KeyIterator this) { } private class EntryIterator extends HashIterator> { + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(@NonEmpty EntryIterator this) { return nextEntry(); @@ -939,6 +948,7 @@ public boolean contains(@Nullable @UnknownSignedness Object o) { return containsKey(o); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { if (containsKey(o)) { @@ -949,6 +959,7 @@ public boolean remove(@Nullable @UnknownSignedness Object o) { return false; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { WeakHashMap.this.clear(); @@ -1000,6 +1011,7 @@ public boolean contains(@Nullable @UnknownSignedness Object o) { return containsValue(o); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { WeakHashMap.this.clear(); @@ -1045,6 +1057,7 @@ && getEntry(e.getKey()) != null && getEntry(e.getKey()).equals(e); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { return removeMapping(o); @@ -1055,6 +1068,7 @@ public boolean remove(@Nullable @UnknownSignedness Object o) { return WeakHashMap.this.size(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { WeakHashMap.this.clear(); diff --git a/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java index 866cc2fe11a9a..a0b197c8c675b 100644 --- a/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java @@ -47,10 +47,10 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.lang.ref.WeakReference; import java.util.AbstractQueue; @@ -344,6 +344,7 @@ public ArrayBlockingQueue(int capacity, boolean fair, * @throws NullPointerException if the specified element is null */ @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { return super.add(e); @@ -358,6 +359,7 @@ public boolean add(E e) { * * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { Objects.requireNonNull(e); @@ -382,6 +384,7 @@ public boolean offer(E e) { * @throws InterruptedException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void put(E e) throws InterruptedException { Objects.requireNonNull(e); @@ -404,6 +407,7 @@ public void put(E e) throws InterruptedException { * @throws InterruptedException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException { @@ -425,6 +429,7 @@ public boolean offer(E e, long timeout, TimeUnit unit) } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E poll(@GuardSatisfied @CanShrink ArrayBlockingQueue this) { final ReentrantLock lock = this.lock; @@ -436,6 +441,7 @@ public E poll(@GuardSatisfied @CanShrink ArrayBlockingQueue this) { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E take(@GuardSatisfied @CanShrink ArrayBlockingQueue this) throws InterruptedException { final ReentrantLock lock = this.lock; @@ -449,6 +455,7 @@ public E take(@GuardSatisfied @CanShrink ArrayBlockingQueue this) throws Inte } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E poll(@GuardSatisfied @CanShrink ArrayBlockingQueue this, long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); @@ -535,6 +542,7 @@ 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 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink ArrayBlockingQueue this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { if (o == null) return false; @@ -687,6 +695,7 @@ public String toString() { * Atomically removes all of the elements from this queue. * The queue will be empty after this call returns. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink ArrayBlockingQueue this) { final ReentrantLock lock = this.lock; @@ -727,6 +736,7 @@ private static void circularClear(Object[] items, int i, int end) { * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink ArrayBlockingQueue this, Collection c) { return drainTo(c, Integer.MAX_VALUE); @@ -738,6 +748,7 @@ public int drainTo(@GuardSatisfied @CanShrink ArrayBlockingQueue this, Collec * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink ArrayBlockingQueue this, Collection c, int maxElements) { Objects.requireNonNull(c); @@ -1305,6 +1316,7 @@ public void forEachRemaining(Consumer action) { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { final ReentrantLock lock = ArrayBlockingQueue.this.lock; @@ -1507,6 +1519,7 @@ public void forEach(Consumer action) { /** * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink ArrayBlockingQueue this, Predicate filter) { Objects.requireNonNull(filter); @@ -1516,6 +1529,7 @@ public boolean removeIf(@CanShrink ArrayBlockingQueue this, Predicate this, Collection c) { Objects.requireNonNull(c); @@ -1525,6 +1539,7 @@ public boolean removeAll(@CanShrink ArrayBlockingQueue this, Collection this, Collection c) { Objects.requireNonNull(c); diff --git a/src/java.base/share/classes/java/util/concurrent/BlockingDeque.java b/src/java.base/share/classes/java/util/concurrent/BlockingDeque.java index 914985bf9b4a1..38f993ecc10d2 100644 --- a/src/java.base/share/classes/java/util/concurrent/BlockingDeque.java +++ b/src/java.base/share/classes/java/util/concurrent/BlockingDeque.java @@ -45,10 +45,10 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.Deque; import java.util.Iterator; @@ -232,6 +232,7 @@ public interface BlockingDeque extends BlockingQueue< * @throws NullPointerException if the specified element is null * @throws IllegalArgumentException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void addFirst(E e); @@ -248,6 +249,7 @@ public interface BlockingDeque extends BlockingQueue< * @throws NullPointerException if the specified element is null * @throws IllegalArgumentException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void addLast(E e); @@ -265,6 +267,7 @@ public interface BlockingDeque extends BlockingQueue< * @throws NullPointerException if the specified element is null * @throws IllegalArgumentException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean offerFirst(E e); @@ -282,6 +285,7 @@ public interface BlockingDeque extends BlockingQueue< * @throws NullPointerException if the specified element is null * @throws IllegalArgumentException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean offerLast(E e); @@ -297,6 +301,7 @@ public interface BlockingDeque extends BlockingQueue< * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void putFirst(E e) throws InterruptedException; @@ -312,6 +317,7 @@ public interface BlockingDeque extends BlockingQueue< * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void putLast(E e) throws InterruptedException; @@ -334,6 +340,7 @@ public interface BlockingDeque extends BlockingQueue< * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException; @@ -357,6 +364,7 @@ boolean offerFirst(E e, long timeout, TimeUnit unit) * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean offerLast(E e, long timeout, TimeUnit unit) throws InterruptedException; @@ -368,6 +376,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * @return the head of this deque * @throws InterruptedException if interrupted while waiting */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E takeFirst(@CanShrink BlockingDeque this) throws InterruptedException; @@ -378,6 +387,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * @return the tail of this deque * @throws InterruptedException if interrupted while waiting */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E takeLast(@CanShrink BlockingDeque this) throws InterruptedException; @@ -394,6 +404,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * waiting time elapses before an element is available * @throws InterruptedException if interrupted while waiting */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E pollFirst(@CanShrink BlockingDeque this, long timeout, TimeUnit unit) throws InterruptedException; @@ -411,6 +422,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * waiting time elapses before an element is available * @throws InterruptedException if interrupted while waiting */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E pollLast(@CanShrink BlockingDeque this, long timeout, TimeUnit unit) throws InterruptedException; @@ -431,6 +443,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * @throws NullPointerException if the specified element is null * (optional) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean removeFirstOccurrence(@CanShrink BlockingDeque this, Object o); @@ -450,6 +463,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * @throws NullPointerException if the specified element is null * (optional) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean removeLastOccurrence(@CanShrink BlockingDeque this, Object o); @@ -474,6 +488,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresNonEmpty("this") boolean add(E e); @@ -496,6 +511,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean offer(E e); @@ -514,6 +530,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void put(E e) throws InterruptedException; @@ -535,6 +552,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException; @@ -550,6 +568,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * @return the head of the queue represented by this deque * @throws NoSuchElementException if this deque is empty */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E remove(@GuardSatisfied @NonEmpty @CanShrink BlockingDeque this); @@ -562,6 +581,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * * @return the head of this deque, or {@code null} if this deque is empty */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E poll(@CanShrink BlockingDeque this); @@ -575,6 +595,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * @return the head of this deque * @throws InterruptedException if interrupted while waiting */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E take(@CanShrink BlockingDeque this) throws InterruptedException; @@ -590,6 +611,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * specified waiting time elapses before an element is available * @throws InterruptedException if interrupted while waiting */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E poll(@CanShrink BlockingDeque this, long timeout, TimeUnit unit) throws InterruptedException; @@ -639,6 +661,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * @throws NullPointerException if the specified element is null * (optional) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean remove(@CanShrink BlockingDeque this, @UnknownSignedness Object o); @@ -691,6 +714,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * @throws NullPointerException if the specified element is null * @throws IllegalArgumentException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void push(E e); } diff --git a/src/java.base/share/classes/java/util/concurrent/BlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/BlockingQueue.java index 76a8d29b5a1c9..4c9ce10a7ed77 100644 --- a/src/java.base/share/classes/java/util/concurrent/BlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/BlockingQueue.java @@ -43,9 +43,9 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.Collection; import java.util.Queue; @@ -209,6 +209,7 @@ public interface BlockingQueue extends Queue { * element prevents it from being added to this queue */ @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean add(E e); @@ -229,6 +230,7 @@ public interface BlockingQueue extends Queue { * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this queue */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean offer(E e); @@ -244,6 +246,7 @@ public interface BlockingQueue extends Queue { * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this queue */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void put(E e) throws InterruptedException; @@ -265,6 +268,7 @@ public interface BlockingQueue extends Queue { * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this queue */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException; @@ -276,6 +280,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * @return the head of this queue * @throws InterruptedException if interrupted while waiting */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E take() throws InterruptedException; @@ -291,6 +296,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * specified waiting time elapses before an element is available * @throws InterruptedException if interrupted while waiting */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E poll(long timeout, TimeUnit unit) throws InterruptedException; @@ -326,6 +332,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * @throws NullPointerException if the specified element is null * (optional) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean remove(@CanShrink BlockingQueue this, @UnknownSignedness Object o); @@ -369,6 +376,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * queue, or some property of an element of this queue prevents * it from being added to the specified collection */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") int drainTo(@GuardSatisfied @CanShrink BlockingQueue this, Collection c); @@ -395,6 +403,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * queue, or some property of an element of this queue prevents * it from being added to the specified collection */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") int drainTo(@GuardSatisfied @CanShrink BlockingQueue this, Collection c, int maxElements); } diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java index bc2aa9ab1d8f0..d306545bacd63 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java @@ -48,11 +48,11 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; 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.DoesNotUnrefineReceiver; import java.io.ObjectStreamField; import java.io.Serializable; @@ -665,6 +665,7 @@ static class Node implements Map.Entry { public final String toString() { return Helpers.mapEntryToString(key, val); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final V setValue(V value) { throw new UnsupportedOperationException(); @@ -1031,6 +1032,7 @@ public boolean containsValue(@GuardSatisfied @UnknownSignedness Object value) { * @throws NullPointerException if the specified key or value is null */ @EnsuresKeyFor(value={"#1"}, map={"this"}) + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V put(K key, V value) { return putVal(key, value, false); @@ -1113,6 +1115,7 @@ else if (f instanceof ReservationNode) * * @param m mappings to be stored in this map */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putAll(Map m) { tryPresize(m.size()); @@ -1129,6 +1132,7 @@ public void putAll(Map m) { * {@code null} if there was no mapping for {@code key} * @throws NullPointerException if the specified key is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V remove(@GuardSatisfied @UnknownSignedness Object key) { return replaceNode(key, null, null); @@ -1215,6 +1219,7 @@ else if (f instanceof ReservationNode) /** * Removes all of the mappings from this map. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { long delta = 0L; // negative number of deletions @@ -1576,6 +1581,7 @@ private void readObject(java.io.ObjectInputStream s) * @throws NullPointerException if the specified key or value is null */ @EnsuresKeyFor(value={"#1"}, map={"this"}) + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V putIfAbsent(K key, V value) { return putVal(key, value, true); @@ -1586,6 +1592,7 @@ private void readObject(java.io.ObjectInputStream s) * * @throws NullPointerException if the specified key is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @UnknownSignedness Object key, @GuardSatisfied @UnknownSignedness Object value) { if (key == null) @@ -1598,6 +1605,7 @@ public boolean remove(@GuardSatisfied @UnknownSignedness Object key, @GuardSatis * * @throws NullPointerException if any of the arguments are null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { if (key == null || oldValue == null || newValue == null) @@ -1612,6 +1620,7 @@ public boolean replace(K key, V oldValue, V newValue) { * or {@code null} if there was no mapping for the key * @throws NullPointerException if the specified key or value is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V replace(K key, V value) { if (key == null || value == null) @@ -3494,6 +3503,7 @@ static class BaseIterator extends Traverser { @Pure public final boolean hasMoreElements() { return next != null; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void remove() { Node p; @@ -3511,6 +3521,7 @@ static final class KeyIterator extends BaseIterator super(tab, size, index, limit, map); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final K next(@NonEmpty KeyIterator this) { Node p; @@ -3522,6 +3533,7 @@ public final K next(@NonEmpty KeyIterator this) { return k; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final K nextElement(@NonEmpty KeyIterator this) { return next(); } } @@ -3533,6 +3545,7 @@ static final class ValueIterator extends BaseIterator super(tab, size, index, limit, map); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final V next(@NonEmpty ValueIterator this) { Node p; @@ -3544,6 +3557,7 @@ public final V next(@NonEmpty ValueIterator this) { return v; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final V nextElement(@NonEmpty ValueIterator this) { return next(); } } @@ -3555,6 +3569,7 @@ static final class EntryIterator extends BaseIterator super(tab, size, index, limit, map); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final Map.Entry next(@NonEmpty EntryIterator this) { Node p; @@ -3604,6 +3619,7 @@ public boolean equals(Object o) { * could even have been removed, in which case the put will * re-establish). We do not and cannot guarantee more. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V setValue(V value) { if (value == null) throw new NullPointerException(); @@ -4496,6 +4512,7 @@ abstract static sealed class CollectionView * Removes all of the elements from this view, by removing all * the mappings from the map backing this view. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void clear() { map.clear(); } @Pure @@ -4519,6 +4536,7 @@ abstract static sealed class CollectionView @Pure @EnsuresNonEmptyIf(result = true, expression = "this") public abstract boolean contains(@UnknownSignedness Object o); + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public abstract boolean remove(@UnknownSignedness Object o); @@ -4616,6 +4634,7 @@ public final boolean containsAll(Collection c) { if (c == null) throw new NullPointerException(); @@ -4639,6 +4658,7 @@ public boolean removeAll(Collection c) { if (c == null) throw new NullPointerException(); @@ -4704,6 +4724,7 @@ public static final class KeySetView extends CollectionView * @return {@code true} if the backing map contained the specified key * @throws NullPointerException if the specified key is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { return map.remove(o) != null; } @@ -4729,6 +4750,7 @@ public Iterator iterator() { * for additions was provided */ @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(K e) { V v; @@ -4748,6 +4770,7 @@ public boolean add(K e) { * @throws UnsupportedOperationException if no default mapped value * for additions was provided */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { boolean added = false; @@ -4810,6 +4833,7 @@ public final boolean contains(@UnknownSignedness Object o) { return map.containsValue(o); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final boolean remove(@UnknownSignedness Object o) { if (o != null) { @@ -4832,10 +4856,12 @@ public final Iterator iterator() { } @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final boolean add(V e) { throw new UnsupportedOperationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final boolean addAll(Collection c) { throw new UnsupportedOperationException(); @@ -4853,6 +4879,7 @@ public final boolean addAll(Collection c) { return modified; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { return map.removeValueIf(filter); @@ -4899,6 +4926,7 @@ public boolean contains(@UnknownSignedness Object o) { (v == r || v.equals(r))); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { Object k, v; Map.Entry e; @@ -4920,11 +4948,13 @@ public Iterator> iterator() { } @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(Entry e) { return map.putVal(e.getKey(), e.getValue(), false) == null; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection> c) { boolean added = false; @@ -4935,6 +4965,7 @@ public boolean addAll(Collection> c) { return added; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate> filter) { return map.removeEntryIf(filter); diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java index 1c954fa07185e..70b0e5b0bd81a 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java @@ -48,11 +48,11 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; 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.DoesNotUnrefineReceiver; import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; @@ -843,6 +843,7 @@ private void initHeadTail(Node h, Node t) { * * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { linkFirst(e); @@ -857,6 +858,7 @@ public void addFirst(E e) { * * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { linkLast(e); @@ -869,6 +871,7 @@ public void addLast(E e) { * @return {@code true} (as specified by {@link Deque#offerFirst}) * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offerFirst(E e) { linkFirst(e); @@ -884,6 +887,7 @@ public boolean offerFirst(E e) { * @return {@code true} (as specified by {@link Deque#offerLast}) * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offerLast(E e) { linkLast(e); @@ -936,6 +940,7 @@ public E getLast(@NonEmpty ConcurrentLinkedDeque this) { return screenNullResult(peekLast()); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollFirst(@GuardSatisfied @CanShrink ConcurrentLinkedDeque this) { restart: for (;;) { @@ -958,6 +963,7 @@ public E getLast(@NonEmpty ConcurrentLinkedDeque this) { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollLast(@GuardSatisfied @CanShrink ConcurrentLinkedDeque this) { restart: for (;;) { @@ -983,6 +989,7 @@ public E getLast(@NonEmpty ConcurrentLinkedDeque this) { /** * @throws NoSuchElementException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeFirst(@GuardSatisfied @NonEmpty @CanShrink ConcurrentLinkedDeque this) { return screenNullResult(pollFirst()); @@ -991,6 +998,7 @@ public E removeFirst(@GuardSatisfied @NonEmpty @CanShrink ConcurrentLinkedDeque< /** * @throws NoSuchElementException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeLast(@GuardSatisfied @NonEmpty @CanShrink ConcurrentLinkedDeque this) { return screenNullResult(pollLast()); @@ -1005,6 +1013,7 @@ public E removeLast(@GuardSatisfied @NonEmpty @CanShrink ConcurrentLinkedDeque this) { return pollFirst(); } @Pure @@ -1032,12 +1043,14 @@ public boolean add(E e) { /** * @throws NoSuchElementException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(@NonEmpty @CanShrink ConcurrentLinkedDeque this) { return removeFirst(); } /** * @throws NoSuchElementException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E pop(@GuardSatisfied @NonEmpty @CanShrink ConcurrentLinkedDeque this) { return removeFirst(); } @@ -1049,6 +1062,7 @@ public boolean add(E e) { /** * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void push(E e) { addFirst(e); } @@ -1064,6 +1078,7 @@ public boolean add(E e) { * @return {@code true} if the deque contained the specified element * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeFirstOccurrence(@CanShrink ConcurrentLinkedDeque this, Object o) { Objects.requireNonNull(o); @@ -1091,6 +1106,7 @@ public boolean removeFirstOccurrence(@CanShrink ConcurrentLinkedDeque this, O * @return {@code true} if the deque contained the specified element * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeLastOccurrence(@CanShrink ConcurrentLinkedDeque this, Object o) { Objects.requireNonNull(o); @@ -1184,6 +1200,7 @@ public int size() { * @return {@code true} if the deque contained the specified element * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink ConcurrentLinkedDeque this, @GuardSatisfied @UnknownSignedness Object o) { return removeFirstOccurrence(o); @@ -1201,6 +1218,7 @@ public boolean remove(@CanShrink ConcurrentLinkedDeque this, @GuardSatisfied * of its elements are null * @throws IllegalArgumentException if the collection is this deque */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { if (c == this) @@ -1256,6 +1274,7 @@ else if (p.prev == p) // NEXT_TERMINATOR /** * Removes all of the elements from this deque. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink ConcurrentLinkedDeque this) { while (pollFirst() != null) @@ -1474,6 +1493,7 @@ public E next(@NonEmpty AbstractItr this) { return item; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { Node l = lastRet; @@ -1660,6 +1680,7 @@ private void readObject(java.io.ObjectInputStream s) /** * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink ConcurrentLinkedDeque this, Predicate filter) { Objects.requireNonNull(filter); @@ -1669,6 +1690,7 @@ public boolean removeIf(@CanShrink ConcurrentLinkedDeque this, Predicate this, Collection c) { Objects.requireNonNull(c); @@ -1678,6 +1700,7 @@ public boolean removeAll(@CanShrink ConcurrentLinkedDeque this, Collection this, Collection c) { Objects.requireNonNull(c); diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java index 131d03389196c..c5f44e2e63d60 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java @@ -47,11 +47,11 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; 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.DoesNotUnrefineReceiver; import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; @@ -299,6 +299,7 @@ public ConcurrentLinkedQueue(Collection c) { * @throws NullPointerException if the specified element is null */ @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { return offer(e); @@ -372,6 +373,7 @@ private Node skipDeadNodes(Node pred, Node c, Node p, Node q) { * @return {@code true} (as specified by {@link Queue#offer}) * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { final Node newNode = new Node(Objects.requireNonNull(e)); @@ -402,6 +404,7 @@ else if (p == q) } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink ConcurrentLinkedQueue this) { restartFromHead: for (;;) { @@ -547,6 +550,7 @@ public boolean contains(@GuardSatisfied @UnknownSignedness Object o) { * @param o element to be removed from this queue, if present * @return {@code true} if this queue changed as a result of the call */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink ConcurrentLinkedQueue this, @GuardSatisfied @UnknownSignedness Object o) { if (o == null) return false; @@ -584,6 +588,7 @@ public boolean remove(@CanShrink ConcurrentLinkedQueue this, @GuardSatisfied * of its elements are null * @throws IllegalArgumentException if the collection is this queue */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { if (c == this) @@ -832,6 +837,7 @@ public E next(@NonEmpty Itr this) { // Default implementation of forEachRemaining is "good enough". + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { Node l = lastRet; @@ -999,6 +1005,7 @@ public Spliterator spliterator() { /** * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink ConcurrentLinkedQueue this, Predicate filter) { Objects.requireNonNull(filter); @@ -1008,6 +1015,7 @@ public boolean removeIf(@CanShrink ConcurrentLinkedQueue this, Predicate this, Collection c) { Objects.requireNonNull(c); @@ -1017,12 +1025,14 @@ public boolean removeAll(@CanShrink ConcurrentLinkedQueue this, Collection this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> !c.contains(e)); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink ConcurrentLinkedQueue this) { bulkRemove(e -> true); diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentMap.java index f063bb3d726c8..a50b12fcabdfa 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentMap.java @@ -35,14 +35,14 @@ package java.util.concurrent; -import org.checkerframework.checker.signedness.qual.UnknownSignedness; import org.checkerframework.checker.nullness.qual.EnsuresKeyFor; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.PolyNull; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; +import org.checkerframework.checker.signedness.qual.UnknownSignedness; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.Map; import java.util.Objects; @@ -167,6 +167,7 @@ default void forEach(BiConsumer action) { * or value prevents it from being stored in this map */ @EnsuresKeyFor(value={"#1"}, map={"this"}) + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable V putIfAbsent(K key, V value); @@ -199,6 +200,7 @@ default void forEach(BiConsumer action) { * and this map does not permit null keys or values * (optional) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean remove(@UnknownSignedness Object key, @UnknownSignedness Object value); @@ -232,6 +234,7 @@ default void forEach(BiConsumer action) { * @throws IllegalArgumentException if some property of a specified key * or value prevents it from being stored in this map */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean replace(K key, V oldValue, V newValue); @@ -265,6 +268,7 @@ default void forEach(BiConsumer action) { * @throws IllegalArgumentException if some property of the specified key * or value prevents it from being stored in this map */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable V replace(K key, V value); diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java index 416b19495c90c..89b7d80ebb258 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java @@ -44,10 +44,10 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; @@ -1357,6 +1357,7 @@ public V getOrDefault(@GuardSatisfied @UnknownSignedness Object key, V defaultVa * with the keys currently in the map * @throws NullPointerException if the specified key or value is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V put(K key, V value) { if (value == null) @@ -1374,6 +1375,7 @@ public V put(K key, V value) { * with the keys currently in the map * @throws NullPointerException if the specified key is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V remove(@GuardSatisfied @UnknownSignedness Object key) { return doRemove(key, null); @@ -1430,6 +1432,7 @@ public boolean isEmpty() { /** * Removes all of the mappings from this map. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { Index h, r, d; Node b; @@ -1814,6 +1817,7 @@ public boolean equals(@Nullable Object o) { * with the keys currently in the map * @throws NullPointerException if the specified key or value is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putIfAbsent(K key, V value) { if (value == null) @@ -1828,6 +1832,7 @@ public V putIfAbsent(K key, V value) { * with the keys currently in the map * @throws NullPointerException if the specified key is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @UnknownSignedness Object key, @GuardSatisfied @UnknownSignedness Object value) { if (key == null) @@ -1842,6 +1847,7 @@ public boolean remove(@GuardSatisfied @UnknownSignedness Object key, @GuardSatis * with the keys currently in the map * @throws NullPointerException if any of the arguments are null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { if (key == null || oldValue == null || newValue == null) @@ -1868,6 +1874,7 @@ public boolean replace(K key, V oldValue, V newValue) { * with the keys currently in the map * @throws NullPointerException if the specified key or value is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { if (key == null || value == null) @@ -1915,6 +1922,7 @@ public K lastKey(@NonEmpty ConcurrentSkipListMap this) { * @throws UnsupportedOperationException always * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putFirst(K k, V v) { throw new UnsupportedOperationException(); @@ -1928,6 +1936,7 @@ public V putFirst(K k, V v) { * @throws UnsupportedOperationException always * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putLast(K k, V v) { throw new UnsupportedOperationException(); @@ -2127,6 +2136,7 @@ public Map.Entry lastEntry() { * The returned entry does not support * the {@code Entry.setValue} method. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry pollFirstEntry() { return doRemoveFirstEntry(); @@ -2138,6 +2148,7 @@ public Map.Entry pollFirstEntry() { * The returned entry does not support * the {@code Entry.setValue} method. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry pollLastEntry() { return doRemoveLastEntry(); @@ -2179,6 +2190,7 @@ final void advance(Node b) { next = n; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void remove() { Node n; K k; @@ -2192,6 +2204,7 @@ public final void remove() { } final class ValueIterator extends Iter { + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V next(@NonEmpty ValueIterator this) { V v; @@ -2203,6 +2216,7 @@ public V next(@NonEmpty ValueIterator this) { } final class KeyIterator extends Iter { + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty KeyIterator this) { Node n; @@ -2215,6 +2229,7 @@ public K next(@NonEmpty KeyIterator this) { } final class EntryIterator extends Iter> { + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(@NonEmpty EntryIterator this) { Node n; @@ -2255,8 +2270,10 @@ static final class KeySet @Pure @EnsuresNonEmptyIf(result = true, expression = "this") public boolean contains(@UnknownSignedness Object o) { return m.containsKey(o); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { return m.remove(o) != null; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { m.clear(); } public K lower(K e) { return m.lowerKey(e); } @@ -2266,11 +2283,13 @@ static final class KeySet public Comparator comparator() { return m.comparator(); } public K first() { return m.firstKey(); } public K last() { return m.lastKey(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public K pollFirst() { Map.Entry e = m.pollFirstEntry(); return (e == null) ? null : e.getKey(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public K pollLast() { Map.Entry e = m.pollLastEntry(); @@ -2349,6 +2368,7 @@ public Iterator iterator() { @Pure @EnsuresNonEmptyIf(result = true, expression = "this") public boolean contains(@UnknownSignedness Object o) { return m.containsValue(o); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { m.clear(); } public Object[] toArray() { return toList(this).toArray(); } @@ -2360,6 +2380,7 @@ public Spliterator spliterator() { : ((SubMap)m).new SubMapValueIterator(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { if (filter == null) throw new NullPointerException(); @@ -2399,6 +2420,7 @@ public boolean contains(@UnknownSignedness Object o) { V v = m.get(e.getKey()); return v != null && v.equals(e.getValue()); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { if (!(o instanceof Map.Entry)) @@ -2416,6 +2438,7 @@ public boolean isEmpty() { public int size() { return m.size(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { m.clear(); @@ -2440,6 +2463,7 @@ public Spliterator> spliterator() { ? ((ConcurrentSkipListMap)m).entrySpliterator() : ((SubMap)m).new SubMapEntryIterator(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate> filter) { if (filter == null) throw new NullPointerException(); @@ -2727,12 +2751,14 @@ public V get(Object key) { return (!inBounds(key, m.comparator)) ? null : m.get(key); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V put(K key, V value) { checkKeyBounds(key, m.comparator); return m.put(key, value); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V remove(Object key) { return (!inBounds(key, m.comparator)) ? null : m.remove(key); @@ -2773,6 +2799,7 @@ public boolean containsValue(@UnknownSignedness Object value) { return false; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { Comparator cmp = m.comparator; @@ -2786,23 +2813,27 @@ public void clear() { /* ---------------- ConcurrentMap API methods -------------- */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putIfAbsent(K key, V value) { checkKeyBounds(key, m.comparator); return m.putIfAbsent(key, value); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object key, @UnknownSignedness Object value) { return inBounds(key, m.comparator) && m.remove(key, value); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { checkKeyBounds(key, m.comparator); return m.replace(key, oldValue, newValue); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { checkKeyBounds(key, m.comparator); @@ -2953,11 +2984,13 @@ public Map.Entry lastEntry() { return isDescending ? lowestEntry() : highestEntry(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry pollFirstEntry() { return isDescending ? removeHighest() : removeLowest(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry pollLastEntry() { return isDescending ? removeLowest() : removeHighest(); @@ -3076,6 +3109,7 @@ private void descend() { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { Node l = lastReturned; @@ -3109,6 +3143,7 @@ public long estimateSize() { } final class SubMapValueIterator extends SubMapIter { + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V next(@NonEmpty SubMapValueIterator this) { V v = nextValue; @@ -3121,6 +3156,7 @@ public int characteristics() { } final class SubMapKeyIterator extends SubMapIter { + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty SubMapKeyIterator this) { Node n = next; @@ -3137,6 +3173,7 @@ public final Comparator getComparator() { } final class SubMapEntryIterator extends SubMapIter> { + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(@NonEmpty SubMapEntryIterator this) { Node n = next; diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java index eaf6fccb55253..c428db68c69c0 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java @@ -45,10 +45,10 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.lang.reflect.Field; import java.util.AbstractSet; @@ -262,6 +262,7 @@ public boolean contains(@GuardSatisfied @UnknownSignedness Object o) { * @throws NullPointerException if the specified element is null */ @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { return m.putIfAbsent(e, Boolean.TRUE) == null; @@ -281,6 +282,7 @@ public boolean add(E e) { * with the elements currently in this set * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @UnknownSignedness Object o) { return m.remove(o, Boolean.TRUE); @@ -289,6 +291,7 @@ public boolean remove(@GuardSatisfied @UnknownSignedness Object o) { /** * Removes all of the elements from this set. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { m.clear(); @@ -358,6 +361,7 @@ public boolean equals(@Nullable Object o) { * @throws NullPointerException if the specified collection or any * of its elements are null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { // Override AbstractSet version to avoid unnecessary call to size() @@ -402,12 +406,14 @@ public E higher(E e) { return m.higherKey(e); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollFirst() { Map.Entry e = m.pollFirstEntry(); return (e == null) ? null : e.getKey(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollLast() { Map.Entry e = m.pollLastEntry(); diff --git a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java index 1232f004e21ae..3b855eaad0d36 100644 --- a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java +++ b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java @@ -47,10 +47,10 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.lang.invoke.VarHandle; import java.lang.reflect.Field; @@ -460,6 +460,7 @@ public E getLast() { * * @throws IndexOutOfBoundsException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E set(int index, E element) { synchronized (lock) { @@ -483,6 +484,7 @@ public E set(int index, E element) { * @return {@code true} (as specified by {@link Collection#add}) */ @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { synchronized (lock) { @@ -502,6 +504,7 @@ public boolean add(E e) { * * @throws IndexOutOfBoundsException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(int index, E element) { synchronized (lock) { @@ -529,6 +532,7 @@ public void add(int index, E element) { * * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { add(0, e); @@ -539,6 +543,7 @@ public void addFirst(E e) { * * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { synchronized (lock) { @@ -553,6 +558,7 @@ public void addLast(E e) { * * @throws IndexOutOfBoundsException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @CanShrink CopyOnWriteArrayList this, int index) { synchronized (lock) { @@ -580,6 +586,7 @@ public E remove(@GuardSatisfied @CanShrink CopyOnWriteArrayList this, int ind * @throws NoSuchElementException {@inheritDoc} * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeFirst() { synchronized (lock) { @@ -596,6 +603,7 @@ public E removeFirst() { * @throws NoSuchElementException {@inheritDoc} * @since 21 */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeLast() { synchronized (lock) { @@ -619,6 +627,7 @@ public E removeLast() { * @param o element to be removed from this list, if present * @return {@code true} if this list contained the specified element */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink CopyOnWriteArrayList this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { Object[] snapshot = getArray(); @@ -700,6 +709,7 @@ void removeRange(@GuardSatisfied @CanShrink CopyOnWriteArrayList this, int fr * @param e element to be added to this list, if absent * @return {@code true} if the element was added */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addIfAbsent(E e) { Object[] snapshot = getArray(); @@ -769,6 +779,7 @@ public boolean containsAll(Collection c) { * or if the specified collection is null * @see #remove(Object) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(@CanShrink CopyOnWriteArrayList this, Collection c) { Objects.requireNonNull(c); @@ -791,6 +802,7 @@ public boolean removeAll(@CanShrink CopyOnWriteArrayList this, Collection this, Collection c) { Objects.requireNonNull(c); @@ -808,6 +820,7 @@ public boolean retainAll(@GuardSatisfied @CanShrink CopyOnWriteArrayList this * @throws NullPointerException if the specified collection is null * @see #addIfAbsent(Object) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int addAllAbsent(Collection c) { Object[] cs = c.toArray(); @@ -840,6 +853,7 @@ public int addAllAbsent(Collection c) { * Removes all of the elements from this list. * The list will be empty after this call returns. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink CopyOnWriteArrayList this) { synchronized (lock) { @@ -857,6 +871,7 @@ public void clear(@GuardSatisfied @CanShrink CopyOnWriteArrayList this) { * @throws NullPointerException if the specified collection is null * @see #add(Object) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { Object[] cs = (c.getClass() == CopyOnWriteArrayList.class) ? @@ -895,6 +910,7 @@ public boolean addAll(Collection c) { * @throws NullPointerException if the specified collection is null * @see #add(int,Object) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(int index, Collection c) { Object[] cs = c.toArray(); @@ -936,6 +952,7 @@ public void forEach(Consumer action) { /** * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink CopyOnWriteArrayList this, Predicate filter) { Objects.requireNonNull(filter); @@ -1010,6 +1027,7 @@ void replaceAllRange(UnaryOperator operator, int i, int end) { setArray(es); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void sort(Comparator c) { synchronized (lock) { @@ -1258,6 +1276,7 @@ public int previousIndex() { * @throws UnsupportedOperationException always; {@code remove} * is not supported by this iterator. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { throw new UnsupportedOperationException(); @@ -1268,6 +1287,7 @@ public void remove() { * @throws UnsupportedOperationException always; {@code set} * is not supported by this iterator. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void set(E e) { throw new UnsupportedOperationException(); @@ -1278,6 +1298,7 @@ public void set(E e) { * @throws UnsupportedOperationException always; {@code add} * is not supported by this iterator. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(E e) { throw new UnsupportedOperationException(); @@ -1486,6 +1507,7 @@ public boolean equals(Object o) { return !it.hasNext(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E set(int index, E element) { synchronized (lock) { @@ -1532,6 +1554,7 @@ public int size() { } @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E element) { synchronized (lock) { @@ -1543,6 +1566,7 @@ public boolean add(E element) { return true; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(int index, E element) { synchronized (lock) { @@ -1554,11 +1578,13 @@ public void add(int index, E element) { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { add(0, e); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { synchronized (lock) { @@ -1566,6 +1592,7 @@ public void addLast(E e) { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { synchronized (lock) { @@ -1577,6 +1604,7 @@ public boolean addAll(Collection c) { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(int index, Collection c) { synchronized (lock) { @@ -1589,6 +1617,7 @@ public boolean addAll(int index, Collection c) { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { synchronized (lock) { @@ -1599,6 +1628,7 @@ public void clear() { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(int index) { synchronized (lock) { @@ -1611,6 +1641,7 @@ public E remove(int index) { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeFirst() { synchronized (lock) { @@ -1621,6 +1652,7 @@ public E removeFirst() { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeLast() { synchronized (lock) { @@ -1631,6 +1663,7 @@ public E removeLast() { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { synchronized (lock) { @@ -1690,6 +1723,7 @@ public void replaceAll(UnaryOperator operator) { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void sort(Comparator c) { synchronized (lock) { @@ -1699,18 +1733,21 @@ public void sort(Comparator c) { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> c.contains(e)); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> !c.contains(e)); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { Objects.requireNonNull(filter); @@ -1841,8 +1878,10 @@ class DescendingIterator implements Iterator { } } public boolean hasNext() { return it.hasPrevious(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next() { return it.previous(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { it.remove(); } } @@ -1864,6 +1903,7 @@ public boolean hasNext() { return it.hasPrevious(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next() { return it.previous(); @@ -1885,16 +1925,19 @@ public int previousIndex() { return nextIndex() - 1; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { throw new UnsupportedOperationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void set(E e) { throw new UnsupportedOperationException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(E e) { throw new UnsupportedOperationException(); @@ -1919,12 +1962,14 @@ public Spliterator spliterator() { // ========== Collection ========== + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { base.add(0, e); return true; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { @SuppressWarnings("unchecked") @@ -1938,6 +1983,7 @@ public boolean addAll(Collection c) { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { base.clear(); @@ -1985,6 +2031,7 @@ public Stream parallelStream() { return StreamSupport.stream(spliterator(), true); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(Object o) { synchronized (lock) { @@ -1996,11 +2043,13 @@ public boolean remove(Object o) { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { return base.removeAll(c); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { return base.retainAll(c); @@ -2047,6 +2096,7 @@ public String toString() { // ========== List ========== + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(int index, E element) { synchronized (lock) { @@ -2054,16 +2104,19 @@ public void add(int index, E element) { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { base.add(e); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { base.add(0, e); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(int index, Collection c) { @SuppressWarnings("unchecked") @@ -2126,6 +2179,7 @@ public ListIterator listIterator(int index) { return new DescendingListIterator(index); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(int index) { synchronized (lock) { @@ -2133,6 +2187,7 @@ public E remove(int index) { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeFirst() { synchronized (lock) { @@ -2144,6 +2199,7 @@ public E removeFirst() { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeLast() { synchronized (lock) { @@ -2154,6 +2210,7 @@ public E removeLast() { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { return base.removeIf(filter); @@ -2164,11 +2221,13 @@ public void replaceAll(UnaryOperator operator) { base.replaceAll(operator); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void sort(Comparator c) { base.sort(Collections.reverseOrder(c)); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E set(int index, E element) { synchronized (lock) { diff --git a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java index 236a7855275bd..88e80923238e9 100644 --- a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java +++ b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java @@ -47,9 +47,9 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.AbstractSet; import java.util.Collection; @@ -247,6 +247,7 @@ public boolean contains(@GuardSatisfied @Nullable @UnknownSignedness Object o) { * Removes all of the elements from this set. * The set will be empty after this call returns. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { al.clear(); @@ -263,6 +264,7 @@ public void clear() { * @param o object to be removed from this set, if present * @return {@code true} if this set contained the specified element */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @Nullable @UnknownSignedness Object o) { return al.remove(o); @@ -281,6 +283,7 @@ public boolean remove(@GuardSatisfied @Nullable @UnknownSignedness Object o) { * element */ @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { return al.addIfAbsent(e); @@ -352,6 +355,7 @@ private static int compareSets(Object[] snapshot, Set set) { * @throws NullPointerException if the specified collection is null * @see #add(Object) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { return al.addAllAbsent(c) > 0; @@ -374,6 +378,7 @@ public boolean addAll(Collection c) { * or if the specified collection is null * @see #remove(Object) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { return al.removeAll(c); @@ -398,6 +403,7 @@ public boolean removeAll(Collection c) { return al.retainAll(c); @@ -445,6 +451,7 @@ public boolean equals(@Nullable Object o) { /** * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { return al.removeIf(filter); diff --git a/src/java.base/share/classes/java/util/concurrent/DelayQueue.java b/src/java.base/share/classes/java/util/concurrent/DelayQueue.java index 13c3544958ffd..54e1cd0118f5a 100644 --- a/src/java.base/share/classes/java/util/concurrent/DelayQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/DelayQueue.java @@ -43,11 +43,11 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; 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.DoesNotUnrefineReceiver; import static java.util.concurrent.TimeUnit.NANOSECONDS; import org.checkerframework.checker.nonempty.qual.PolyNonEmpty; @@ -171,6 +171,7 @@ public DelayQueue(Collection c) { * @throws NullPointerException if the specified element is null */ @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { return offer(e); @@ -183,6 +184,7 @@ public boolean add(E e) { * @return {@code true} * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { final ReentrantLock lock = this.lock; @@ -206,6 +208,7 @@ public boolean offer(E e) { * @param e the element to add * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void put(E e) { offer(e); @@ -221,6 +224,7 @@ public void put(E e) { * @return {@code true} * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e, long timeout, TimeUnit unit) { return offer(e); @@ -234,6 +238,7 @@ public boolean offer(E e, long timeout, TimeUnit unit) { * @return the expired head of this queue, or {@code null} if this * queue has no elements with an expired delay */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink DelayQueue this) { final ReentrantLock lock = this.lock; @@ -256,6 +261,7 @@ public boolean offer(E e, long timeout, TimeUnit unit) { * @return the expired head of this queue * @throws InterruptedException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E take(@GuardSatisfied @CanShrink DelayQueue this) throws InterruptedException { final ReentrantLock lock = this.lock; @@ -302,6 +308,7 @@ public E take(@GuardSatisfied @CanShrink DelayQueue this) throws InterruptedE * an expired delay becomes available * @throws InterruptedException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink DelayQueue this, long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); @@ -353,6 +360,7 @@ public E take(@GuardSatisfied @CanShrink DelayQueue this) throws InterruptedE * @throws NoSuchElementException if this queue has no elements with an * expired delay */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove() { return super.remove(); @@ -395,6 +403,7 @@ public int size() { * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink DelayQueue this, Collection c) { return drainTo(c, Integer.MAX_VALUE); @@ -406,6 +415,7 @@ public int drainTo(@GuardSatisfied @CanShrink DelayQueue this, Collection this, Collection c, int maxElements) { Objects.requireNonNull(c); @@ -437,6 +447,7 @@ public int drainTo(@GuardSatisfied @CanShrink DelayQueue this, Collection this) { final ReentrantLock lock = this.lock; @@ -532,6 +543,7 @@ public int remainingCapacity() { * Removes a single instance of the specified element from this * queue, if it is present, whether or not it has expired. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink DelayQueue this, @UnknownSignedness Object o) { final ReentrantLock lock = this.lock; @@ -604,6 +616,7 @@ public E next(@NonEmpty Itr this) { return (E)array[lastRet = cursor++]; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastRet < 0) diff --git a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java index 0c44380329959..3e82a3e0d9a9a 100644 --- a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java +++ b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java @@ -47,10 +47,10 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.AbstractQueue; import java.util.Collection; @@ -332,6 +332,7 @@ void unlink(@CanShrink LinkedBlockingDeque this, Node x) { * @throws IllegalStateException if this deque is full * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { if (!offerFirst(e)) @@ -342,6 +343,7 @@ public void addFirst(E e) { * @throws IllegalStateException if this deque is full * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { if (!offerLast(e)) @@ -351,6 +353,7 @@ public void addLast(E e) { /** * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offerFirst(E e) { if (e == null) throw new NullPointerException(); @@ -367,6 +370,7 @@ public boolean offerFirst(E e) { /** * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offerLast(E e) { if (e == null) throw new NullPointerException(); @@ -384,6 +388,7 @@ public boolean offerLast(E e) { * @throws NullPointerException {@inheritDoc} * @throws InterruptedException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putFirst(E e) throws InterruptedException { if (e == null) throw new NullPointerException(); @@ -402,6 +407,7 @@ public void putFirst(E e) throws InterruptedException { * @throws NullPointerException {@inheritDoc} * @throws InterruptedException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putLast(E e) throws InterruptedException { if (e == null) throw new NullPointerException(); @@ -420,6 +426,7 @@ public void putLast(E e) throws InterruptedException { * @throws NullPointerException {@inheritDoc} * @throws InterruptedException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException { @@ -444,6 +451,7 @@ public boolean offerFirst(E e, long timeout, TimeUnit unit) * @throws NullPointerException {@inheritDoc} * @throws InterruptedException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offerLast(E e, long timeout, TimeUnit unit) throws InterruptedException { @@ -467,6 +475,7 @@ public boolean offerLast(E e, long timeout, TimeUnit unit) /** * @throws NoSuchElementException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeFirst(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque this) { E x = pollFirst(); @@ -477,6 +486,7 @@ public E removeFirst(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque /** * @throws NoSuchElementException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeLast(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque this) { E x = pollLast(); @@ -484,6 +494,7 @@ public E removeLast(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque return x; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollFirst(@GuardSatisfied @CanShrink LinkedBlockingDeque this) { final ReentrantLock lock = this.lock; @@ -495,6 +506,7 @@ public E removeLast(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollLast(@GuardSatisfied @CanShrink LinkedBlockingDeque this) { final ReentrantLock lock = this.lock; @@ -506,6 +518,7 @@ public E removeLast(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E takeFirst(@GuardSatisfied @CanShrink LinkedBlockingDeque this) throws InterruptedException { final ReentrantLock lock = this.lock; @@ -520,6 +533,7 @@ public E takeFirst(@GuardSatisfied @CanShrink LinkedBlockingDeque this) throw } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E takeLast(@GuardSatisfied @CanShrink LinkedBlockingDeque this) throws InterruptedException { final ReentrantLock lock = this.lock; @@ -534,6 +548,7 @@ public E takeLast(@GuardSatisfied @CanShrink LinkedBlockingDeque this) throws } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollFirst(@GuardSatisfied @CanShrink LinkedBlockingDeque this, long timeout, TimeUnit unit) throws InterruptedException { @@ -553,6 +568,7 @@ public E takeLast(@GuardSatisfied @CanShrink LinkedBlockingDeque this) throws } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollLast(@GuardSatisfied @CanShrink LinkedBlockingDeque this, long timeout, TimeUnit unit) throws InterruptedException { @@ -612,6 +628,7 @@ public E getLast(@NonEmpty LinkedBlockingDeque this) { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeFirstOccurrence(@CanShrink LinkedBlockingDeque this, Object o) { if (o == null) return false; @@ -630,6 +647,7 @@ public boolean removeFirstOccurrence(@CanShrink LinkedBlockingDeque this, Obj } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeLastOccurrence(@CanShrink LinkedBlockingDeque this, Object o) { if (o == null) return false; @@ -661,6 +679,7 @@ public boolean removeLastOccurrence(@CanShrink LinkedBlockingDeque this, Obje * @throws NullPointerException if the specified element is null */ @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { addLast(e); @@ -670,6 +689,7 @@ public boolean add(E e) { /** * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { return offerLast(e); @@ -679,6 +699,7 @@ public boolean offer(E e) { * @throws NullPointerException {@inheritDoc} * @throws InterruptedException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void put(E e) throws InterruptedException { putLast(e); @@ -688,6 +709,7 @@ public void put(E e) throws InterruptedException { * @throws NullPointerException {@inheritDoc} * @throws InterruptedException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException { @@ -704,21 +726,25 @@ public boolean offer(E e, long timeout, TimeUnit unit) * @return the head of the queue represented by this deque * @throws NoSuchElementException if this deque is empty */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque this) { return removeFirst(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink LinkedBlockingDeque this) { return pollFirst(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E take(@GuardSatisfied @CanShrink LinkedBlockingDeque this) throws InterruptedException { return takeFirst(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink LinkedBlockingDeque this, long timeout, TimeUnit unit) throws InterruptedException { return pollFirst(timeout, unit); @@ -770,6 +796,7 @@ public int remainingCapacity() { * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink LinkedBlockingDeque this, Collection c) { return drainTo(c, Integer.MAX_VALUE); @@ -781,6 +808,7 @@ public int drainTo(@GuardSatisfied @CanShrink LinkedBlockingDeque this, Colle * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink LinkedBlockingDeque this, Collection c, int maxElements) { Objects.requireNonNull(c); @@ -808,6 +836,7 @@ public int drainTo(@GuardSatisfied @CanShrink LinkedBlockingDeque this, Colle * @throws IllegalStateException if this deque is full * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void push(E e) { addFirst(e); @@ -816,6 +845,7 @@ public void push(E e) { /** * @throws NoSuchElementException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E pop(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque this) { return removeFirst(); @@ -837,6 +867,7 @@ public E pop(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque this) { * @param o element to be removed from this deque, if present * @return {@code true} if this deque changed as a result of the call */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink LinkedBlockingDeque this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { return removeFirstOccurrence(o); @@ -896,6 +927,7 @@ public boolean contains(@GuardSatisfied @Nullable @UnknownSignedness Object o) { * @throws IllegalStateException if this deque is full * @see #add(Object) */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { if (c == this) @@ -1034,6 +1066,7 @@ public String toString() { * Atomically removes all of the elements from this deque. * The deque will be empty after this call returns. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink LinkedBlockingDeque this) { final ReentrantLock lock = this.lock; @@ -1205,6 +1238,7 @@ public void forEachRemaining(Consumer action) { } while (n > 0 && p != null); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { Node n = lastRet; @@ -1393,6 +1427,7 @@ void forEachFrom(Consumer action, Node p) { /** * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink LinkedBlockingDeque this, Predicate filter) { Objects.requireNonNull(filter); @@ -1402,6 +1437,7 @@ public boolean removeIf(@CanShrink LinkedBlockingDeque this, Predicate this, Collection c) { Objects.requireNonNull(c); @@ -1411,6 +1447,7 @@ public boolean removeAll(@CanShrink LinkedBlockingDeque this, Collection this, Collection c) { Objects.requireNonNull(c); diff --git a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java index ad5ed1b667712..871e06a13f53d 100644 --- a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java @@ -46,10 +46,10 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.AbstractQueue; import java.util.Collection; @@ -341,6 +341,7 @@ public int remainingCapacity() { * @throws InterruptedException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void put(E e) throws InterruptedException { if (e == null) throw new NullPointerException(); @@ -381,6 +382,7 @@ public void put(E e) throws InterruptedException { * @throws InterruptedException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException { @@ -420,6 +422,7 @@ public boolean offer(E e, long timeout, TimeUnit unit) * * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { if (e == null) throw new NullPointerException(); @@ -445,6 +448,7 @@ public boolean offer(E e) { return true; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E take(@GuardSatisfied @CanShrink LinkedBlockingQueue this) throws InterruptedException { final E x; @@ -468,6 +472,7 @@ public E take(@GuardSatisfied @CanShrink LinkedBlockingQueue this) throws Int return x; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink LinkedBlockingQueue this, long timeout, TimeUnit unit) throws InterruptedException { final E x; @@ -494,6 +499,7 @@ public E take(@GuardSatisfied @CanShrink LinkedBlockingQueue this) throws Int return x; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink LinkedBlockingQueue this) { final AtomicInteger count = this.count; @@ -559,6 +565,7 @@ void unlink(Node p, Node pred) { * @param o element to be removed from this queue, if present * @return {@code true} if this queue changed as a result of the call */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink LinkedBlockingQueue this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { if (o == null) return false; @@ -691,6 +698,7 @@ public String toString() { * Atomically removes all of the elements from this queue. * The queue will be empty after this call returns. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink LinkedBlockingQueue this) { fullyLock(); @@ -714,6 +722,7 @@ public void clear(@GuardSatisfied @CanShrink LinkedBlockingQueue this) { * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink LinkedBlockingQueue this, Collection c) { return drainTo(c, Integer.MAX_VALUE); @@ -725,6 +734,7 @@ public int drainTo(@GuardSatisfied @CanShrink LinkedBlockingQueue this, Colle * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink LinkedBlockingQueue this, Collection c, int maxElements) { Objects.requireNonNull(c); @@ -879,6 +889,7 @@ public void forEachRemaining(Consumer action) { } while (n > 0 && p != null); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { Node p = lastRet; @@ -1053,6 +1064,7 @@ void forEachFrom(Consumer action, Node p) { /** * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink LinkedBlockingQueue this, Predicate filter) { Objects.requireNonNull(filter); @@ -1062,6 +1074,7 @@ public boolean removeIf(@CanShrink LinkedBlockingQueue this, Predicate this, Collection c) { Objects.requireNonNull(c); @@ -1071,6 +1084,7 @@ public boolean removeAll(@CanShrink LinkedBlockingQueue this, Collection this, Collection c) { Objects.requireNonNull(c); diff --git a/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java b/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java index 0b02f6cee7b31..c7448a8f93fcb 100644 --- a/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java @@ -47,9 +47,9 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; @@ -943,6 +943,7 @@ public void forEachRemaining(Consumer action) { lastRet = q; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void remove() { final Node lastRet = this.lastRet; @@ -1205,6 +1206,7 @@ public LinkedTransferQueue(Collection c) { * * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void put(E e) { xfer(e, true, ASYNC, 0L); @@ -1219,6 +1221,7 @@ public void put(E e) { * {@link BlockingQueue#offer(Object,long,TimeUnit) BlockingQueue.offer}) * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e, long timeout, TimeUnit unit) { xfer(e, true, ASYNC, 0L); @@ -1232,6 +1235,7 @@ public boolean offer(E e, long timeout, TimeUnit unit) { * @return {@code true} (as specified by {@link Queue#offer}) * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { xfer(e, true, ASYNC, 0L); @@ -1247,6 +1251,7 @@ public boolean offer(E e) { * @throws NullPointerException if the specified element is null */ @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { xfer(e, true, ASYNC, 0L); @@ -1263,6 +1268,7 @@ public boolean add(E e) { * * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean tryTransfer(@GuardSatisfied @CanShrink LinkedTransferQueue this, E e) { return xfer(e, true, NOW, 0L) == null; @@ -1279,6 +1285,7 @@ public boolean tryTransfer(@GuardSatisfied @CanShrink LinkedTransferQueue thi * * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void transfer(@GuardSatisfied @CanShrink LinkedTransferQueue this, E e) throws InterruptedException { if (xfer(e, true, SYNC, 0L) != null) { @@ -1301,6 +1308,7 @@ public void transfer(@GuardSatisfied @CanShrink LinkedTransferQueue this, E e * * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean tryTransfer(@GuardSatisfied @CanShrink LinkedTransferQueue this, E e, long timeout, TimeUnit unit) throws InterruptedException { @@ -1311,6 +1319,7 @@ public boolean tryTransfer(@GuardSatisfied @CanShrink LinkedTransferQueue thi throw new InterruptedException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E take(@GuardSatisfied @CanShrink LinkedTransferQueue this) throws InterruptedException { E e = xfer(null, false, SYNC, 0L); @@ -1320,6 +1329,7 @@ public E take(@GuardSatisfied @CanShrink LinkedTransferQueue this) throws Int throw new InterruptedException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E poll(@GuardSatisfied @CanShrink LinkedTransferQueue this, long timeout, TimeUnit unit) throws InterruptedException { E e = xfer(null, false, TIMED, unit.toNanos(timeout)); @@ -1328,6 +1338,7 @@ public E poll(@GuardSatisfied @CanShrink LinkedTransferQueue this, long timeo throw new InterruptedException(); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E poll(@GuardSatisfied @CanShrink LinkedTransferQueue this) { return xfer(null, false, NOW, 0L); @@ -1337,6 +1348,7 @@ public E poll(@GuardSatisfied @CanShrink LinkedTransferQueue this) { * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink LinkedTransferQueue this, Collection c) { Objects.requireNonNull(c); @@ -1352,6 +1364,7 @@ public int drainTo(@GuardSatisfied @CanShrink LinkedTransferQueue this, Colle * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink LinkedTransferQueue this, Collection c, int maxElements) { Objects.requireNonNull(c); @@ -1456,6 +1469,7 @@ public int getWaitingConsumerCount() { * @param o element to be removed from this queue, if present * @return {@code true} if this queue changed as a result of the call */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink LinkedTransferQueue this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { if (o == null) return false; @@ -1577,6 +1591,7 @@ private void readObject(java.io.ObjectInputStream s) /** * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink LinkedTransferQueue this, Predicate filter) { Objects.requireNonNull(filter); @@ -1586,6 +1601,7 @@ public boolean removeIf(@CanShrink LinkedTransferQueue this, Predicate this, Collection c) { Objects.requireNonNull(c); @@ -1595,12 +1611,14 @@ public boolean removeAll(@CanShrink LinkedTransferQueue this, Collection this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> !c.contains(e)); } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink LinkedTransferQueue this) { bulkRemove(e -> true); diff --git a/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java index 6e23f869ab209..ca6d893f3fa50 100644 --- a/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java @@ -47,10 +47,10 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; @@ -464,6 +464,7 @@ private void heapify() { * @throws NullPointerException if the specified element is null */ @EnsuresNonEmpty("this") + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { return offer(e); @@ -480,6 +481,7 @@ public boolean add(E e) { * priority queue's ordering * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { if (e == null) @@ -514,6 +516,7 @@ public boolean offer(E e) { * priority queue's ordering * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void put(E e) { offer(e); // never need to block @@ -534,11 +537,13 @@ public void put(E e) { * priority queue's ordering * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e, long timeout, TimeUnit unit) { return offer(e); // never need to block } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink PriorityBlockingQueue this) { final ReentrantLock lock = this.lock; @@ -550,6 +555,7 @@ public boolean offer(E e, long timeout, TimeUnit unit) { } } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E take(@GuardSatisfied @CanShrink PriorityBlockingQueue this) throws InterruptedException { final ReentrantLock lock = this.lock; @@ -564,6 +570,7 @@ public E take(@GuardSatisfied @CanShrink PriorityBlockingQueue this) throws I return result; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink PriorityBlockingQueue this, long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); @@ -670,6 +677,7 @@ private void removeAt(int i) { * @param o element to be removed from this queue, if present * @return {@code true} if this queue changed as a result of the call */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink PriorityBlockingQueue this, @Nullable @UnknownSignedness Object o) { final ReentrantLock lock = this.lock; @@ -736,6 +744,7 @@ public String toString() { * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink PriorityBlockingQueue this, Collection c) { return drainTo(c, Integer.MAX_VALUE); @@ -747,6 +756,7 @@ public int drainTo(@GuardSatisfied @CanShrink PriorityBlockingQueue this, Col * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink PriorityBlockingQueue this, Collection c, int maxElements) { Objects.requireNonNull(c); @@ -772,6 +782,7 @@ public int drainTo(@GuardSatisfied @CanShrink PriorityBlockingQueue this, Col * Atomically removes all of the elements from this queue. * The queue will be empty after this call returns. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink PriorityBlockingQueue this) { final ReentrantLock lock = this.lock; @@ -900,6 +911,7 @@ public E next(@NonEmpty Itr this) { return (E)array[lastRet = cursor++]; } + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastRet < 0) @@ -1046,6 +1058,7 @@ public Spliterator spliterator() { /** * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink PriorityBlockingQueue this, Predicate filter) { Objects.requireNonNull(filter); @@ -1055,6 +1068,7 @@ public boolean removeIf(@CanShrink PriorityBlockingQueue this, Predicate this, Collection c) { Objects.requireNonNull(c); @@ -1064,6 +1078,7 @@ public boolean removeAll(@CanShrink PriorityBlockingQueue this, Collection this, Collection c) { Objects.requireNonNull(c); diff --git a/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java b/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java index fc43091c127dd..40fb1f960b5f8 100644 --- a/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java @@ -46,10 +46,10 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; @@ -850,6 +850,7 @@ public SynchronousQueue(boolean fair) { * @throws InterruptedException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void put(E e) throws InterruptedException { if (e == null) throw new NullPointerException(); @@ -868,6 +869,7 @@ public void put(E e) throws InterruptedException { * @throws InterruptedException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException { @@ -888,6 +890,7 @@ public boolean offer(E e, long timeout, TimeUnit unit) * {@code false} * @throws NullPointerException if the specified element is null */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { if (e == null) throw new NullPointerException(); @@ -901,6 +904,7 @@ public boolean offer(E e) { * @return the head of this queue * @throws InterruptedException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E take(@GuardSatisfied @CanShrink SynchronousQueue this) throws InterruptedException { E e = transferer.transfer(null, false, 0); @@ -919,6 +923,7 @@ public E take(@GuardSatisfied @CanShrink SynchronousQueue this) throws Interr * specified waiting time elapses before an element is present * @throws InterruptedException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E poll(@GuardSatisfied @CanShrink SynchronousQueue this, long timeout, TimeUnit unit) throws InterruptedException { E e = transferer.transfer(null, true, unit.toNanos(timeout)); @@ -934,6 +939,7 @@ public E poll(@GuardSatisfied @CanShrink SynchronousQueue this, long timeout, * @return the head of this queue, or {@code null} if no * element is available */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E poll(@GuardSatisfied @CanShrink SynchronousQueue this) { return transferer.transfer(null, true, 0); @@ -976,6 +982,7 @@ public int remainingCapacity() { * Does nothing. * A {@code SynchronousQueue} has no internal capacity. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink SynchronousQueue this) { } @@ -1000,6 +1007,7 @@ public boolean contains(@GuardSatisfied @Nullable @UnknownSignedness Object o) { * @param o the element to remove * @return {@code false} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink SynchronousQueue this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { return false; @@ -1024,6 +1032,7 @@ public boolean containsAll(Collection c) { * @param c the collection * @return {@code false} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(@CanShrink SynchronousQueue this, Collection c) { return false; @@ -1036,6 +1045,7 @@ public boolean removeAll(@CanShrink SynchronousQueue this, Collection this, Collection c) { return false; @@ -1114,6 +1124,7 @@ public String toString() { * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink SynchronousQueue this, Collection c) { Objects.requireNonNull(c); @@ -1131,6 +1142,7 @@ public int drainTo(@GuardSatisfied @CanShrink SynchronousQueue this, Collecti * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink SynchronousQueue this, Collection c, int maxElements) { Objects.requireNonNull(c); diff --git a/src/java.base/share/classes/java/util/jar/Attributes.java b/src/java.base/share/classes/java/util/jar/Attributes.java index 4630b1e44b571..4bd951b03173b 100644 --- a/src/java.base/share/classes/java/util/jar/Attributes.java +++ b/src/java.base/share/classes/java/util/jar/Attributes.java @@ -175,6 +175,7 @@ public String getValue(Name name) { * @throws ClassCastException if the name is not a Attributes.Name * or the value is not a String */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Object put(Object name, Object value) { return map.put((Attributes.Name)name, (String)value); @@ -207,6 +208,7 @@ public String putValue(String name, String value) { * @param name attribute name * @return the previous value of the attribute, or null if none */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Object remove(@GuardSatisfied @Nullable @UnknownSignedness Object name) { return map.remove(name); @@ -243,6 +245,7 @@ public boolean containsKey(@GuardSatisfied @Nullable @UnknownSignedness Object n * @param attr the Attributes to be stored in this map * @throws ClassCastException if attr is not an Attributes */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putAll(Map attr) { // ## javac bug? @@ -255,6 +258,7 @@ public void putAll(Map attr) { /** * Removes all attributes from this Map. */ + @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { map.clear(); From 2f3d5ae116eb03f0cf0e5fc3a6b7815ab3e5f4b5 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 19 May 2026 11:20:50 -0700 Subject: [PATCH 07/15] Comment out `@SideEffectsOnly` annotations --- .../share/classes/java/io/BufferedReader.java | 4 +- .../java/lang/AbstractStringBuilder.java | 2 +- .../share/classes/java/lang/CharSequence.java | 6 +- .../classes/java/lang/StackStreamFactory.java | 4 +- .../share/classes/java/lang/String.java | 2 +- .../share/classes/java/lang/StringBuffer.java | 2 +- .../classes/java/lang/StringBuilder.java | 66 ++--- .../share/classes/java/lang/StringLatin1.java | 2 +- .../share/classes/java/lang/StringUTF16.java | 2 +- .../lang/invoke/AbstractConstantGroup.java | 4 +- src/java.base/share/classes/java/net/URL.java | 4 +- .../classes/java/nio/charset/Charset.java | 4 +- .../java/nio/file/FileTreeIterator.java | 4 +- .../share/classes/java/nio/file/Files.java | 4 +- .../share/classes/java/nio/file/Path.java | 4 +- .../classes/java/util/AbstractCollection.java | 12 +- .../share/classes/java/util/AbstractList.java | 44 +-- .../share/classes/java/util/AbstractMap.java | 38 +-- .../classes/java/util/AbstractQueue.java | 8 +- .../java/util/AbstractSequentialList.java | 8 +- .../share/classes/java/util/AbstractSet.java | 2 +- .../share/classes/java/util/ArrayDeque.java | 52 ++-- .../share/classes/java/util/ArrayList.java | 74 ++--- .../share/classes/java/util/Arrays.java | 4 +- .../share/classes/java/util/Collection.java | 14 +- .../share/classes/java/util/Collections.java | 268 +++++++++--------- .../share/classes/java/util/Deque.java | 48 ++-- .../share/classes/java/util/EnumMap.java | 30 +- .../share/classes/java/util/EnumSet.java | 8 +- .../share/classes/java/util/Enumeration.java | 4 +- .../share/classes/java/util/HashMap.java | 40 +-- .../share/classes/java/util/HashSet.java | 12 +- .../share/classes/java/util/Hashtable.java | 38 +-- .../classes/java/util/IdentityHashMap.java | 44 +-- .../java/util/ImmutableCollections.java | 10 +- .../share/classes/java/util/Iterator.java | 6 +- .../share/classes/java/util/JumboEnumSet.java | 24 +- .../classes/java/util/LinkedHashMap.java | 64 ++--- .../classes/java/util/LinkedHashSet.java | 12 +- .../share/classes/java/util/LinkedList.java | 116 ++++---- .../share/classes/java/util/List.java | 32 +-- .../share/classes/java/util/ListIterator.java | 12 +- .../share/classes/java/util/Map.java | 18 +- .../share/classes/java/util/NavigableMap.java | 4 +- .../share/classes/java/util/NavigableSet.java | 14 +- .../classes/java/util/PrimitiveIterator.java | 12 +- .../classes/java/util/PriorityQueue.java | 22 +- .../share/classes/java/util/Properties.java | 32 +-- .../share/classes/java/util/Queue.java | 10 +- .../classes/java/util/RegularEnumSet.java | 24 +- .../share/classes/java/util/Scanner.java | 40 +-- .../java/util/SequencedCollection.java | 10 +- .../share/classes/java/util/SequencedMap.java | 16 +- .../share/classes/java/util/SequencedSet.java | 2 +- .../classes/java/util/ServiceLoader.java | 10 +- .../share/classes/java/util/SortedMap.java | 6 +- .../share/classes/java/util/SortedSet.java | 12 +- .../share/classes/java/util/Spliterators.java | 10 +- .../share/classes/java/util/Stack.java | 4 +- .../share/classes/java/util/TreeMap.java | 86 +++--- .../share/classes/java/util/TreeSet.java | 22 +- .../share/classes/java/util/Vector.java | 50 ++-- .../share/classes/java/util/WeakHashMap.java | 32 +-- .../util/concurrent/ArrayBlockingQueue.java | 34 +-- .../java/util/concurrent/BlockingDeque.java | 48 ++-- .../java/util/concurrent/BlockingQueue.java | 18 +- .../util/concurrent/ConcurrentHashMap.java | 64 ++--- .../concurrent/ConcurrentLinkedDeque.java | 50 ++-- .../concurrent/ConcurrentLinkedQueue.java | 24 +- .../java/util/concurrent/ConcurrentMap.java | 8 +- .../concurrent/ConcurrentSkipListMap.java | 76 ++--- .../concurrent/ConcurrentSkipListSet.java | 12 +- .../util/concurrent/CopyOnWriteArrayList.java | 126 ++++---- .../util/concurrent/CopyOnWriteArraySet.java | 14 +- .../java/util/concurrent/DelayQueue.java | 30 +- .../util/concurrent/LinkedBlockingDeque.java | 78 ++--- .../util/concurrent/LinkedBlockingQueue.java | 32 +-- .../util/concurrent/LinkedTransferQueue.java | 40 +-- .../concurrent/PriorityBlockingQueue.java | 34 +-- .../ScheduledThreadPoolExecutor.java | 4 +- .../util/concurrent/SynchronousQueue.java | 24 +- .../classes/java/util/jar/Attributes.java | 8 +- .../classes/java/util/regex/Matcher.java | 4 +- .../classes/java/util/regex/Pattern.java | 4 +- .../share/classes/java/util/zip/ZipFile.java | 6 +- .../classes/javax/security/auth/Subject.java | 4 +- .../jdk/internal/icu/text/Replaceable.java | 2 +- .../internal/icu/text/ReplaceableString.java | 2 +- .../classes/sun/net/www/HeaderParser.java | 4 +- .../classes/sun/net/www/MessageHeader.java | 4 +- .../sun/security/jca/ProviderList.java | 4 +- .../share/classes/sun/util/PreHashedMap.java | 6 +- .../sun/util/locale/StringTokenIterator.java | 4 +- .../resources/ParallelListResourceBundle.java | 4 +- 94 files changed, 1173 insertions(+), 1173 deletions(-) diff --git a/src/java.base/share/classes/java/io/BufferedReader.java b/src/java.base/share/classes/java/io/BufferedReader.java index 41f6de0853dd0..498c3677a49ce 100644 --- a/src/java.base/share/classes/java/io/BufferedReader.java +++ b/src/java.base/share/classes/java/io/BufferedReader.java @@ -38,7 +38,7 @@ import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf; import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.dataflow.qual.Pure; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -709,7 +709,7 @@ public boolean hasNext() { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public String next(/*@NonEmpty Iterator this*/) { if (nextLine != null || hasNext()) { diff --git a/src/java.base/share/classes/java/lang/AbstractStringBuilder.java b/src/java.base/share/classes/java/lang/AbstractStringBuilder.java index e862852c7dbc4..f021b20eeb9e0 100644 --- a/src/java.base/share/classes/java/lang/AbstractStringBuilder.java +++ b/src/java.base/share/classes/java/lang/AbstractStringBuilder.java @@ -35,7 +35,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import jdk.internal.math.DoubleToDecimal; diff --git a/src/java.base/share/classes/java/lang/CharSequence.java b/src/java.base/share/classes/java/lang/CharSequence.java index 9850955c2037a..3469c83c9bd9e 100644 --- a/src/java.base/share/classes/java/lang/CharSequence.java +++ b/src/java.base/share/classes/java/lang/CharSequence.java @@ -34,7 +34,7 @@ import org.checkerframework.checker.nonempty.qual.NonEmpty; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -175,7 +175,7 @@ public boolean hasNext() { return cur < length(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int nextInt(@NonEmpty CharIterator this) { if (hasNext()) { @@ -253,7 +253,7 @@ public boolean hasNext() { return cur < length(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int nextInt(@NonEmpty CodePointIterator this) { final int length = length(); diff --git a/src/java.base/share/classes/java/lang/StackStreamFactory.java b/src/java.base/share/classes/java/lang/StackStreamFactory.java index 2900a4f31ce73..e2df08c6e17ca 100644 --- a/src/java.base/share/classes/java/lang/StackStreamFactory.java +++ b/src/java.base/share/classes/java/lang/StackStreamFactory.java @@ -26,7 +26,7 @@ import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf; import org.checkerframework.dataflow.qual.Pure; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import jdk.internal.reflect.MethodAccessor; import jdk.internal.reflect.ConstructorAccessor; import java.lang.StackWalker.Option; @@ -375,7 +375,7 @@ private void setContinuation(Continuation cont) { * * @see #tryNextFrame */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") final Class nextFrame() { if (!hasNext()) { return null; diff --git a/src/java.base/share/classes/java/lang/String.java b/src/java.base/share/classes/java/lang/String.java index 11b5de32d51f6..82b0503805f7c 100644 --- a/src/java.base/share/classes/java/lang/String.java +++ b/src/java.base/share/classes/java/lang/String.java @@ -56,7 +56,7 @@ import org.checkerframework.common.value.qual.StringVal; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; diff --git a/src/java.base/share/classes/java/lang/StringBuffer.java b/src/java.base/share/classes/java/lang/StringBuffer.java index eddd4aa36513a..208f096a873f4 100644 --- a/src/java.base/share/classes/java/lang/StringBuffer.java +++ b/src/java.base/share/classes/java/lang/StringBuffer.java @@ -35,7 +35,7 @@ import org.checkerframework.common.aliasing.qual.Unique; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import java.io.IOException; diff --git a/src/java.base/share/classes/java/lang/StringBuilder.java b/src/java.base/share/classes/java/lang/StringBuilder.java index 6c17308dfdbc9..641a2f40026df 100644 --- a/src/java.base/share/classes/java/lang/StringBuilder.java +++ b/src/java.base/share/classes/java/lang/StringBuilder.java @@ -34,7 +34,7 @@ import org.checkerframework.checker.regex.qual.PolyRegex; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import jdk.internal.vm.annotation.IntrinsicCandidate; @@ -183,14 +183,14 @@ public int compareTo(StringBuilder another) { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder append(@GuardSatisfied @Nullable Object obj) { return append(String.valueOf(obj)); } @Override @IntrinsicCandidate - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder append(@Nullable String str) { super.append(str); return this; @@ -215,14 +215,14 @@ public StringBuilder append(@Nullable String str) { * @param sb the {@code StringBuffer} to append. * @return a reference to this object. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder append(@Nullable StringBuffer sb) { super.append(sb); return this; } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder append(@Nullable CharSequence s) { super.append(s); return this; @@ -232,14 +232,14 @@ public StringBuilder append(@Nullable CharSequence s) { * @throws IndexOutOfBoundsException {@inheritDoc} */ @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder append(@Nullable CharSequence s, @IndexOrHigh({"#1"}) int start, @IndexOrHigh({"#1"}) int end) { super.append(s, start, end); return this; } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder append(char[] str) { super.append(str); return this; @@ -249,14 +249,14 @@ public StringBuilder append(char[] str) { * @throws IndexOutOfBoundsException {@inheritDoc} */ @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder append(char[] str, @IndexOrHigh({"#1"}) int offset, @LTLengthOf(value={"#1"}, offset={"#2 - 1"}) @NonNegative int len) { super.append(str, offset, len); return this; } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder append(boolean b) { super.append(b); return this; @@ -264,7 +264,7 @@ public StringBuilder append(boolean b) { @Override @IntrinsicCandidate - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder append(char c) { super.append(c); return this; @@ -272,28 +272,28 @@ public StringBuilder append(char c) { @Override @IntrinsicCandidate - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder append(int i) { super.append(i); return this; } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder append(long lng) { super.append(lng); return this; } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder append(float f) { super.append(f); return this; } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder append(double d) { super.append(d); return this; @@ -303,7 +303,7 @@ public StringBuilder append(double d) { * @since 1.5 */ @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder appendCodePoint(int codePoint) { super.appendCodePoint(codePoint); return this; @@ -313,7 +313,7 @@ public StringBuilder appendCodePoint(int codePoint) { * @throws StringIndexOutOfBoundsException {@inheritDoc} */ @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder delete(@NonNegative int start, @NonNegative int end) { super.delete(start, end); return this; @@ -323,7 +323,7 @@ public StringBuilder delete(@NonNegative int start, @NonNegative int end) { * @throws StringIndexOutOfBoundsException {@inheritDoc} */ @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder deleteCharAt(@NonNegative int index) { super.deleteCharAt(index); return this; @@ -333,7 +333,7 @@ public StringBuilder deleteCharAt(@NonNegative int index) { * @throws StringIndexOutOfBoundsException {@inheritDoc} */ @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder replace(@NonNegative int start, @NonNegative int end, String str) { super.replace(start, end, str); return this; @@ -343,7 +343,7 @@ public StringBuilder replace(@NonNegative int start, @NonNegative int end, Strin * @throws StringIndexOutOfBoundsException {@inheritDoc} */ @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder insert(@NonNegative int index, char[] str, @IndexOrHigh({"#2"}) int offset, @IndexOrHigh({"#2"}) int len) { @@ -355,7 +355,7 @@ public StringBuilder insert(@NonNegative int index, char[] str, @IndexOrHigh({"# * @throws StringIndexOutOfBoundsException {@inheritDoc} */ @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder insert(@NonNegative int offset, @GuardSatisfied @Nullable Object obj) { super.insert(offset, obj); return this; @@ -365,7 +365,7 @@ public StringBuilder insert(@NonNegative int offset, @GuardSatisfied @Nullable O * @throws StringIndexOutOfBoundsException {@inheritDoc} */ @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder insert(@NonNegative int offset, @Nullable String str) { super.insert(offset, str); return this; @@ -375,7 +375,7 @@ public StringBuilder insert(@NonNegative int offset, @Nullable String str) { * @throws StringIndexOutOfBoundsException {@inheritDoc} */ @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder insert(@NonNegative int offset, char[] str) { super.insert(offset, str); return this; @@ -385,7 +385,7 @@ public StringBuilder insert(@NonNegative int offset, char[] str) { * @throws IndexOutOfBoundsException {@inheritDoc} */ @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder insert(@NonNegative int dstOffset, @Nullable CharSequence s) { super.insert(dstOffset, s); return this; @@ -395,7 +395,7 @@ public StringBuilder insert(@NonNegative int dstOffset, @Nullable CharSequence s * @throws IndexOutOfBoundsException {@inheritDoc} */ @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder insert(@NonNegative int dstOffset, @Nullable CharSequence s, @NonNegative int start, @NonNegative int end) { @@ -407,7 +407,7 @@ public StringBuilder insert(@NonNegative int dstOffset, @Nullable CharSequence s * @throws StringIndexOutOfBoundsException {@inheritDoc} */ @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder insert(@NonNegative int offset, boolean b) { super.insert(offset, b); return this; @@ -417,7 +417,7 @@ public StringBuilder insert(@NonNegative int offset, boolean b) { * @throws IndexOutOfBoundsException {@inheritDoc} */ @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder insert(@NonNegative int offset, char c) { super.insert(offset, c); return this; @@ -427,7 +427,7 @@ public StringBuilder insert(@NonNegative int offset, char c) { * @throws StringIndexOutOfBoundsException {@inheritDoc} */ @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder insert(@NonNegative int offset, int i) { super.insert(offset, i); return this; @@ -437,7 +437,7 @@ public StringBuilder insert(@NonNegative int offset, int i) { * @throws StringIndexOutOfBoundsException {@inheritDoc} */ @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder insert(@NonNegative int offset, long l) { super.insert(offset, l); return this; @@ -447,7 +447,7 @@ public StringBuilder insert(@NonNegative int offset, long l) { * @throws StringIndexOutOfBoundsException {@inheritDoc} */ @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder insert(@NonNegative int offset, float f) { super.insert(offset, f); return this; @@ -457,7 +457,7 @@ public StringBuilder insert(@NonNegative int offset, float f) { * @throws StringIndexOutOfBoundsException {@inheritDoc} */ @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder insert(@NonNegative int offset, double d) { super.insert(offset, d); return this; @@ -488,7 +488,7 @@ public StringBuilder insert(@NonNegative int offset, double d) { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public StringBuilder reverse() { super.reverse(); return this; @@ -499,7 +499,7 @@ public StringBuilder reverse() { * * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @Override @SideEffectFree public StringBuilder repeat(int codePoint, int count) { @@ -512,7 +512,7 @@ public StringBuilder repeat(int codePoint, int count) { * * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @Override public StringBuilder repeat(CharSequence cs, int count) { super.repeat(cs, count); diff --git a/src/java.base/share/classes/java/lang/StringLatin1.java b/src/java.base/share/classes/java/lang/StringLatin1.java index b4da360e6aa3c..011159e1a6435 100644 --- a/src/java.base/share/classes/java/lang/StringLatin1.java +++ b/src/java.base/share/classes/java/lang/StringLatin1.java @@ -25,7 +25,7 @@ package java.lang; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import java.util.Arrays; import java.util.Locale; diff --git a/src/java.base/share/classes/java/lang/StringUTF16.java b/src/java.base/share/classes/java/lang/StringUTF16.java index 64916fa731255..5c0a69206a43c 100644 --- a/src/java.base/share/classes/java/lang/StringUTF16.java +++ b/src/java.base/share/classes/java/lang/StringUTF16.java @@ -25,7 +25,7 @@ package java.lang; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import java.util.Arrays; import java.util.Locale; diff --git a/src/java.base/share/classes/java/lang/invoke/AbstractConstantGroup.java b/src/java.base/share/classes/java/lang/invoke/AbstractConstantGroup.java index 674838eca05be..075fe0f562d23 100644 --- a/src/java.base/share/classes/java/lang/invoke/AbstractConstantGroup.java +++ b/src/java.base/share/classes/java/lang/invoke/AbstractConstantGroup.java @@ -28,7 +28,7 @@ import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf; import org.checkerframework.checker.nonempty.qual.NonEmpty; import org.checkerframework.dataflow.qual.Pure; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.*; @@ -101,7 +101,7 @@ public boolean hasNext() { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Object next(@NonEmpty AsIterator this) { int i = bumpIndex(); diff --git a/src/java.base/share/classes/java/net/URL.java b/src/java.base/share/classes/java/net/URL.java index 7519c017ba9aa..9aaf4a1b7df71 100644 --- a/src/java.base/share/classes/java/net/URL.java +++ b/src/java.base/share/classes/java/net/URL.java @@ -33,7 +33,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -1513,7 +1513,7 @@ public boolean hasNext() { return getNext(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public URLStreamHandlerProvider next(/*@NonEmpty Iterator this*/) { if (!getNext()) diff --git a/src/java.base/share/classes/java/nio/charset/Charset.java b/src/java.base/share/classes/java/nio/charset/Charset.java index 3a518470c51b6..346e27c985c86 100644 --- a/src/java.base/share/classes/java/nio/charset/Charset.java +++ b/src/java.base/share/classes/java/nio/charset/Charset.java @@ -28,7 +28,7 @@ import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf; import org.checkerframework.checker.nonempty.qual.NonEmpty; import org.checkerframework.dataflow.qual.Pure; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import jdk.internal.misc.ThreadTracker; @@ -371,7 +371,7 @@ public boolean hasNext() { return getNext(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public CharsetProvider next(/*@NonEmpty Iterator this*/) { if (!getNext()) diff --git a/src/java.base/share/classes/java/nio/file/FileTreeIterator.java b/src/java.base/share/classes/java/nio/file/FileTreeIterator.java index c8675e2d16b1d..fff8cbec47500 100644 --- a/src/java.base/share/classes/java/nio/file/FileTreeIterator.java +++ b/src/java.base/share/classes/java/nio/file/FileTreeIterator.java @@ -28,7 +28,7 @@ import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf; import org.checkerframework.checker.nonempty.qual.NonEmpty; import org.checkerframework.dataflow.qual.Pure; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.io.Closeable; @@ -113,7 +113,7 @@ public boolean hasNext() { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Event next(@NonEmpty FileTreeIterator this) { if (!walker.isOpen()) diff --git a/src/java.base/share/classes/java/nio/file/Files.java b/src/java.base/share/classes/java/nio/file/Files.java index 829edd4b494c6..1a5099e646bd5 100644 --- a/src/java.base/share/classes/java/nio/file/Files.java +++ b/src/java.base/share/classes/java/nio/file/Files.java @@ -34,7 +34,7 @@ import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -3866,7 +3866,7 @@ public boolean hasNext() { throw new UncheckedIOException(e.getCause()); } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Override public Path next(/*@NonEmpty Iterator this*/) { diff --git a/src/java.base/share/classes/java/nio/file/Path.java b/src/java.base/share/classes/java/nio/file/Path.java index 3780a87b696fb..d1ab91c4bec5b 100644 --- a/src/java.base/share/classes/java/nio/file/Path.java +++ b/src/java.base/share/classes/java/nio/file/Path.java @@ -30,7 +30,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -963,7 +963,7 @@ public boolean hasNext() { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Path next(/*@NonEmpty Iterator this*/) { if (i < getNameCount()) { diff --git a/src/java.base/share/classes/java/util/AbstractCollection.java b/src/java.base/share/classes/java/util/AbstractCollection.java index 5e168fd6153bc..d38628827e01a 100644 --- a/src/java.base/share/classes/java/util/AbstractCollection.java +++ b/src/java.base/share/classes/java/util/AbstractCollection.java @@ -276,7 +276,7 @@ private static T[] finishToArray(T[] r, Iterator it) { * @throws IllegalArgumentException {@inheritDoc} * @throws IllegalStateException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(@GuardSatisfied AbstractCollection this, E e) { throw new UnsupportedOperationException(); @@ -299,7 +299,7 @@ public boolean add(@GuardSatisfied AbstractCollection this, E e) { * @throws ClassCastException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @CanShrink AbstractCollection this, @GuardSatisfied @UnknownSignedness Object o) { Iterator it = iterator(); @@ -364,7 +364,7 @@ public boolean containsAll(@GuardSatisfied AbstractCollection this, @GuardSat * * @see #add(Object) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@GuardSatisfied AbstractCollection this, Collection c) { boolean modified = false; @@ -396,7 +396,7 @@ public boolean addAll(@GuardSatisfied AbstractCollection this, Collection this, Collection c) { Objects.requireNonNull(c); @@ -433,7 +433,7 @@ public boolean removeAll(@GuardSatisfied @CanShrink AbstractCollection this, * @see #remove(Object) * @see #contains(Object) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(@GuardSatisfied @CanShrink AbstractCollection this, Collection c) { Objects.requireNonNull(c); @@ -464,7 +464,7 @@ public boolean retainAll(@GuardSatisfied @CanShrink AbstractCollection this, * * @throws UnsupportedOperationException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink AbstractCollection this) { Iterator it = iterator(); diff --git a/src/java.base/share/classes/java/util/AbstractList.java b/src/java.base/share/classes/java/util/AbstractList.java index a3a5164664790..c5e394168c8e1 100644 --- a/src/java.base/share/classes/java/util/AbstractList.java +++ b/src/java.base/share/classes/java/util/AbstractList.java @@ -39,7 +39,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -132,7 +132,7 @@ protected AbstractList() { * prevents it from being added to this list */ @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(@GuardSatisfied AbstractList this, E e) { add(size(), e); @@ -160,7 +160,7 @@ public boolean add(@GuardSatisfied AbstractList this, E e) { * @throws IllegalArgumentException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E set(@GuardSatisfied AbstractList this, @IndexFor({"this"}) int index, E element) { throw new UnsupportedOperationException(); @@ -179,7 +179,7 @@ public E set(@GuardSatisfied AbstractList this, @IndexFor({"this"}) int index * @throws IllegalArgumentException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(@GuardSatisfied AbstractList this, @IndexOrHigh({"this"}) int index, E element) { throw new UnsupportedOperationException(); @@ -195,7 +195,7 @@ public void add(@GuardSatisfied AbstractList this, @IndexOrHigh({"this"}) int * @throws UnsupportedOperationException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @CanShrink AbstractList this, @IndexFor({"this"}) int index) { throw new UnsupportedOperationException(); @@ -275,7 +275,7 @@ public E remove(@GuardSatisfied @CanShrink AbstractList this, @IndexFor({"thi * @throws UnsupportedOperationException if the {@code clear} operation * is not supported by this list */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink AbstractList this) { removeRange(0, size()); @@ -301,7 +301,7 @@ public void clear(@GuardSatisfied @CanShrink AbstractList this) { * @throws IllegalArgumentException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@GuardSatisfied AbstractList this, @IndexOrHigh({"this"}) int index, Collection c) { rangeCheckForAdd(index); @@ -407,7 +407,7 @@ public boolean hasNext() { return cursor != size(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty Itr this) { checkForComodification(); @@ -423,7 +423,7 @@ public E next(@NonEmpty Itr this) { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastRet < 0) @@ -477,7 +477,7 @@ public int previousIndex() { return cursor-1; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void set(E e) { if (lastRet < 0) @@ -492,7 +492,7 @@ public void set(E e) { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(E e) { checkForComodification(); @@ -645,7 +645,7 @@ public int hashCode(@GuardSatisfied AbstractList this) { * @param fromIndex index of first element to be removed * @param toIndex index after last element to be removed */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") protected void removeRange(@GuardSatisfied @CanShrink AbstractList this, @IndexOrHigh({"this"}) int fromIndex, @IndexOrHigh({"this"}) int toIndex) { ListIterator it = listIterator(fromIndex); @@ -830,7 +830,7 @@ protected SubList(SubList parent, int fromIndex, int toIndex) { this.modCount = root.modCount; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E set(int index, E element) { Objects.checkIndex(index, size); @@ -850,7 +850,7 @@ public int size() { return size; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(int index, E element) { rangeCheckForAdd(index); @@ -859,7 +859,7 @@ public void add(int index, E element) { updateSizeAndModCount(1); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(int index) { Objects.checkIndex(index, size); @@ -875,13 +875,13 @@ protected void removeRange(int fromIndex, int toIndex) { updateSizeAndModCount(fromIndex - toIndex); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { return addAll(size, c); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(int index, Collection c) { rangeCheckForAdd(index); @@ -912,7 +912,7 @@ public boolean hasNext() { return nextIndex() < size; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(/*@NonEmpty ListIterator this*/) { if (hasNext()) @@ -926,7 +926,7 @@ public boolean hasPrevious() { return previousIndex() >= 0; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public E previous() { if (hasPrevious()) return i.previous(); @@ -944,20 +944,20 @@ public int previousIndex() { return i.previousIndex() - offset; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { i.remove(); updateSizeAndModCount(-1); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void set(E e) { i.set(e); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(E e) { i.add(e); diff --git a/src/java.base/share/classes/java/util/AbstractMap.java b/src/java.base/share/classes/java/util/AbstractMap.java index 96141b8ee8dfd..70a70fe2dcae0 100644 --- a/src/java.base/share/classes/java/util/AbstractMap.java +++ b/src/java.base/share/classes/java/util/AbstractMap.java @@ -37,7 +37,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -238,7 +238,7 @@ public boolean containsKey(@GuardSatisfied AbstractMap this, @GuardSatisfi */ @ReleasesNoLocks @EnsuresKeyFor(value={"#1"}, map={"this"}) - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V put(@GuardSatisfied AbstractMap this, K key, V value) { throw new UnsupportedOperationException(); @@ -266,7 +266,7 @@ public boolean containsKey(@GuardSatisfied AbstractMap this, @GuardSatisfi * @throws ClassCastException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V remove(@GuardSatisfied AbstractMap this, @GuardSatisfied @UnknownSignedness Object key) { Iterator> i = entrySet().iterator(); @@ -313,7 +313,7 @@ public boolean containsKey(@GuardSatisfied AbstractMap this, @GuardSatisfi * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putAll(@GuardSatisfied AbstractMap this, Map m) { for (Map.Entry e : m.entrySet()) @@ -332,7 +332,7 @@ public void putAll(@GuardSatisfied AbstractMap this, Map this) { entrySet().clear(); @@ -399,13 +399,13 @@ public boolean hasNext() { return i.hasNext(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public K next(/*@NonEmpty Iterator this*/) { return i.next().getKey(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { i.remove(); @@ -424,7 +424,7 @@ public boolean isEmpty() { return AbstractMap.this.isEmpty(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { AbstractMap.this.clear(); @@ -471,13 +471,13 @@ public boolean hasNext() { return i.hasNext(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V next(/*@NonEmpty Iterator this*/) { return i.next().getValue(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { i.remove(); @@ -496,7 +496,7 @@ public boolean isEmpty() { return AbstractMap.this.isEmpty(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { AbstractMap.this.clear(); @@ -737,7 +737,7 @@ public V getValue(AbstractMap.@GuardSatisfied SimpleEntry this) { * @param value new value to be stored in this entry * @return the old value corresponding to the entry */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V setValue(AbstractMap.@GuardSatisfied SimpleEntry this, V value) { V oldValue = this.value; @@ -982,13 +982,13 @@ public String toString(AbstractMap.@GuardSatisfied SimpleImmutableEntry th UnsupportedOperationException uoe() { return new UnsupportedOperationException(); } abstract Collection view(); - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E t) { throw uoe(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { throw uoe(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { view().clear(); } public boolean contains(Object o) { return view().contains(o); } @@ -997,16 +997,16 @@ public String toString(AbstractMap.@GuardSatisfied SimpleImmutableEntry th public boolean isEmpty() { return view().isEmpty(); } public Iterator iterator() { return view().iterator(); } public Stream parallelStream() { return view().parallelStream(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(Object o) { return view().remove(o); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { return view().removeAll(c); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { return view().removeIf(filter); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { return view().retainAll(c); } public int size() { return view().size(); } diff --git a/src/java.base/share/classes/java/util/AbstractQueue.java b/src/java.base/share/classes/java/util/AbstractQueue.java index 7f487df7ff363..dc006f3509487 100644 --- a/src/java.base/share/classes/java/util/AbstractQueue.java +++ b/src/java.base/share/classes/java/util/AbstractQueue.java @@ -100,7 +100,7 @@ protected AbstractQueue() { * prevents it from being added to this queue */ @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(@GuardSatisfied AbstractQueue this, E e) { if (offer(e)) @@ -120,7 +120,7 @@ public boolean add(@GuardSatisfied AbstractQueue this, E e) { * @return the head of this queue * @throws NoSuchElementException if this queue is empty */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @NonEmpty @CanShrink AbstractQueue this) { E x = poll(); @@ -156,7 +156,7 @@ public E element(@GuardSatisfied @NonEmpty AbstractQueue this) { *

This implementation repeatedly invokes {@link #poll poll} until it * returns {@code null}. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink AbstractQueue this) { while (poll() != null) @@ -192,7 +192,7 @@ public void clear(@GuardSatisfied @CanShrink AbstractQueue this) { * this time due to insertion restrictions * @see #add(Object) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@GuardSatisfied AbstractQueue this, Collection c) { if (c == null) diff --git a/src/java.base/share/classes/java/util/AbstractSequentialList.java b/src/java.base/share/classes/java/util/AbstractSequentialList.java index 865cca704a925..a8932d5d6673d 100644 --- a/src/java.base/share/classes/java/util/AbstractSequentialList.java +++ b/src/java.base/share/classes/java/util/AbstractSequentialList.java @@ -125,7 +125,7 @@ public E get(@GuardSatisfied AbstractSequentialList this, int index) { * @throws IllegalArgumentException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E set(@GuardSatisfied AbstractSequentialList this, int index, E element) { try { @@ -158,7 +158,7 @@ public E set(@GuardSatisfied AbstractSequentialList this, int index, E elemen * @throws IllegalArgumentException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(@GuardSatisfied AbstractSequentialList this, int index, E element) { try { @@ -185,7 +185,7 @@ public void add(@GuardSatisfied AbstractSequentialList this, int index, E ele * @throws UnsupportedOperationException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @CanShrink AbstractSequentialList this, int index) { try { @@ -230,7 +230,7 @@ public E remove(@GuardSatisfied @CanShrink AbstractSequentialList this, int i * @throws IllegalArgumentException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@GuardSatisfied AbstractSequentialList this, int index, Collection c) { try { diff --git a/src/java.base/share/classes/java/util/AbstractSet.java b/src/java.base/share/classes/java/util/AbstractSet.java index ce10698e69de6..19e90776f4b1a 100644 --- a/src/java.base/share/classes/java/util/AbstractSet.java +++ b/src/java.base/share/classes/java/util/AbstractSet.java @@ -175,7 +175,7 @@ public int hashCode(@GuardSatisfied AbstractSet this) { * @see #remove(Object) * @see #contains(Object) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(@GuardSatisfied AbstractSet this, Collection c) { Objects.requireNonNull(c); diff --git a/src/java.base/share/classes/java/util/ArrayDeque.java b/src/java.base/share/classes/java/util/ArrayDeque.java index e611f0ba13360..b005423e281db 100644 --- a/src/java.base/share/classes/java/util/ArrayDeque.java +++ b/src/java.base/share/classes/java/util/ArrayDeque.java @@ -50,7 +50,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -302,7 +302,7 @@ static final E nonNullElementAt(@PolyNull @PolySigned Object[] es, int i) { * @param e the element to add * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addFirst(@GuardSatisfied ArrayDeque this, E e) { if (e == null) @@ -321,7 +321,7 @@ public void addFirst(@GuardSatisfied ArrayDeque this, E e) { * @param e the element to add * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addLast(@GuardSatisfied ArrayDeque this, E e) { if (e == null) @@ -342,7 +342,7 @@ public void addLast(@GuardSatisfied ArrayDeque this, E e) { * @throws NullPointerException if the specified collection or any * of its elements are null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { final int s, needed; @@ -363,7 +363,7 @@ private void copyElements(Collection c) { * @return {@code true} (as specified by {@link Deque#offerFirst}) * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offerFirst(E e) { addFirst(e); @@ -377,7 +377,7 @@ public boolean offerFirst(E e) { * @return {@code true} (as specified by {@link Deque#offerLast}) * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offerLast(E e) { addLast(e); @@ -387,7 +387,7 @@ public boolean offerLast(E e) { /** * @throws NoSuchElementException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeFirst(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { E e = pollFirst(); @@ -399,7 +399,7 @@ public E removeFirst(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { /** * @throws NoSuchElementException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeLast(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { E e = pollLast(); @@ -408,7 +408,7 @@ public E removeLast(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { return e; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollFirst(@GuardSatisfied @CanShrink ArrayDeque this) { final Object[] es; @@ -421,7 +421,7 @@ public E removeLast(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { return e; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollLast(@GuardSatisfied @CanShrink ArrayDeque this) { final Object[] es; @@ -476,7 +476,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 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeFirstOccurrence(@GuardSatisfied @CanShrink ArrayDeque this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { if (o != null) { @@ -506,7 +506,7 @@ public boolean removeFirstOccurrence(@GuardSatisfied @CanShrink ArrayDeque th * @param o element to be removed from this deque, if present * @return {@code true} if the deque contained the specified element */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeLastOccurrence(@GuardSatisfied @CanShrink ArrayDeque this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { if (o != null) { @@ -536,7 +536,7 @@ public boolean removeLastOccurrence(@GuardSatisfied @CanShrink ArrayDeque thi * @throws NullPointerException if the specified element is null */ @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(@GuardSatisfied ArrayDeque this, E e) { addLast(e); @@ -552,7 +552,7 @@ public boolean add(@GuardSatisfied ArrayDeque this, E e) { * @return {@code true} (as specified by {@link Queue#offer}) * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(@GuardSatisfied ArrayDeque this, E e) { return offerLast(e); @@ -569,7 +569,7 @@ public boolean offer(@GuardSatisfied ArrayDeque this, E e) { * @return the head of the queue represented by this deque * @throws NoSuchElementException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { return removeFirst(); @@ -585,7 +585,7 @@ public E remove(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { * @return the head of the queue represented by this deque, or * {@code null} if this deque is empty */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink ArrayDeque this) { return pollFirst(); @@ -630,7 +630,7 @@ public E element(@GuardSatisfied @NonEmpty ArrayDeque this) { * @param e the element to push * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void push(@GuardSatisfied ArrayDeque this, E e) { addFirst(e); @@ -646,7 +646,7 @@ public void push(@GuardSatisfied ArrayDeque this, E e) { * of the stack represented by this deque) * @throws NoSuchElementException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E pop(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { return removeFirst(); @@ -759,7 +759,7 @@ public final boolean hasNext() { return remaining > 0; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty DeqIterator this) { if (remaining <= 0) @@ -776,7 +776,7 @@ void postDelete(boolean leftShifted) { cursor = dec(cursor, elements.length); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void remove() { if (lastRet < 0) @@ -811,7 +811,7 @@ public void forEachRemaining(Consumer action) { private class DescendingIterator extends DeqIterator { DescendingIterator() { cursor = dec(tail, elements.length); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final E next(@NonEmpty DescendingIterator this) { if (remaining <= 0) @@ -968,7 +968,7 @@ public void forEach(Consumer action) { /** * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink ArrayDeque this, Predicate filter) { Objects.requireNonNull(filter); @@ -978,7 +978,7 @@ public boolean removeIf(@CanShrink ArrayDeque this, Predicate filt /** * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(@CanShrink ArrayDeque this, Collection c) { Objects.requireNonNull(c); @@ -988,7 +988,7 @@ public boolean removeAll(@CanShrink ArrayDeque this, Collection this, Collection c) { Objects.requireNonNull(c); @@ -1106,7 +1106,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 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @CanShrink ArrayDeque this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { return removeFirstOccurrence(o); @@ -1116,7 +1116,7 @@ public boolean remove(@GuardSatisfied @CanShrink ArrayDeque this, @GuardSatis * Removes all of the elements from this deque. * The deque will be empty after this call returns. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink ArrayDeque this) { circularClear(elements, head, tail); diff --git a/src/java.base/share/classes/java/util/ArrayList.java b/src/java.base/share/classes/java/util/ArrayList.java index 1594dbae39c07..2375ea57ade26 100644 --- a/src/java.base/share/classes/java/util/ArrayList.java +++ b/src/java.base/share/classes/java/util/ArrayList.java @@ -42,7 +42,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -504,7 +504,7 @@ public E getLast() { * @return the element previously at the specified position * @throws IndexOutOfBoundsException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E set(@GuardSatisfied ArrayList this, @NonNegative int index, E element) { Objects.checkIndex(index, size); @@ -518,7 +518,7 @@ 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") + // @SideEffectsOnly("this") private void add(E e, Object[] elementData, int s) { if (s == elementData.length) elementData = grow(); @@ -532,9 +532,9 @@ 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") + // @SideEffectsOnly("this") @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(@GuardSatisfied ArrayList this, E e) { modCount++; @@ -551,7 +551,7 @@ public boolean add(@GuardSatisfied ArrayList this, E e) { * @param element element to be inserted * @throws IndexOutOfBoundsException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(@GuardSatisfied ArrayList this, @NonNegative int index, E element) { rangeCheckForAdd(index); @@ -572,7 +572,7 @@ public void add(@GuardSatisfied ArrayList this, @NonNegative int index, E ele * * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addFirst(E element) { add(0, element); @@ -583,7 +583,7 @@ public void addFirst(E element) { * * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addLast(E element) { add(element); @@ -598,7 +598,7 @@ public void addLast(E element) { * @return the element that was removed from the list * @throws IndexOutOfBoundsException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @CanShrink ArrayList this, @NonNegative int index) { Objects.checkIndex(index, size); @@ -616,7 +616,7 @@ public E remove(@GuardSatisfied @CanShrink ArrayList this, @NonNegative int i * @throws NoSuchElementException {@inheritDoc} * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeFirst() { if (size == 0) { @@ -635,7 +635,7 @@ public E removeFirst() { * @throws NoSuchElementException {@inheritDoc} * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeLast() { int last = size - 1; @@ -751,7 +751,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 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @CanShrink ArrayList this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { final Object[] es = elementData; @@ -789,7 +789,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. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink ArrayList this) { modCount++; @@ -811,7 +811,7 @@ public void clear(@GuardSatisfied @CanShrink 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") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@GuardSatisfied ArrayList this, Collection c) { Object[] a = c.toArray(); @@ -843,7 +843,7 @@ public boolean addAll(@GuardSatisfied ArrayList this, Collection * @throws IndexOutOfBoundsException {@inheritDoc} * @throws NullPointerException if the specified collection is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@GuardSatisfied ArrayList this, @NonNegative int index, Collection c) { rangeCheckForAdd(index); @@ -936,7 +936,7 @@ private static String outOfBoundsMsg(int fromIndex, int toIndex) { * or if the specified collection is null * @see Collection#contains(Object) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(@CanShrink ArrayList this, Collection c) { return batchRemove(c, false, 0, size); @@ -958,7 +958,7 @@ public boolean removeAll(@CanShrink ArrayList this, Collection this, Collection c) { return batchRemove(c, true, 0, size); @@ -1119,7 +1119,7 @@ public boolean hasNext() { } @SuppressWarnings("unchecked") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty Itr this) { checkForComodification(); @@ -1133,7 +1133,7 @@ public E next(@NonEmpty Itr this) { return (E) elementData[lastRet = i]; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastRet < 0) @@ -1188,20 +1188,20 @@ public boolean hasPrevious() { return cursor != 0; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int nextIndex() { return cursor; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int previousIndex() { return cursor - 1; } @SuppressWarnings("unchecked") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E previous() { checkForComodification(); @@ -1215,7 +1215,7 @@ public E previous() { return (E) elementData[lastRet = i]; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void set(E e) { if (lastRet < 0) @@ -1229,7 +1229,7 @@ public void set(E e) { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(E e) { checkForComodification(); @@ -1275,7 +1275,7 @@ public void add(E e) { * @throws IndexOutOfBoundsException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @PolyGrowShrink List subList(@GuardSatisfied @PolyGrowShrink ArrayList this, @NonNegative int fromIndex, @NonNegative int toIndex) { subListRangeCheck(fromIndex, toIndex, size); @@ -1310,7 +1310,7 @@ private SubList(SubList parent, int fromIndex, int toIndex) { this.modCount = parent.modCount; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E set(@NonNegative int index, E element) { Objects.checkIndex(index, size); @@ -1332,7 +1332,7 @@ public E get(@NonNegative int index) { return size; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(@NonNegative int index, E element) { rangeCheckForAdd(index); @@ -1341,7 +1341,7 @@ public void add(@NonNegative int index, E element) { updateSizeAndModCount(1); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(@NonNegative int index) { Objects.checkIndex(index, size); @@ -1351,7 +1351,7 @@ public E remove(@NonNegative int index) { return result; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") protected void removeRange(int fromIndex, int toIndex) { checkForComodification(); @@ -1359,13 +1359,13 @@ protected void removeRange(int fromIndex, int toIndex) { updateSizeAndModCount(fromIndex - toIndex); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { return addAll(this.size, c); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@NonNegative int index, Collection c) { rangeCheckForAdd(index); @@ -1383,13 +1383,13 @@ public void replaceAll(UnaryOperator operator) { root.replaceAllRange(operator, offset, offset + size); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { return batchRemove(c, false); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { return batchRemove(c, true); @@ -1405,7 +1405,7 @@ private boolean batchRemove(Collection c, boolean complement) { return modified; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { checkForComodification(); @@ -1491,7 +1491,7 @@ public boolean hasNext() { } @SuppressWarnings("unchecked") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public E next(/*@NonEmpty ListIterator this*/) { checkForComodification(); int i = cursor; @@ -1857,7 +1857,7 @@ private static boolean isClear(long[] bits, int i) { * @throws NullPointerException {@inheritDoc} */ @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink ArrayList this, Predicate filter) { return removeIf(filter, 0, size); @@ -1921,7 +1921,7 @@ private void replaceAllRange(UnaryOperator operator, int i, int end) { @Override @SuppressWarnings("unchecked") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void sort(Comparator c) { final int expectedModCount = modCount; diff --git a/src/java.base/share/classes/java/util/Arrays.java b/src/java.base/share/classes/java/util/Arrays.java index d7d43d421a57e..37f0a44ea8a8a 100644 --- a/src/java.base/share/classes/java/util/Arrays.java +++ b/src/java.base/share/classes/java/util/Arrays.java @@ -44,7 +44,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -4402,7 +4402,7 @@ public boolean hasNext() { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty ArrayItr this) { int i = cursor; diff --git a/src/java.base/share/classes/java/util/Collection.java b/src/java.base/share/classes/java/util/Collection.java index ad33f9063f9ca..3a8a2a522ab13 100644 --- a/src/java.base/share/classes/java/util/Collection.java +++ b/src/java.base/share/classes/java/util/Collection.java @@ -489,7 +489,7 @@ default T[] toArray(IntFunction generator) { * time due to insertion restrictions */ @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean add(@GuardSatisfied Collection this, E e); @@ -513,7 +513,7 @@ default T[] toArray(IntFunction generator) { * @throws UnsupportedOperationException if the {@code remove} operation * is not supported by this collection */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean remove(@GuardSatisfied @CanShrink Collection this, @UnknownSignedness Object o); @@ -567,7 +567,7 @@ default T[] toArray(IntFunction generator) { * this time due to insertion restrictions * @see #add(Object) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean addAll(@GuardSatisfied Collection this, Collection c); @@ -594,7 +594,7 @@ default T[] toArray(IntFunction generator) { * @see #remove(Object) * @see #contains(Object) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean removeAll(@GuardSatisfied @CanShrink Collection this, Collection c); @@ -620,7 +620,7 @@ default T[] toArray(IntFunction generator) { * supported. * @since 1.8 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default boolean removeIf(@CanShrink Collection this, Predicate filter) { Objects.requireNonNull(filter); @@ -657,7 +657,7 @@ default boolean removeIf(@CanShrink Collection this, Predicate fil * @see #remove(Object) * @see #contains(Object) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean retainAll(@GuardSatisfied @CanShrink Collection this, Collection c); @@ -668,7 +668,7 @@ default boolean removeIf(@CanShrink Collection this, Predicate fil * @throws UnsupportedOperationException if the {@code clear} operation * is not supported by this collection */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void clear(@GuardSatisfied @CanShrink Collection this); diff --git a/src/java.base/share/classes/java/util/Collections.java b/src/java.base/share/classes/java/util/Collections.java index ac24514affeff..01197ac12ca44 100644 --- a/src/java.base/share/classes/java/util/Collections.java +++ b/src/java.base/share/classes/java/util/Collections.java @@ -45,7 +45,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -1123,10 +1123,10 @@ static class UnmodifiableCollection implements Collection, Serializable { @Pure @EnsuresNonEmptyIf(result = true, expression = "this") public boolean hasNext() {return i.hasNext();} - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(/*@NonEmpty Iterator this*/) {return i.next();} - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { throw new UnsupportedOperationException(); @@ -1140,13 +1140,13 @@ public void forEachRemaining(Consumer action) { }; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresNonEmpty("this") public boolean add(E e) { throw new UnsupportedOperationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { throw new UnsupportedOperationException(); @@ -1156,22 +1156,22 @@ public boolean remove(@UnknownSignedness Object o) { public boolean containsAll(Collection coll) { return c.containsAll(coll); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection coll) { throw new UnsupportedOperationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection coll) { throw new UnsupportedOperationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection coll) { throw new UnsupportedOperationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { throw new UnsupportedOperationException(); @@ -1184,7 +1184,7 @@ public void forEach(Consumer action) { c.forEach(action); } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { throw new UnsupportedOperationException(); @@ -1197,14 +1197,14 @@ public Spliterator spliterator() { } @SuppressWarnings("unchecked") @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Stream stream() { return (Stream)c.stream(); } @SuppressWarnings("unchecked") @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Stream parallelStream() { return (Stream)c.parallelStream(); @@ -1263,19 +1263,19 @@ private SequencedCollection sc() { // Even though this wrapper class is serializable, the reversed view is effectively // not serializable because it points to the reversed collection view, which usually isn't // serializable. - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public SequencedCollection reversed() { return new UnmodifiableSequencedCollection<>(sc().reversed()); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { throw new UnsupportedOperationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { throw new UnsupportedOperationException(); @@ -1289,13 +1289,13 @@ public E getLast() { return sc().getLast(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeFirst() { throw new UnsupportedOperationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeLast() { throw new UnsupportedOperationException(); @@ -1384,7 +1384,7 @@ private SequencedSet ss() { // Even though this wrapper class is serializable, the reversed view is effectively // not serializable because it points to the reversed set view, which usually isn't // serializable. - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public SequencedSet reversed() { return new UnmodifiableSequencedSet<>(ss().reversed()); @@ -1431,17 +1431,17 @@ static class UnmodifiableSortedSet public Comparator comparator() {return ss.comparator();} - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public SortedSet subSet(E fromElement, E toElement) { return new UnmodifiableSortedSet<>(ss.subSet(fromElement,toElement)); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public SortedSet headSet(E toElement) { return new UnmodifiableSortedSet<>(ss.headSet(toElement)); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public SortedSet tailSet(E fromElement) { return new UnmodifiableSortedSet<>(ss.tailSet(fromElement)); @@ -1524,36 +1524,36 @@ public EmptyNavigableSet() { public E floor(E e) { return ns.floor(e); } public E ceiling(E e) { return ns.ceiling(e); } public E higher(E e) { return ns.higher(e); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E pollFirst() { throw new UnsupportedOperationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E pollLast() { throw new UnsupportedOperationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public NavigableSet descendingSet() { return new UnmodifiableNavigableSet<>(ns.descendingSet()); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Iterator descendingIterator() { return descendingSet().iterator(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public NavigableSet subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive) { return new UnmodifiableNavigableSet<>( ns.subSet(fromElement, fromInclusive, toElement, toInclusive)); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public NavigableSet headSet(E toElement, boolean inclusive) { return new UnmodifiableNavigableSet<>( ns.headSet(toElement, inclusive)); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public NavigableSet tailSet(E fromElement, boolean inclusive) { return new UnmodifiableNavigableSet<>( @@ -1608,24 +1608,24 @@ static class UnmodifiableList extends UnmodifiableCollection public int hashCode() {return list.hashCode();} public E get(int index) {return list.get(index);} - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E set(int index, E element) { throw new UnsupportedOperationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(int index, E element) { throw new UnsupportedOperationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(int index) { throw new UnsupportedOperationException(); } public int indexOf(Object o) {return list.indexOf(o);} public int lastIndexOf(Object o) {return list.lastIndexOf(o);} - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(int index, Collection c) { throw new UnsupportedOperationException(); @@ -1637,7 +1637,7 @@ public void replaceAll(UnaryOperator operator) { throw new UnsupportedOperationException(); } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void sort(Comparator c) { throw new UnsupportedOperationException(); @@ -1645,7 +1645,7 @@ public void sort(Comparator c) { public @PolyGrowShrink @PolyNonEmpty ListIterator listIterator(@PolyGrowShrink @PolyNonEmpty UnmodifiableList this) {return listIterator(0);} - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public ListIterator listIterator(final int index) { return new ListIterator<>() { @@ -1655,27 +1655,27 @@ public ListIterator listIterator(final int index) { @Pure @EnsuresNonEmptyIf(result = true, expression = "this") public boolean hasNext() {return i.hasNext();} - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(/*@NonEmpty ListIterator this*/) {return i.next();} @Pure public boolean hasPrevious() {return i.hasPrevious();} - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public E previous() {return i.previous();} public int nextIndex() {return i.nextIndex();} public int previousIndex() {return i.previousIndex();} - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { throw new UnsupportedOperationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void set(E e) { throw new UnsupportedOperationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(E e) { throw new UnsupportedOperationException(); @@ -1795,23 +1795,23 @@ private static class UnmodifiableMap implements Map, Serializable { public boolean containsValue(@UnknownSignedness Object val) {return m.containsValue(val);} public V get(Object key) {return m.get(key);} - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresKeyFor(value={"#1"}, map={"this"}) public V put(K key, V value) { throw new UnsupportedOperationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V remove(Object key) { throw new UnsupportedOperationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putAll(Map m) { throw new UnsupportedOperationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { throw new UnsupportedOperationException(); @@ -1864,7 +1864,7 @@ public void replaceAll(BiFunction function) { throw new UnsupportedOperationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresKeyFor(value={"#1"}, map={"this"}) @Override @@ -1873,21 +1873,21 @@ public V putIfAbsent(K key, V value) { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object key, @UnknownSignedness Object value) { throw new UnsupportedOperationException(); } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { throw new UnsupportedOperationException(); } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { throw new UnsupportedOperationException(); @@ -2027,12 +2027,12 @@ public Iterator> iterator() { public boolean hasNext() { return i.hasNext(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(/*@NonEmpty Iterator> this*/) { return new UnmodifiableEntry<>(i.next()); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { throw new UnsupportedOperationException(); @@ -2187,25 +2187,25 @@ public SequencedMap reversed() { return new UnmodifiableSequencedMap<>(sm().reversed()); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Entry pollFirstEntry() { throw new UnsupportedOperationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Entry pollLastEntry() { throw new UnsupportedOperationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putFirst(K k, V v) { throw new UnsupportedOperationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putLast(K k, V v) { throw new UnsupportedOperationException(); @@ -2395,11 +2395,11 @@ public Entry lastEntry() { : null; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Entry pollFirstEntry() { throw new UnsupportedOperationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Entry pollLastEntry() { throw new UnsupportedOperationException(); } @@ -2523,13 +2523,13 @@ public Iterator iterator() { return c.iterator(); // Must be manually synched by user! } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresNonEmpty("this") public boolean add(E e) { synchronized (mutex) {return c.add(e);} } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { synchronized (mutex) {return c.remove(o);} @@ -2539,22 +2539,22 @@ public boolean remove(@UnknownSignedness Object o) { public boolean containsAll(Collection coll) { synchronized (mutex) {return c.containsAll(coll);} } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection coll) { synchronized (mutex) {return c.addAll(coll);} } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection coll) { synchronized (mutex) {return c.removeAll(coll);} } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection coll) { synchronized (mutex) {return c.retainAll(coll);} } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { synchronized (mutex) {c.clear();} @@ -2568,7 +2568,7 @@ public void forEach(Consumer consumer) { synchronized (mutex) {c.forEach(consumer);} } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { synchronized (mutex) {return c.removeIf(filter);} @@ -2818,10 +2818,10 @@ static class SynchronizedNavigableSet public E floor(E e) { synchronized (mutex) {return ns.floor(e);} } public E ceiling(E e) { synchronized (mutex) {return ns.ceiling(e);} } public E higher(E e) { synchronized (mutex) {return ns.higher(e);} } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E pollFirst() { synchronized (mutex) {return ns.pollFirst();} } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E pollLast() { synchronized (mutex) {return ns.pollLast();} } @@ -2941,17 +2941,17 @@ public int hashCode() { public E get(int index) { synchronized (mutex) {return list.get(index);} } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E set(int index, E element) { synchronized (mutex) {return list.set(index, element);} } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(int index, E element) { synchronized (mutex) {list.add(index, element);} } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(int index) { synchronized (mutex) {return list.remove(index);} @@ -2964,7 +2964,7 @@ public int lastIndexOf(Object o) { synchronized (mutex) {return list.lastIndexOf(o);} } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(int index, Collection c) { synchronized (mutex) {return list.addAll(index, c);} @@ -2991,7 +2991,7 @@ public void replaceAll(UnaryOperator operator) { synchronized (mutex) {list.replaceAll(operator);} } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void sort(Comparator c) { synchronized (mutex) {list.sort(c);} @@ -3133,23 +3133,23 @@ public V get(Object key) { synchronized (mutex) {return m.get(key);} } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresKeyFor(value={"#1"}, map={"this"}) public V put(K key, V value) { synchronized (mutex) {return m.put(key, value);} } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V remove(Object key) { synchronized (mutex) {return m.remove(key);} } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putAll(Map map) { synchronized (mutex) {m.putAll(map);} } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { synchronized (mutex) {m.clear();} @@ -3211,7 +3211,7 @@ public void forEach(BiConsumer action) { public void replaceAll(BiFunction function) { synchronized (mutex) {m.replaceAll(function);} } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresKeyFor(value={"#1"}, map={"this"}) @Override @@ -3219,19 +3219,19 @@ public V putIfAbsent(K key, V value) { synchronized (mutex) {return m.putIfAbsent(key, value);} } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object key, @UnknownSignedness Object value) { synchronized (mutex) {return m.remove(key, value);} } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { synchronized (mutex) {return m.replace(key, oldValue, newValue);} } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { synchronized (mutex) {return m.replace(key, value);} @@ -3465,11 +3465,11 @@ public Entry firstEntry() { synchronized (mutex) { return nm.firstEntry(); } } public Entry lastEntry() { synchronized (mutex) { return nm.lastEntry(); } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Entry pollFirstEntry() { synchronized (mutex) { return nm.pollFirstEntry(); } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Entry pollLastEntry() { synchronized (mutex) { return nm.pollLastEntry(); } } @@ -3662,10 +3662,10 @@ private String badElementMsg(Object o) { public @Nullable T[] toArray(@PolyNull T[] a) { return c.toArray(a); } public T[] toArray(IntFunction f) { return c.toArray(f); } public String toString() { return c.toString(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { return c.remove(o); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { c.clear(); } @@ -3673,12 +3673,12 @@ private String badElementMsg(Object o) { public boolean containsAll(Collection coll) { return c.containsAll(coll); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection coll) { return c.removeAll(coll); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection coll) { return c.retainAll(coll); @@ -3693,10 +3693,10 @@ public Iterator iterator() { @Pure @EnsuresNonEmptyIf(result = true, expression = "this") public boolean hasNext() { return it.hasNext(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(/*@NonEmpty Iterator this*/) { return it.next(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { it.remove(); } public void forEachRemaining(Consumer action) { @@ -3705,7 +3705,7 @@ public void forEachRemaining(Consumer action) { }; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresNonEmpty("this") public boolean add(E e) { return c.add(typeCheck(e)); } @@ -3741,7 +3741,7 @@ Collection checkedCopyOf(Collection coll) { return (Collection) Arrays.asList(a); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection coll) { // Doing things this way insulates us from concurrent changes @@ -3755,7 +3755,7 @@ public boolean addAll(Collection coll) { @Override public void forEach(Consumer action) {c.forEach(action);} @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { return c.removeIf(filter); @@ -3824,13 +3824,13 @@ static class CheckedQueue public int hashCode() {return c.hashCode();} @Pure public E peek() {return queue.peek();} - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E poll() {return queue.poll();} - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove() {return queue.remove();} - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) {return queue.offer(typeCheck(e));} } @@ -4083,25 +4083,25 @@ static class CheckedList public boolean equals(Object o) { return o == this || list.equals(o); } public int hashCode() { return list.hashCode(); } public E get(int index) { return list.get(index); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(int index) { return list.remove(index); } public int indexOf(Object o) { return list.indexOf(o); } public int lastIndexOf(Object o) { return list.lastIndexOf(o); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E set(int index, E element) { return list.set(index, typeCheck(element)); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(int index, E element) { list.add(index, typeCheck(element)); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(int index, Collection c) { return list.addAll(index, checkedCopyOf(c)); @@ -4115,24 +4115,24 @@ public ListIterator listIterator(final int index) { @Pure @EnsuresNonEmptyIf(result = true, expression = "this") public boolean hasNext() { return i.hasNext(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(/*@NonEmpty ListIterator this*/) { return i.next(); } public boolean hasPrevious() { return i.hasPrevious(); } public E previous() { return i.previous(); } public int nextIndex() { return i.nextIndex(); } public int previousIndex() { return i.previousIndex(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { i.remove(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void set(E e) { i.set(typeCheck(e)); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(E e) { i.add(typeCheck(e)); @@ -4165,7 +4165,7 @@ public void replaceAll(UnaryOperator operator) { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void sort(Comparator c) { list.sort(c); @@ -4295,10 +4295,10 @@ private String badValueMsg(Object value) { @Pure public boolean containsValue(@UnknownSignedness Object v) { return m.containsValue(v); } public V get(Object key) { return m.get(key); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V remove(Object key) { return m.remove(key); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { m.clear(); } public Set keySet() { return m.keySet(); } @@ -4307,7 +4307,7 @@ private String badValueMsg(Object value) { public int hashCode() { return m.hashCode(); } public String toString() { return m.toString(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresKeyFor(value={"#1"}, map={"this"}) public V put(K key, V value) { @@ -4315,7 +4315,7 @@ public V put(K key, V value) { return m.put(key, value); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @SuppressWarnings("unchecked") public void putAll(Map t) { @@ -4359,7 +4359,7 @@ public void replaceAll(BiFunction function) { m.replaceAll(typeCheck(function)); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresKeyFor(value={"#1"}, map={"this"}) @Override @@ -4369,14 +4369,14 @@ public V putIfAbsent(K key, V value) { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object key, @UnknownSignedness Object value) { return m.remove(key, value); } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { typeCheck(key, newValue); @@ -4384,7 +4384,7 @@ public boolean replace(K key, V oldValue, V newValue) { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { typeCheck(key, value); @@ -4452,17 +4452,17 @@ static class CheckedEntrySet implements Set> { public boolean isEmpty() { return s.isEmpty(); } public String toString() { return s.toString(); } public int hashCode() { return s.hashCode(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { s.clear(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresNonEmpty("this") public boolean add(Map.Entry e) { throw new UnsupportedOperationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection> coll) { throw new UnsupportedOperationException(); @@ -4475,11 +4475,11 @@ public Iterator> iterator() { @Pure @EnsuresNonEmptyIf(result = true, expression = "this") public boolean hasNext() { return i.hasNext(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { i.remove(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(/*@NonEmpty Iterator> this*/) { return checkedEntry(i.next(), valueType); @@ -4556,7 +4556,7 @@ public boolean containsAll(Collection c) { return true; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { if (!(o instanceof Map.Entry)) @@ -4565,12 +4565,12 @@ public boolean remove(@UnknownSignedness Object o) { <>((Map.Entry)o)); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { return batchRemove(c, false); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { return batchRemove(c, true); @@ -4838,7 +4838,7 @@ public Entry lastEntry() { : null; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Entry pollFirstEntry() { Entry entry = nm.pollFirstEntry(); @@ -4847,7 +4847,7 @@ public Entry pollFirstEntry() { : new CheckedMap.CheckedEntrySet.CheckedEntry<>(entry, valueType); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Entry pollLastEntry() { Entry entry = nm.pollLastEntry(); @@ -4944,10 +4944,10 @@ private static class EmptyIterator implements Iterator { @Pure @EnsuresNonEmptyIf(result = true, expression = "this") public boolean hasNext() { return false; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty EmptyIterator this) { throw new NoSuchElementException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove(@NonEmpty EmptyIterator this) { throw new IllegalStateException(); } @Override @@ -4999,10 +4999,10 @@ private static class EmptyListIterator public E previous() { throw new NoSuchElementException(); } public int nextIndex() { return 0; } public int previousIndex() { return -1; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void set(E e) { throw new IllegalStateException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(E e) { throw new UnsupportedOperationException(); } } @@ -5420,7 +5420,7 @@ public void replaceAll(BiFunction function) { Objects.requireNonNull(function); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresKeyFor(value={"#1"}, map={"this"}) @Override @@ -5429,21 +5429,21 @@ public V putIfAbsent(K key, V value) { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object key, @UnknownSignedness Object value) { throw new UnsupportedOperationException(); } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { throw new UnsupportedOperationException(); } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { throw new UnsupportedOperationException(); @@ -5506,7 +5506,7 @@ static Iterator singletonIterator(final E e) { public boolean hasNext() { return hasNext; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(/*@NonEmpty Iterator this*/) { if (hasNext) { @@ -5515,7 +5515,7 @@ public E next(/*@NonEmpty Iterator this*/) { } throw new NoSuchElementException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { throw new UnsupportedOperationException(); @@ -5615,7 +5615,7 @@ public Spliterator spliterator() { return singletonSpliterator(element); } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { throw new UnsupportedOperationException(); @@ -5680,7 +5680,7 @@ public void forEach(Consumer action) { action.accept(element); } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { throw new UnsupportedOperationException(); @@ -5793,7 +5793,7 @@ public void replaceAll(BiFunction function) { throw new UnsupportedOperationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresKeyFor(value={"#1"}, map={"this"}) @Override @@ -5802,21 +5802,21 @@ public V putIfAbsent(K key, V value) { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object key, @UnknownSignedness Object value) { throw new UnsupportedOperationException(); } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { throw new UnsupportedOperationException(); } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { throw new UnsupportedOperationException(); diff --git a/src/java.base/share/classes/java/util/Deque.java b/src/java.base/share/classes/java/util/Deque.java index ecac591a51941..c288e0162b2c1 100644 --- a/src/java.base/share/classes/java/util/Deque.java +++ b/src/java.base/share/classes/java/util/Deque.java @@ -238,7 +238,7 @@ public interface Deque extends Queue, SequencedCollection { * element prevents it from being added to this deque */ @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void addFirst(@GuardSatisfied Deque this, E e); @@ -262,7 +262,7 @@ public interface Deque extends Queue, SequencedCollection { * element prevents it from being added to this deque */ @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void addLast(@GuardSatisfied Deque this, E e); @@ -282,7 +282,7 @@ public interface Deque extends Queue, SequencedCollection { * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean offerFirst(E e); @@ -302,7 +302,7 @@ public interface Deque extends Queue, SequencedCollection { * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean offerLast(E e); @@ -314,7 +314,7 @@ public interface Deque extends Queue, SequencedCollection { * @return the head of this deque * @throws NoSuchElementException if this deque is empty */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E removeFirst(@GuardSatisfied @NonEmpty @CanShrink Deque this); @@ -326,7 +326,7 @@ public interface Deque extends Queue, SequencedCollection { * @return the tail of this deque * @throws NoSuchElementException if this deque is empty */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E removeLast(@GuardSatisfied @NonEmpty @CanShrink Deque this); @@ -336,7 +336,7 @@ public interface Deque extends Queue, SequencedCollection { * * @return the head of this deque, or {@code null} if this deque is empty */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E pollFirst(@GuardSatisfied @CanShrink Deque this); @@ -346,7 +346,7 @@ public interface Deque extends Queue, SequencedCollection { * * @return the tail of this deque, or {@code null} if this deque is empty */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E pollLast(@GuardSatisfied @CanShrink Deque this); @@ -379,7 +379,7 @@ public interface Deque extends Queue, SequencedCollection { * * @return the head of this deque, or {@code null} if this deque is empty */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E peekFirst(); @@ -389,7 +389,7 @@ public interface Deque extends Queue, SequencedCollection { * * @return the tail of this deque, or {@code null} if this deque is empty */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E peekLast(); @@ -410,7 +410,7 @@ public interface Deque extends Queue, SequencedCollection { * deque does not permit null elements * ({@linkplain Collection##optional-restrictions optional}) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean removeFirstOccurrence(@GuardSatisfied @CanShrink Deque this, Object o); @@ -431,7 +431,7 @@ public interface Deque extends Queue, SequencedCollection { * deque does not permit null elements * ({@linkplain Collection##optional-restrictions optional}) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean removeLastOccurrence(@GuardSatisfied @CanShrink Deque this, Object o); @@ -460,7 +460,7 @@ public interface Deque extends Queue, SequencedCollection { * element prevents it from being added to this deque */ @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean add(@GuardSatisfied Deque this, E e); @@ -485,7 +485,7 @@ public interface Deque extends Queue, SequencedCollection { * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean offer(E e); @@ -500,7 +500,7 @@ public interface Deque extends Queue, SequencedCollection { * @return the head of the queue represented by this deque * @throws NoSuchElementException if this deque is empty */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E remove(@GuardSatisfied @NonEmpty @CanShrink Deque this); @@ -514,7 +514,7 @@ public interface Deque extends Queue, SequencedCollection { * @return the first element of this deque, or {@code null} if * this deque is empty */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E poll(@GuardSatisfied @CanShrink Deque this); @@ -529,7 +529,7 @@ public interface Deque extends Queue, SequencedCollection { * @return the head of the queue represented by this deque * @throws NoSuchElementException if this deque is empty */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E element(@GuardSatisfied @NonEmpty Deque this); @@ -543,7 +543,7 @@ public interface Deque extends Queue, SequencedCollection { * @return the head of the queue represented by this deque, or * {@code null} if this deque is empty */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E peek(); @@ -571,7 +571,7 @@ public interface Deque extends Queue, SequencedCollection { * @throws IllegalArgumentException if some property of an element of the * specified collection prevents it from being added to this deque */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean addAll(Collection c); @@ -595,7 +595,7 @@ public interface Deque extends Queue, SequencedCollection { * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void push(@GuardSatisfied Deque this, E e); @@ -609,7 +609,7 @@ public interface Deque extends Queue, SequencedCollection { * of the stack represented by this deque) * @throws NoSuchElementException if this deque is empty */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E pop(@GuardSatisfied @NonEmpty @CanShrink Deque this); @@ -635,7 +635,7 @@ public interface Deque extends Queue, SequencedCollection { * deque does not permit null elements * ({@linkplain Collection##optional-restrictions optional}) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean remove(@GuardSatisfied @CanShrink Deque this, @UnknownSignedness Object o); @@ -682,7 +682,7 @@ public interface Deque extends Queue, SequencedCollection { * @return an iterator over the elements in this deque in reverse * sequence */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") Iterator descendingIterator(); @@ -696,7 +696,7 @@ public interface Deque extends Queue, SequencedCollection { * @return a reverse-ordered view of this collection, as a {@code Deque} * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default Deque reversed() { return ReverseOrderDequeView.of(this); diff --git a/src/java.base/share/classes/java/util/EnumMap.java b/src/java.base/share/classes/java/util/EnumMap.java index cf7d7956c7895..9df266b7be679 100644 --- a/src/java.base/share/classes/java/util/EnumMap.java +++ b/src/java.base/share/classes/java/util/EnumMap.java @@ -287,7 +287,7 @@ private boolean containsMapping(@GuardSatisfied @UnknownSignedness Object key, @ * @throws NullPointerException if the specified key is null */ @EnsuresKeyFor(value={"#1"}, map={"this"}) - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V put(K key, V value) { typeCheck(key); @@ -309,7 +309,7 @@ private boolean containsMapping(@GuardSatisfied @UnknownSignedness Object key, @ * return can also indicate that the map previously associated * {@code null} with the specified key.) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V remove(@GuardSatisfied @UnknownSignedness Object key) { if (!isValidKey(key)) @@ -363,7 +363,7 @@ private boolean isValidKey(@GuardSatisfied @UnknownSignedness Object key) { "and vals are private class members for EnumMap and are absent in AbstractMap."}) @SuppressWarnings({"nullness:contracts.precondition.override.invalid"}) @RequiresNonNull({"keyUniverse", "vals"}) - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putAll(@UnknownInitialization EnumMap this, Map m) { if (m instanceof EnumMap em) { @@ -389,7 +389,7 @@ public void putAll(@UnknownInitialization EnumMap this, Map iterator() { public boolean contains(@Nullable @UnknownSignedness Object o) { return containsKey(o); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { int oldSize = size; EnumMap.this.remove(o); return size != oldSize; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { EnumMap.this.clear(); @@ -484,7 +484,7 @@ public Iterator iterator() { public boolean contains(@Nullable @UnknownSignedness Object o) { return containsValue(o); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { o = maskNull(o); @@ -498,7 +498,7 @@ public boolean remove(@Nullable @UnknownSignedness Object o) { } return false; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { EnumMap.this.clear(); @@ -535,7 +535,7 @@ public boolean contains(@Nullable @UnknownSignedness Object o) { return o instanceof Map.Entry entry && containsMapping(entry.getKey(), entry.getValue()); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { return o instanceof Map.Entry entry @@ -545,7 +545,7 @@ public boolean remove(@Nullable @UnknownSignedness Object o) { public @NonNegative int size() { return size; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { EnumMap.this.clear(); @@ -599,7 +599,7 @@ public boolean hasNext() { return index != vals.length; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { checkLastReturnedIndex(); @@ -618,7 +618,7 @@ private void checkLastReturnedIndex() { } private class KeyIterator extends EnumMapIterator { - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty KeyIterator this) { if (!hasNext()) @@ -632,7 +632,7 @@ private class ValueIterator extends EnumMapIterator { @CFComment({"nullness: Value returned by unmaskNull", "will be of type V (not @Nullable V) for mapped value"}) @SuppressWarnings({"nullness:return"}) - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V next(@NonEmpty ValueIterator this) { if (!hasNext()) @@ -645,7 +645,7 @@ public V next(@NonEmpty ValueIterator this) { private class EntryIterator extends EnumMapIterator> { private Entry lastReturnedEntry; - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(@NonEmpty EntryIterator this) { if (!hasNext()) @@ -654,7 +654,7 @@ public Map.Entry next(@NonEmpty EntryIterator this) { return lastReturnedEntry; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { lastReturnedIndex = diff --git a/src/java.base/share/classes/java/util/EnumSet.java b/src/java.base/share/classes/java/util/EnumSet.java index c9df90a2e86b9..02b36184d757a 100644 --- a/src/java.base/share/classes/java/util/EnumSet.java +++ b/src/java.base/share/classes/java/util/EnumSet.java @@ -145,7 +145,7 @@ public static > EnumSet allOf(Class elementType) { * Adds all of the elements from the appropriate enum type to this enum * set, which is empty prior to the call. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") abstract void addAll(); @@ -378,7 +378,7 @@ public static > EnumSet range(E from, E to) { * Adds the specified range to this enum set, which is empty prior * to the call. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") abstract void addRange(E from, E to); @@ -388,7 +388,7 @@ public static > EnumSet range(E from, E to) { * @return a copy of this set */ @SuppressWarnings("unchecked") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public EnumSet clone() { try { @@ -401,7 +401,7 @@ public EnumSet clone() { /** * Complements the contents of this enum set. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") abstract void complement(); diff --git a/src/java.base/share/classes/java/util/Enumeration.java b/src/java.base/share/classes/java/util/Enumeration.java index f86132d27e72c..3ae284e8d527c 100644 --- a/src/java.base/share/classes/java/util/Enumeration.java +++ b/src/java.base/share/classes/java/util/Enumeration.java @@ -29,7 +29,7 @@ import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf; import org.checkerframework.checker.nonempty.qual.NonEmpty; import org.checkerframework.dataflow.qual.Pure; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -134,7 +134,7 @@ default Iterator asIterator() { @Override public boolean hasNext() { return hasMoreElements(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Override public E next(/*@NonEmpty Iterator this*/) { return nextElement(); diff --git a/src/java.base/share/classes/java/util/HashMap.java b/src/java.base/share/classes/java/util/HashMap.java index f0cd011923ee3..5af06bf32997b 100644 --- a/src/java.base/share/classes/java/util/HashMap.java +++ b/src/java.base/share/classes/java/util/HashMap.java @@ -39,7 +39,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -319,7 +319,7 @@ public final int hashCode() { return Objects.hashCode(key) ^ Objects.hashCode(value); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final V setValue(V newValue) { V oldValue = value; @@ -643,7 +643,7 @@ public boolean containsKey(@GuardSatisfied HashMap this, @GuardSatisfied @ * previously associated {@code null} with {@code key}.) */ @EnsuresKeyFor(value={"#1"}, map={"this"}) - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V put(@GuardSatisfied HashMap this, K key, V value) { return putVal(hash(key), key, value, false, true); @@ -819,7 +819,7 @@ else if ((e = tab[index = (n - 1) & hash]) != null) { * @param m mappings to be stored in this map * @throws NullPointerException if the specified map is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putAll(@GuardSatisfied HashMap this, Map m) { putMapEntries(m, true); @@ -834,7 +834,7 @@ public void putAll(@GuardSatisfied HashMap this, Map this, @GuardSatisfied @Nullable @UnknownSignedness Object key) { Node e; @@ -897,7 +897,7 @@ else if (node == p) * Removes all of the mappings from this map. * The map will be empty after this call returns. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied HashMap this) { Node[] tab; @@ -1028,7 +1028,7 @@ T[] valuesToArray(T[] a) { final class KeySet extends AbstractSet { @Pure public final @NonNegative int size() { return size; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void clear() { HashMap.this.clear(); } @SideEffectFree @@ -1036,7 +1036,7 @@ final class KeySet extends AbstractSet { @Pure @EnsuresNonEmptyIf(result = true, expression = "this") public final boolean contains(@Nullable @UnknownSignedness Object o) { return containsKey(o); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final boolean remove(@Nullable @UnknownSignedness Object key) { return removeNode(hash(key), key, null, false, true) != null; @@ -1099,7 +1099,7 @@ public Collection values(@GuardSatisfied HashMap this) { final class Values extends AbstractCollection { @Pure public final @NonNegative int size() { return size; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void clear() { HashMap.this.clear(); } @SideEffectFree @@ -1161,7 +1161,7 @@ public final void forEach(Consumer action) { final class EntrySet extends AbstractSet> { @Pure public final @NonNegative int size() { return size; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void clear() { HashMap.this.clear(); } @SideEffectFree @@ -1177,7 +1177,7 @@ public final boolean contains(@Nullable @UnknownSignedness Object o) { Node candidate = getNode(key); return candidate != null && candidate.equals(e); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final boolean remove(@Nullable @UnknownSignedness Object o) { if (o instanceof Map.Entry e) { @@ -1219,21 +1219,21 @@ public V getOrDefault(@GuardSatisfied @Nullable @UnknownSignedness Object key, V @EnsuresKeyFor(value={"#1"}, map={"this"}) @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V putIfAbsent(K key, V value) { return putVal(hash(key), key, value, true, true); } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @Nullable @UnknownSignedness Object key, @GuardSatisfied @Nullable @UnknownSignedness Object value) { return removeNode(hash(key), key, value, true, true) != null; } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { Node e; V v; @@ -1247,7 +1247,7 @@ public boolean replace(K key, V oldValue, V newValue) { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V replace(K key, V value) { Node e; @@ -1686,7 +1686,7 @@ public final boolean hasNext() { return next != null; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") final Node nextNode(@NonEmpty HashIterator this) { Node[] t; Node e = next; @@ -1700,7 +1700,7 @@ final Node nextNode(@NonEmpty HashIterator this) { return e; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void remove() { Node p = current; @@ -1716,21 +1716,21 @@ public final void remove() { final class KeyIterator extends HashIterator implements Iterator { - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final K next(@NonEmpty KeyIterator this) { return nextNode().key; } } final class ValueIterator extends HashIterator implements Iterator { - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final V next(@NonEmpty ValueIterator this) { return nextNode().value; } } final class EntryIterator extends HashIterator implements Iterator> { - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final Map.Entry next(@NonEmpty EntryIterator this) { return nextNode(); } } diff --git a/src/java.base/share/classes/java/util/HashSet.java b/src/java.base/share/classes/java/util/HashSet.java index 57d49ac0d8937..98dc6de2f27ce 100644 --- a/src/java.base/share/classes/java/util/HashSet.java +++ b/src/java.base/share/classes/java/util/HashSet.java @@ -37,7 +37,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -248,9 +248,9 @@ public boolean contains(@GuardSatisfied HashSet this, @GuardSatisfied @Nullab * @return {@code true} if this set did not already contain the specified * element */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(@GuardSatisfied HashSet this, E e) { return map.put(e, PRESENT)==null; @@ -268,7 +268,7 @@ public boolean add(@GuardSatisfied HashSet this, E e) { * @param o object to be removed from this set, if present * @return {@code true} if the set contained the specified element */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied HashSet this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { return map.remove(o)==PRESENT; @@ -278,7 +278,7 @@ public boolean remove(@GuardSatisfied HashSet this, @GuardSatisfied @Nullable * Removes all of the elements from this set. * The set will be empty after this call returns. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied HashSet this) { map.clear(); @@ -399,7 +399,7 @@ private void readObject(java.io.ObjectInputStream s) * @return a {@code Spliterator} over the elements in this set * @since 1.8 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Spliterator spliterator() { return new HashMap.KeySpliterator<>(map, 0, -1, 0, 0); diff --git a/src/java.base/share/classes/java/util/Hashtable.java b/src/java.base/share/classes/java/util/Hashtable.java index 9c0a8c135e8c7..ac6afe1422b2d 100644 --- a/src/java.base/share/classes/java/util/Hashtable.java +++ b/src/java.base/share/classes/java/util/Hashtable.java @@ -39,7 +39,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -501,7 +501,7 @@ private void addEntry(int hash, K key, V value, int index) { * @see #get(Object) */ @EnsuresKeyFor(value={"#1"}, map={"this"}) - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized @Nullable V put(@GuardSatisfied Hashtable this, K key, V value) { // Make sure the value is not null @@ -536,7 +536,7 @@ private void addEntry(int hash, K key, V value, int index) { * or {@code null} if the key did not have a mapping * @throws NullPointerException if the key is {@code null} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized @Nullable V remove(@GuardSatisfied Hashtable this, @GuardSatisfied @UnknownSignedness Object key) { Entry tab[] = table; @@ -570,7 +570,7 @@ private void addEntry(int hash, K key, V value, int index) { * @throws NullPointerException if the specified map is null * @since 1.2 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized void putAll(@GuardSatisfied Hashtable this, Map t) { for (Map.Entry e : t.entrySet()) @@ -580,7 +580,7 @@ public synchronized void putAll(@GuardSatisfied Hashtable this, Map this) { Entry tab[] = table; @@ -719,12 +719,12 @@ public Iterator iterator() { public boolean contains(@UnknownSignedness Object o) { return containsKey(o); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { return Hashtable.this.remove(o) != null; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { Hashtable.this.clear(); @@ -761,7 +761,7 @@ public Iterator> iterator() { } @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(Map.Entry o) { return super.add(o); @@ -783,7 +783,7 @@ public boolean contains(@UnknownSignedness Object o) { return false; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { if (!(o instanceof Map.Entry entry)) @@ -816,7 +816,7 @@ public boolean remove(@UnknownSignedness Object o) { return count; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { Hashtable.this.clear(); @@ -860,7 +860,7 @@ public Iterator iterator() { public boolean contains(@UnknownSignedness Object o) { return containsValue(o); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { Hashtable.this.clear(); @@ -996,7 +996,7 @@ public synchronized void replaceAll(BiFunction this) { Entry et = entry; @@ -1587,7 +1587,7 @@ public boolean hasNext() { return hasMoreElements(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public T next(@NonEmpty Enumerator this) { if (Hashtable.this.modCount != expectedModCount) @@ -1595,7 +1595,7 @@ public T next(@NonEmpty Enumerator this) { return nextElement(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (!iterator) diff --git a/src/java.base/share/classes/java/util/IdentityHashMap.java b/src/java.base/share/classes/java/util/IdentityHashMap.java index 2f1598b507c4e..5ef7004af3355 100644 --- a/src/java.base/share/classes/java/util/IdentityHashMap.java +++ b/src/java.base/share/classes/java/util/IdentityHashMap.java @@ -37,7 +37,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -458,7 +458,7 @@ private boolean containsMapping(@UnknownSignedness @GuardSatisfied @Nullable Obj * @see #containsKey(Object) */ @EnsuresKeyFor(value={"#1"}, map={"this"}) - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V put(@GuardSatisfied IdentityHashMap this, K key, V value) { final Object k = maskNull(key); @@ -541,7 +541,7 @@ private boolean resize(int newCapacity) { * @param m mappings to be stored in this map * @throws NullPointerException if the specified map is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putAll(@GuardSatisfied IdentityHashMap this, Map m) { int n = m.size(); @@ -565,7 +565,7 @@ public void putAll(@GuardSatisfied IdentityHashMap this, Map this, @GuardSatisfied @Nullable @UnknownSignedness Object key) { Object k = maskNull(key); @@ -663,7 +663,7 @@ private void closeDeletion(int d) { * Removes all of the mappings from this map. * The map will be empty after this call returns. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied IdentityHashMap this) { modCount++; @@ -791,7 +791,7 @@ public boolean hasNext() { return false; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") protected int nextIndex(@NonEmpty IdentityHashMapIterator this) { if (modCount != expectedModCount) throw new ConcurrentModificationException(); @@ -804,7 +804,7 @@ protected int nextIndex(@NonEmpty IdentityHashMapIterator this) { return lastReturnedIndex; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastReturnedIndex == -1) @@ -886,7 +886,7 @@ public void remove() { private class KeyIterator extends IdentityHashMapIterator { @SuppressWarnings("unchecked") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty KeyIterator this) { return (K) unmaskNull(traversalTable[nextIndex()]); @@ -895,7 +895,7 @@ public K next(@NonEmpty KeyIterator this) { private class ValueIterator extends IdentityHashMapIterator { @SuppressWarnings("unchecked") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V next(@NonEmpty ValueIterator this) { return (V) traversalTable[nextIndex() + 1]; @@ -907,14 +907,14 @@ private class EntryIterator { private Entry lastReturnedEntry; - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(@NonEmpty EntryIterator this) { lastReturnedEntry = new Entry(nextIndex()); return lastReturnedEntry; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { lastReturnedIndex = @@ -944,7 +944,7 @@ public V getValue() { } @SuppressWarnings("unchecked") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V setValue(V value) { checkIndexForEntryUse(); @@ -1059,7 +1059,7 @@ public Iterator iterator() { public boolean contains(@Nullable @UnknownSignedness Object o) { return containsKey(o); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { int oldSize = size; @@ -1071,7 +1071,7 @@ public boolean remove(@Nullable @UnknownSignedness Object o) { * the former contains an optimization that results in incorrect * behavior when c is a smaller "normal" (non-identity-based) Set. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { Objects.requireNonNull(c); @@ -1084,7 +1084,7 @@ public boolean removeAll(Collection c) { } return modified; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { IdentityHashMap.this.clear(); @@ -1179,7 +1179,7 @@ public Iterator iterator() { public boolean contains(@Nullable @UnknownSignedness Object o) { return containsValue(o); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { for (Iterator i = iterator(); i.hasNext(); ) { @@ -1190,7 +1190,7 @@ public boolean remove(@Nullable @UnknownSignedness Object o) { } return false; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { IdentityHashMap.this.clear(); @@ -1294,7 +1294,7 @@ public boolean contains(@Nullable @UnknownSignedness Object o) { return o instanceof Entry entry && containsMapping(entry.getKey(), entry.getValue()); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { return o instanceof Entry entry @@ -1304,7 +1304,7 @@ public boolean remove(@Nullable @UnknownSignedness Object o) { public @NonNegative int size() { return size; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { IdentityHashMap.this.clear(); @@ -1314,7 +1314,7 @@ public void clear() { * the former contains an optimization that results in incorrect * behavior when c is a smaller "normal" (non-identity-based) Set. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { Objects.requireNonNull(c); @@ -1504,7 +1504,7 @@ public void replaceAll(BiFunction function) { * {@code false}. */ @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(Object key, Object value) { return removeMapping(key, value); @@ -1520,7 +1520,7 @@ public boolean remove(Object key, Object value) { * otherwise it returns {@code false}. */ @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { Object k = maskNull(key); diff --git a/src/java.base/share/classes/java/util/ImmutableCollections.java b/src/java.base/share/classes/java/util/ImmutableCollections.java index 78f460363cbd3..559f30657d04a 100644 --- a/src/java.base/share/classes/java/util/ImmutableCollections.java +++ b/src/java.base/share/classes/java/util/ImmutableCollections.java @@ -34,7 +34,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.io.IOException; @@ -390,7 +390,7 @@ public boolean hasNext() { return cursor != size; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty ListItr this) { try { @@ -865,7 +865,7 @@ public boolean hasNext() { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @SuppressWarnings("unchecked") public E next(/*@NonEmpty Iterator this*/) { @@ -1004,7 +1004,7 @@ public boolean hasNext() { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty SetNIterator this) { if (remaining > 0) { @@ -1327,7 +1327,7 @@ public boolean hasNext() { return remaining > 0; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") private int nextIndex() { int idx = this.idx; diff --git a/src/java.base/share/classes/java/util/Iterator.java b/src/java.base/share/classes/java/util/Iterator.java index 04e99e4cedc45..912863723d88a 100644 --- a/src/java.base/share/classes/java/util/Iterator.java +++ b/src/java.base/share/classes/java/util/Iterator.java @@ -30,7 +30,7 @@ import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf; import org.checkerframework.checker.nonempty.qual.NonEmpty; import org.checkerframework.dataflow.qual.Pure; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; import org.checkerframework.framework.qual.Covariant; @@ -89,7 +89,7 @@ public interface Iterator { * @return the next element in the iteration * @throws NoSuchElementException if the iteration has no more elements */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E next(@GuardSatisfied @NonEmpty Iterator this); @@ -118,7 +118,7 @@ public interface Iterator { * been called after the last call to the {@code next} * method */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default void remove(@GuardSatisfied @CanShrink Iterator this) { throw new UnsupportedOperationException("remove"); diff --git a/src/java.base/share/classes/java/util/JumboEnumSet.java b/src/java.base/share/classes/java/util/JumboEnumSet.java index 3ed6211bf416f..d66a78539931b 100644 --- a/src/java.base/share/classes/java/util/JumboEnumSet.java +++ b/src/java.base/share/classes/java/util/JumboEnumSet.java @@ -37,7 +37,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.checker.index.qual.NonNegative; @@ -72,7 +72,7 @@ final class JumboEnumSet> extends EnumSet { elements = new long[(universe.length + 63) >>> 6]; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void addRange(E from, E to) { int fromIndex = from.ordinal() >>> 6; @@ -90,7 +90,7 @@ void addRange(E from, E to) { size = to.ordinal() - from.ordinal() + 1; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void addAll() { for (int i = 0; i < elements.length; i++) @@ -99,7 +99,7 @@ void addAll() { size = universe.length; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void complement() { for (int i = 0; i < elements.length; i++) @@ -159,7 +159,7 @@ public boolean hasNext() { @Override @SuppressWarnings("unchecked") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty EnumSetIterator this) { if (!hasNext()) @@ -172,7 +172,7 @@ public E next(@NonEmpty EnumSetIterator this) { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastReturned == 0) @@ -237,7 +237,7 @@ public boolean contains(@GuardSatisfied @Nullable @UnknownSignedness Object e) { * @throws NullPointerException if {@code e} is null */ @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { typeCheck(e); @@ -259,7 +259,7 @@ public boolean add(E e) { * @param e element to be removed from this set, if present * @return {@code true} if the set contained the specified element */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @Nullable @UnknownSignedness Object e) { if (e == null) @@ -311,7 +311,7 @@ public boolean containsAll(Collection c) { * @throws NullPointerException if the specified collection or any of * its elements are null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { if (!(c instanceof JumboEnumSet es)) @@ -338,7 +338,7 @@ public boolean addAll(Collection c) { * @return {@code true} if this set changed as a result of the call * @throws NullPointerException if the specified collection is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { if (!(c instanceof JumboEnumSet es)) @@ -360,7 +360,7 @@ public boolean removeAll(Collection c) { * @return {@code true} if this set changed as a result of the call * @throws NullPointerException if the specified collection is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { if (!(c instanceof JumboEnumSet es)) @@ -380,7 +380,7 @@ public boolean retainAll(Collection c) { /** * Removes all of the elements from this set. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { Arrays.fill(elements, 0); diff --git a/src/java.base/share/classes/java/util/LinkedHashMap.java b/src/java.base/share/classes/java/util/LinkedHashMap.java index 674c9a2ab3873..bae7f8b5d8a75 100644 --- a/src/java.base/share/classes/java/util/LinkedHashMap.java +++ b/src/java.base/share/classes/java/util/LinkedHashMap.java @@ -36,7 +36,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -405,7 +405,7 @@ void afterNodeAccess(Node e) { * * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putFirst(K k, V v) { try { @@ -424,7 +424,7 @@ public V putFirst(K k, V v) { * * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putLast(K k, V v) { try { @@ -578,7 +578,7 @@ public V getOrDefault(@Nullable Object key, V defaultValue) { /** * {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied LinkedHashMap this) { super.clear(); @@ -722,7 +722,7 @@ final class LinkedKeySet extends AbstractSet implements SequencedSet { LinkedKeySet(boolean reversed) { this.reversed = reversed; } @Pure public final int size() { return size; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void clear() { LinkedHashMap.this.clear(); } @SideEffectFree @@ -732,7 +732,7 @@ public final Iterator iterator() { @Pure @EnsuresNonEmptyIf(result = true, expression = "this") public final boolean contains(@Nullable @UnknownSignedness Object o) { return containsKey(o); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final boolean remove(@Nullable @UnknownSignedness Object key) { return removeNode(hash(key), key, null, false, true) != null; @@ -771,14 +771,14 @@ public final void forEach(Consumer action) { public final void addLast(K k) { throw new UnsupportedOperationException(); } public final K getFirst() { return nsee(reversed ? tail : head).key; } public final K getLast() { return nsee(reversed ? head : tail).key; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final K removeFirst() { var node = nsee(reversed ? tail : head); removeNode(node.hash, node.key, null, false, false); return node.key; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final K removeLast() { var node = nsee(reversed ? head : tail); @@ -844,7 +844,7 @@ final class LinkedValues extends AbstractCollection implements SequencedColle LinkedValues(boolean reversed) { this.reversed = reversed; } @Pure public final int size() { return size; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void clear() { LinkedHashMap.this.clear(); } @SideEffectFree @@ -887,14 +887,14 @@ public final void forEach(Consumer action) { public final void addLast(V v) { throw new UnsupportedOperationException(); } public final V getFirst() { return nsee(reversed ? tail : head).value; } public final V getLast() { return nsee(reversed ? head : tail).value; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final V removeFirst() { var node = nsee(reversed ? tail : head); removeNode(node.hash, node.key, null, false, false); return node.value; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final V removeLast() { var node = nsee(reversed ? head : tail); @@ -963,7 +963,7 @@ final class LinkedEntrySet extends AbstractSet> LinkedEntrySet(boolean reversed) { this.reversed = reversed; } @Pure public final int size() { return size; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void clear() { LinkedHashMap.this.clear(); } @SideEffectFree @@ -979,7 +979,7 @@ public final boolean contains(@Nullable @UnknownSignedness Object o) { Node candidate = getNode(key); return candidate != null && candidate.equals(e); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final boolean remove(@Nullable @UnknownSignedness Object o) { if (o instanceof Map.Entry e) { @@ -1020,14 +1020,14 @@ final Node nsee(Node e) { public final void addLast(Map.Entry e) { throw new UnsupportedOperationException(); } public final Map.Entry getFirst() { return nsee(reversed ? tail : head); } public final Map.Entry getLast() { return nsee(reversed ? head : tail); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final Map.Entry removeFirst() { var node = nsee(reversed ? tail : head); removeNode(node.hash, node.key, null, false, false); return node; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final Map.Entry removeLast() { var node = nsee(reversed ? head : tail); @@ -1088,7 +1088,7 @@ public final boolean hasNext() { return next != null; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") final LinkedHashMap.Entry nextNode(@NonEmpty LinkedHashIterator this) { LinkedHashMap.Entry e = next; if (modCount != expectedModCount) @@ -1100,7 +1100,7 @@ final LinkedHashMap.Entry nextNode(@NonEmpty LinkedHashIterator this) { return e; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void remove() { Node p = current; @@ -1117,7 +1117,7 @@ public final void remove() { final class LinkedKeyIterator extends LinkedHashIterator implements Iterator { LinkedKeyIterator(boolean reversed) { super(reversed); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final K next(@NonEmpty LinkedKeyIterator this) { return nextNode().getKey(); } } @@ -1125,7 +1125,7 @@ final class LinkedKeyIterator extends LinkedHashIterator final class LinkedValueIterator extends LinkedHashIterator implements Iterator { LinkedValueIterator(boolean reversed) { super(reversed); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final V next(@NonEmpty LinkedValueIterator this) { return nextNode().value; } } @@ -1133,7 +1133,7 @@ final class LinkedValueIterator extends LinkedHashIterator final class LinkedEntryIterator extends LinkedHashIterator implements Iterator> { LinkedEntryIterator(boolean reversed) { super(reversed); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final Map.Entry next(@NonEmpty LinkedEntryIterator this) { return nextNode(); } } @@ -1215,25 +1215,25 @@ public V get(Object key) { return base.get(key); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V put(K key, V value) { return base.put(key, value); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V remove(Object key) { return base.remove(key); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putAll(Map m) { base.putAll(m); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { base.clear(); @@ -1277,25 +1277,25 @@ public void replaceAll(BiFunction function) { throw new ConcurrentModificationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putIfAbsent(K key, V value) { return base.putIfAbsent(key, value); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(Object key, Object value) { return base.remove(key, value); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { return base.replace(key, oldValue, newValue); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { return base.replace(key, value); @@ -1335,25 +1335,25 @@ public Entry lastEntry() { return base.firstEntry(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Entry pollFirstEntry() { return base.pollLastEntry(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Entry pollLastEntry() { return base.pollFirstEntry(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putFirst(K k, V v) { return base.putLast(k, v); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putLast(K k, V v) { return base.putFirst(k, v); diff --git a/src/java.base/share/classes/java/util/LinkedHashSet.java b/src/java.base/share/classes/java/util/LinkedHashSet.java index ff58254266339..b87c6b391220a 100644 --- a/src/java.base/share/classes/java/util/LinkedHashSet.java +++ b/src/java.base/share/classes/java/util/LinkedHashSet.java @@ -210,7 +210,7 @@ public LinkedHashSet(Collection c) { * @since 1.8 */ @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Spliterator spliterator() { return Spliterators.spliterator(this, Spliterator.DISTINCT | Spliterator.ORDERED); @@ -249,7 +249,7 @@ LinkedHashMap map() { * * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { map().putFirst(e, PRESENT); @@ -263,7 +263,7 @@ public void addFirst(E e) { * * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { map().putLast(e, PRESENT); @@ -297,7 +297,7 @@ public E getLast() { * @throws NoSuchElementException {@inheritDoc} * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeFirst() { return map().sequencedKeySet().removeFirst(); @@ -309,7 +309,7 @@ public E removeFirst() { * @throws NoSuchElementException {@inheritDoc} * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeLast() { return map().sequencedKeySet().removeLast(); @@ -324,7 +324,7 @@ public E removeLast() { * @return {@inheritDoc} * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public SequencedSet reversed() { class ReverseLinkedHashSetView extends AbstractSet implements SequencedSet { diff --git a/src/java.base/share/classes/java/util/LinkedList.java b/src/java.base/share/classes/java/util/LinkedList.java index 77506ec454152..8b97ec19f8b2b 100644 --- a/src/java.base/share/classes/java/util/LinkedList.java +++ b/src/java.base/share/classes/java/util/LinkedList.java @@ -41,7 +41,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -298,7 +298,7 @@ public E getLast(@GuardSatisfied @NonEmpty LinkedList this) { * @return the first element from this list * @throws NoSuchElementException if this list is empty */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeFirst(@GuardSatisfied @NonEmpty @CanShrink LinkedList this) { final Node f = first; @@ -313,7 +313,7 @@ public E removeFirst(@GuardSatisfied @NonEmpty @CanShrink LinkedList this) { * @return the last element from this list * @throws NoSuchElementException if this list is empty */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeLast(@GuardSatisfied @NonEmpty @CanShrink LinkedList this) { final Node l = last; @@ -327,7 +327,7 @@ public E removeLast(@GuardSatisfied @NonEmpty @CanShrink LinkedList this) { * * @param e the element to add */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addFirst(@GuardSatisfied LinkedList this, E e) { linkFirst(e); @@ -340,7 +340,7 @@ public void addFirst(@GuardSatisfied LinkedList this, E e) { * * @param e the element to add */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addLast(@GuardSatisfied LinkedList this, E e) { linkLast(e); @@ -381,7 +381,7 @@ public boolean contains(@GuardSatisfied LinkedList this, @GuardSatisfied @Nul */ @ReleasesNoLocks @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(@GuardSatisfied LinkedList this, E e) { linkLast(e); @@ -402,7 +402,7 @@ public boolean add(@GuardSatisfied LinkedList this, E e) { * @return {@code true} if this list contained the specified element */ @ReleasesNoLocks - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @CanShrink LinkedList this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { if (o == null) { @@ -435,7 +435,7 @@ public boolean remove(@GuardSatisfied @CanShrink LinkedList this, @GuardSatis * @return {@code true} if this list changed as a result of the call * @throws NullPointerException if the specified collection is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@GuardSatisfied LinkedList this, Collection c) { return addAll(size, c); @@ -456,7 +456,7 @@ public boolean addAll(@GuardSatisfied LinkedList this, Collection this, @NonNegative int index, Collection c) { checkPositionIndex(index); @@ -501,7 +501,7 @@ public boolean addAll(@GuardSatisfied LinkedList this, @NonNegative int index * Removes all of the elements from this list. * The list will be empty after this call returns. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink LinkedList this) { // Clearing all of the links between nodes is "unnecessary", but: @@ -545,7 +545,7 @@ public E get(@GuardSatisfied LinkedList this, @NonNegative int index) { * @return the element previously at the specified position * @throws IndexOutOfBoundsException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E set(@GuardSatisfied LinkedList this, @NonNegative int index, E element) { checkElementIndex(index); @@ -564,7 +564,7 @@ public E set(@GuardSatisfied LinkedList this, @NonNegative int index, E eleme * @param element element to be inserted * @throws IndexOutOfBoundsException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(@GuardSatisfied LinkedList this, @NonNegative int index, E element) { checkPositionIndex(index); @@ -584,7 +584,7 @@ public void add(@GuardSatisfied LinkedList this, @NonNegative int index, E el * @return the element previously at the specified position * @throws IndexOutOfBoundsException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @CanShrink LinkedList this, @NonNegative int index) { checkElementIndex(index); @@ -737,7 +737,7 @@ public E element(@GuardSatisfied @NonEmpty LinkedList this) { * @return the head of this list, or {@code null} if this list is empty * @since 1.5 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink LinkedList this) { final Node f = first; @@ -751,7 +751,7 @@ public E element(@GuardSatisfied @NonEmpty LinkedList this) { * @throws NoSuchElementException if this list is empty * @since 1.5 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @NonEmpty @CanShrink LinkedList this) { return removeFirst(); @@ -764,7 +764,7 @@ public E remove(@GuardSatisfied @NonEmpty @CanShrink LinkedList this) { * @return {@code true} (as specified by {@link Queue#offer}) * @since 1.5 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { return add(e); @@ -778,7 +778,7 @@ public boolean offer(E e) { * @return {@code true} (as specified by {@link Deque#offerFirst}) * @since 1.6 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offerFirst(E e) { addFirst(e); @@ -792,7 +792,7 @@ public boolean offerFirst(E e) { * @return {@code true} (as specified by {@link Deque#offerLast}) * @since 1.6 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offerLast(E e) { addLast(e); @@ -835,7 +835,7 @@ public boolean offerLast(E e) { * this list is empty * @since 1.6 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollFirst(@GuardSatisfied @CanShrink LinkedList this) { final Node f = first; @@ -850,7 +850,7 @@ public boolean offerLast(E e) { * this list is empty * @since 1.6 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollLast(@GuardSatisfied @CanShrink LinkedList this) { final Node l = last; @@ -866,7 +866,7 @@ public boolean offerLast(E e) { * @param e the element to push * @since 1.6 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void push(@GuardSatisfied LinkedList this, E e) { addFirst(e); @@ -883,7 +883,7 @@ public void push(@GuardSatisfied LinkedList this, E e) { * @throws NoSuchElementException if this list is empty * @since 1.6 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E pop(@GuardSatisfied @NonEmpty @CanShrink LinkedList this) { return removeFirst(); @@ -898,7 +898,7 @@ public E pop(@GuardSatisfied @NonEmpty @CanShrink LinkedList this) { * @return {@code true} if the list contained the specified element * @since 1.6 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeFirstOccurrence(@GuardSatisfied @CanShrink LinkedList this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { return remove(o); @@ -913,7 +913,7 @@ public boolean removeFirstOccurrence(@GuardSatisfied @CanShrink LinkedList th * @return {@code true} if the list contained the specified element * @since 1.6 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeLastOccurrence(@GuardSatisfied @CanShrink LinkedList this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { if (o == null) { @@ -978,7 +978,7 @@ public boolean hasNext() { return nextIndex < size; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty ListItr this) { checkForComodification(); @@ -995,7 +995,7 @@ public boolean hasPrevious() { return nextIndex > 0; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E previous() { checkForComodification(); @@ -1015,7 +1015,7 @@ public int previousIndex() { return nextIndex - 1; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { checkForComodification(); @@ -1032,7 +1032,7 @@ public void remove() { expectedModCount++; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void set(E e) { if (lastReturned == null) @@ -1041,7 +1041,7 @@ public void set(E e) { lastReturned.item = e; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(E e) { checkForComodification(); @@ -1100,12 +1100,12 @@ private class DescendingIterator implements Iterator { public boolean hasNext() { return itr.hasPrevious(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty DescendingIterator this) { return itr.previous(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { itr.remove(); @@ -1407,13 +1407,13 @@ public String toString() { return rlist.toString(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { return rlist.retainAll(c); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { return rlist.removeAll(c); @@ -1435,7 +1435,7 @@ public Stream stream() { return rlist.stream(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { return rlist.removeIf(filter); @@ -1469,7 +1469,7 @@ public ListIterator listIterator() { return rlist.listIterator(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void sort(Comparator c) { rlist.sort(c); @@ -1504,37 +1504,37 @@ public ListIterator listIterator(int index) { return rlist.listIterator(index); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeLastOccurrence(Object o) { return rdeque.removeLastOccurrence(o); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeFirstOccurrence(Object o) { return rdeque.removeFirstOccurrence(o); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E pop() { return rdeque.pop(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void push(E e) { rdeque.push(e); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E pollLast() { return rdeque.pollLast(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E pollFirst() { return rdeque.pollFirst(); @@ -1548,31 +1548,31 @@ public E peekFirst() { return rdeque.peekFirst(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offerLast(E e) { return rdeque.offerLast(e); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offerFirst(E e) { return rdeque.offerFirst(e); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { return rdeque.offer(e); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove() { return rdeque.remove(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E poll() { return rdeque.poll(); @@ -1594,19 +1594,19 @@ public int indexOf(Object o) { return rlist.indexOf(o); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(int index) { return rlist.remove(index); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(int index, E element) { rlist.add(index, element); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E set(int index, E element) { return rlist.set(index, element); @@ -1616,31 +1616,31 @@ public E get(int index) { return rlist.get(index); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { rlist.clear(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(int index, Collection c) { return rlist.addAll(index, c); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { return rlist.addAll(c); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(Object o) { return rlist.remove(o); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { return rlist.add(e); @@ -1654,25 +1654,25 @@ public boolean contains(Object o) { return rlist.contains(o); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { rdeque.addLast(e); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { rdeque.addFirst(e); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeLast() { return rdeque.removeLast(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeFirst() { return rdeque.removeFirst(); diff --git a/src/java.base/share/classes/java/util/List.java b/src/java.base/share/classes/java/util/List.java index 5c19bb1750b9f..56524e6e35d08 100644 --- a/src/java.base/share/classes/java/util/List.java +++ b/src/java.base/share/classes/java/util/List.java @@ -43,7 +43,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -299,7 +299,7 @@ public interface List extends SequencedCollection { * prevents it from being added to this list */ @ReleasesNoLocks - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresNonEmpty("this") boolean add(@GuardSatisfied List this, E e); @@ -325,7 +325,7 @@ public interface List extends SequencedCollection { * @throws UnsupportedOperationException if the {@code remove} operation * is not supported by this list */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean remove(@GuardSatisfied @CanShrink List this, @UnknownSignedness Object o); @@ -374,7 +374,7 @@ public interface List extends SequencedCollection { * specified collection prevents it from being added to this list * @see #add(Object) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresNonEmptyIf(result = true, expression = "this") boolean addAll(@GuardSatisfied List this, Collection c); @@ -406,7 +406,7 @@ public interface List extends SequencedCollection { * @throws IndexOutOfBoundsException if the index is out of range * ({@code index < 0 || index > size()}) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresNonEmptyIf(result = true, expression = "this") boolean addAll(@GuardSatisfied List this, @IndexOrHigh({"this"}) int index, Collection c); @@ -429,7 +429,7 @@ public interface List extends SequencedCollection { * @see #remove(Object) * @see #contains(Object) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean removeAll(@GuardSatisfied @CanShrink List this, Collection c); @@ -453,7 +453,7 @@ public interface List extends SequencedCollection { * @see #remove(Object) * @see #contains(Object) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean retainAll(@GuardSatisfied @CanShrink List this, Collection c); @@ -554,7 +554,7 @@ default void replaceAll(UnaryOperator operator) { * @since 1.8 */ @SuppressWarnings({"unchecked", "rawtypes"}) - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default void sort(Comparator c) { Object[] a = this.toArray(); @@ -573,7 +573,7 @@ default void sort(Comparator c) { * @throws UnsupportedOperationException if the {@code clear} operation * is not supported by this list */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void clear(@GuardSatisfied @CanShrink List this); @@ -649,7 +649,7 @@ default void sort(Comparator c) { * @throws IndexOutOfBoundsException if the index is out of range * ({@code index < 0 || index >= size()}) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E set(@GuardSatisfied List this, @IndexFor({"this"}) int index, E element); @@ -673,7 +673,7 @@ default void sort(Comparator c) { * ({@code index < 0 || index > size()}) */ @ReleasesNoLocks - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void add(@GuardSatisfied List this, @IndexOrHigh({"this"}) int index, E element); @@ -691,7 +691,7 @@ default void sort(Comparator c) { * ({@code index < 0 || index >= size()}) */ @ReleasesNoLocks - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E remove(@GuardSatisfied @CanShrink List this, @IndexFor({"this"}) int index); @@ -861,7 +861,7 @@ default Spliterator spliterator() { * @throws UnsupportedOperationException {@inheritDoc} * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default void addFirst(E e) { this.add(0, e); @@ -877,7 +877,7 @@ default void addFirst(E e) { * @throws UnsupportedOperationException {@inheritDoc} * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default void addLast(E e) { this.add(e); @@ -932,7 +932,7 @@ default E getLast() { * @throws UnsupportedOperationException {@inheritDoc} * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default E removeFirst() { if (this.isEmpty()) { @@ -953,7 +953,7 @@ default E removeFirst() { * @throws UnsupportedOperationException {@inheritDoc} * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default E removeLast() { if (this.isEmpty()) { diff --git a/src/java.base/share/classes/java/util/ListIterator.java b/src/java.base/share/classes/java/util/ListIterator.java index 83bf5f586c182..ec6b6e863346c 100644 --- a/src/java.base/share/classes/java/util/ListIterator.java +++ b/src/java.base/share/classes/java/util/ListIterator.java @@ -31,7 +31,7 @@ import org.checkerframework.checker.nonempty.qual.EnsuresNonEmptyIf; import org.checkerframework.checker.nonempty.qual.NonEmpty; import org.checkerframework.dataflow.qual.Pure; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -97,7 +97,7 @@ public interface ListIterator extends Iterator { * @return the next element in the list * @throws NoSuchElementException if the iteration has no next element */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E next(@GuardSatisfied @NonEmpty ListIterator this); @@ -125,7 +125,7 @@ public interface ListIterator extends Iterator { * @throws NoSuchElementException if the iteration has no previous * element */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E previous(@GuardSatisfied ListIterator this); @@ -170,7 +170,7 @@ public interface ListIterator extends Iterator { * {@code add} have been called after the last call to * {@code next} or {@code previous} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void remove(@GuardSatisfied ListIterator this); @@ -194,7 +194,7 @@ public interface ListIterator extends Iterator { * {@code add} have been called after the last call to * {@code next} or {@code previous} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void set(@GuardSatisfied ListIterator this, E e); @@ -218,7 +218,7 @@ public interface ListIterator extends Iterator { * @throws IllegalArgumentException if some aspect of this element * prevents it from being added to this list */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void add(@GuardSatisfied ListIterator this, E e); } diff --git a/src/java.base/share/classes/java/util/Map.java b/src/java.base/share/classes/java/util/Map.java index 794bcaaf2b441..6249e66a0e1f9 100644 --- a/src/java.base/share/classes/java/util/Map.java +++ b/src/java.base/share/classes/java/util/Map.java @@ -303,7 +303,7 @@ public interface Map { @ReleasesNoLocks @EnsuresKeyFor(value={"#1"}, map={"this"}) @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable V put(@GuardSatisfied Map this, K key, V value); @@ -336,7 +336,7 @@ public interface Map { * map does not permit null keys ({@linkplain Collection##optional-restrictions optional}) */ @CFComment("nullness: key is not @Nullable because this map might not permit null values") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable V remove(@GuardSatisfied Map this, @GuardSatisfied @UnknownSignedness Object key); @@ -364,7 +364,7 @@ public interface Map { * @throws IllegalArgumentException if some property of a key or value in * the specified map prevents it from being stored in this map */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void putAll(@GuardSatisfied Map this, Map m); @@ -375,7 +375,7 @@ public interface Map { * @throws UnsupportedOperationException if the {@code clear} operation * is not supported by this map */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void clear(@GuardSatisfied Map this); @@ -541,7 +541,7 @@ interface Entry { * required to, throw this exception if the entry has been * removed from the backing map. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") V setValue(Map.@GuardSatisfied Entry this, V value); @@ -898,7 +898,7 @@ default void replaceAll(BiFunction function) * @since 1.8 */ @EnsuresKeyFor(value={"#1"}, map={"this"}) - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default @Nullable V putIfAbsent(K key, V value) { V v = get(key); @@ -944,7 +944,7 @@ default void replaceAll(BiFunction function) * @since 1.8 */ @CFComment("nullness: key and value are not @Nullable because this map might not permit null values") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default boolean remove(@GuardSatisfied @UnknownSignedness Object key, @GuardSatisfied @UnknownSignedness Object value) { Object curValue = get(key); @@ -996,7 +996,7 @@ default boolean remove(@GuardSatisfied @UnknownSignedness Object key, @GuardSati * or value prevents it from being stored in this map * @since 1.8 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default boolean replace(K key, V oldValue, V newValue) { Object curValue = get(key); @@ -1046,7 +1046,7 @@ default boolean replace(K key, V oldValue, V newValue) { * or value prevents it from being stored in this map * @since 1.8 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default @Nullable V replace(K key, V value) { V curValue; diff --git a/src/java.base/share/classes/java/util/NavigableMap.java b/src/java.base/share/classes/java/util/NavigableMap.java index a2501ee26b397..12653e7153764 100644 --- a/src/java.base/share/classes/java/util/NavigableMap.java +++ b/src/java.base/share/classes/java/util/NavigableMap.java @@ -252,7 +252,7 @@ public interface NavigableMap extends SortedMap { * @return the removed first entry of this map, * or {@code null} if this map is empty */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") Map.@Nullable Entry pollFirstEntry(@GuardSatisfied NavigableMap this); @@ -263,7 +263,7 @@ public interface NavigableMap extends SortedMap { * @return the removed last entry of this map, * or {@code null} if this map is empty */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") Map.@Nullable Entry pollLastEntry(@GuardSatisfied NavigableMap this); diff --git a/src/java.base/share/classes/java/util/NavigableSet.java b/src/java.base/share/classes/java/util/NavigableSet.java index 170ffdb1b0ddf..fd6b8d14e497f 100644 --- a/src/java.base/share/classes/java/util/NavigableSet.java +++ b/src/java.base/share/classes/java/util/NavigableSet.java @@ -161,7 +161,7 @@ public interface NavigableSet extends SortedSet { * * @return the first element, or {@code null} if this set is empty */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E pollFirst(@GuardSatisfied NavigableSet this); @@ -171,7 +171,7 @@ public interface NavigableSet extends SortedSet { * * @return the last element, or {@code null} if this set is empty */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E pollLast(@GuardSatisfied NavigableSet this); @@ -198,7 +198,7 @@ public interface NavigableSet extends SortedSet { * * @return a reverse order view of this set */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") NavigableSet descendingSet(); @@ -208,7 +208,7 @@ public interface NavigableSet extends SortedSet { * * @return an iterator over the elements in this set, in descending order */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") Iterator descendingIterator(); @@ -358,7 +358,7 @@ NavigableSet subSet(@GuardSatisfied NavigableSet this, @GuardSatisfied E f * @throws UnsupportedOperationException {@inheritDoc} * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default E removeFirst() { if (this.isEmpty()) { @@ -379,7 +379,7 @@ default E removeFirst() { * @throws UnsupportedOperationException {@inheritDoc} * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default E removeLast() { if (this.isEmpty()) { @@ -401,7 +401,7 @@ default E removeLast() { * @return a reverse-ordered view of this collection, as a {@code NavigableSet} * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default NavigableSet reversed() { return this.descendingSet(); diff --git a/src/java.base/share/classes/java/util/PrimitiveIterator.java b/src/java.base/share/classes/java/util/PrimitiveIterator.java index 58c31aa7d44a7..61ead18c6991d 100644 --- a/src/java.base/share/classes/java/util/PrimitiveIterator.java +++ b/src/java.base/share/classes/java/util/PrimitiveIterator.java @@ -107,7 +107,7 @@ public static interface OfInt extends PrimitiveIterator { * @return the next {@code int} element in the iteration * @throws NoSuchElementException if the iteration has no more elements */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") int nextInt(@NonEmpty OfInt this); @@ -134,7 +134,7 @@ default void forEachRemaining(IntConsumer action) { * {@link #nextInt()}, and returns that boxed result. */ @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default Integer next(PrimitiveIterator.@GuardSatisfied OfInt this) { if (Tripwire.ENABLED) @@ -181,7 +181,7 @@ public static interface OfLong extends PrimitiveIterator { * @return the next {@code long} element in the iteration * @throws NoSuchElementException if the iteration has no more elements */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") long nextLong(@NonEmpty OfLong this); @@ -208,7 +208,7 @@ default void forEachRemaining(LongConsumer action) { * {@link #nextLong()}, and returns that boxed result. */ @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default Long next(PrimitiveIterator.@GuardSatisfied OfLong this) { if (Tripwire.ENABLED) @@ -254,7 +254,7 @@ public static interface OfDouble extends PrimitiveIterator this, E e) { return offer(e); @@ -346,7 +346,7 @@ public boolean add(@GuardSatisfied PriorityQueue this, E e) { * according to the priority queue's ordering * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { if (e == null) @@ -386,7 +386,7 @@ private int indexOf(@GuardSatisfied @Nullable @UnknownSignedness Object o) { * @param o element to be removed from this queue, if present * @return {@code true} if this queue changed as a result of the call */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @CanShrink PriorityQueue this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { int i = indexOf(o); @@ -553,7 +553,7 @@ public boolean hasNext() { (forgetMeNot != null && !forgetMeNot.isEmpty()); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty Itr this) { if (expectedModCount != modCount) @@ -569,7 +569,7 @@ public E next(@NonEmpty Itr this) { throw new NoSuchElementException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (expectedModCount != modCount) @@ -603,7 +603,7 @@ public void remove() { * Removes all of the elements from this priority queue. * The queue will be empty after this call returns. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink PriorityQueue this) { modCount++; @@ -613,7 +613,7 @@ public void clear(@GuardSatisfied @CanShrink PriorityQueue this) { size = 0; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink PriorityQueue this) { final Object[] es; @@ -938,7 +938,7 @@ public int characteristics() { /** * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@GuardSatisfied @CanShrink PriorityQueue this, Predicate filter) { Objects.requireNonNull(filter); @@ -948,7 +948,7 @@ public boolean removeIf(@GuardSatisfied @CanShrink PriorityQueue this, Predic /** * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(@GuardSatisfied @CanShrink PriorityQueue this, Collection c) { Objects.requireNonNull(c); @@ -958,7 +958,7 @@ public boolean removeAll(@GuardSatisfied @CanShrink PriorityQueue this, Colle /** * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(@GuardSatisfied @CanShrink PriorityQueue this, Collection c) { Objects.requireNonNull(c); diff --git a/src/java.base/share/classes/java/util/Properties.java b/src/java.base/share/classes/java/util/Properties.java index 4e79a37752023..a877b1a0cdc4a 100644 --- a/src/java.base/share/classes/java/util/Properties.java +++ b/src/java.base/share/classes/java/util/Properties.java @@ -239,7 +239,7 @@ private Properties(Properties defaults, int initialCapacity) { * @see #getProperty * @since 1.2 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized @Nullable Object setProperty(@GuardSatisfied Properties this, @PropertyKey String key, String value) { return put(key, value); @@ -1366,28 +1366,28 @@ public boolean containsKey(@GuardSatisfied @Nullable @UnknownSignedness Object k } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized Object put(Object key, Object value) { return map.put(key, value); } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized Object remove(@GuardSatisfied @Nullable @UnknownSignedness Object key) { return map.remove(key); } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized void putAll(Map t) { map.putAll(t); } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized void clear() { map.clear(); @@ -1435,10 +1435,10 @@ private EntrySet(Set> entrySet) { @Override public boolean contains(@UnknownSignedness Object o) { return entrySet.contains(o); } @Override public Object[] toArray() { return entrySet.toArray(); } @Override public @Nullable T[] toArray(@PolyNull T[] a) { return entrySet.toArray(a); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Override public void clear() { entrySet.clear(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Override public boolean remove(@UnknownSignedness Object o) { return entrySet.remove(o); } @@ -1474,14 +1474,14 @@ public String toString() { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { return entrySet.removeAll(c); } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { return entrySet.retainAll(c); @@ -1522,35 +1522,35 @@ public synchronized void replaceAll(BiFunction mappingFunction) { @@ -1558,7 +1558,7 @@ public synchronized Object replace(Object key, Object value) { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized @PolyNull Object computeIfPresent(Object key, BiFunction remappingFunction) { @@ -1566,7 +1566,7 @@ public synchronized Object replace(Object key, Object value) { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized @PolyNull Object compute(Object key, BiFunction remappingFunction) { diff --git a/src/java.base/share/classes/java/util/Queue.java b/src/java.base/share/classes/java/util/Queue.java index 0ba979fe5b785..f27b0261692b0 100644 --- a/src/java.base/share/classes/java/util/Queue.java +++ b/src/java.base/share/classes/java/util/Queue.java @@ -167,7 +167,7 @@ public interface Queue extends Collection { * prevents it from being added to this queue */ @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean add(@GuardSatisfied Queue this, E e); @@ -188,7 +188,7 @@ public interface Queue extends Collection { * @throws IllegalArgumentException if some property of this element * prevents it from being added to this queue */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean offer(E e); @@ -200,7 +200,7 @@ public interface Queue extends Collection { * @return the head of this queue * @throws NoSuchElementException if this queue is empty */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E remove(@GuardSatisfied @NonEmpty @CanShrink Queue this); @@ -210,7 +210,7 @@ public interface Queue extends Collection { * * @return the head of this queue, or {@code null} if this queue is empty */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E poll(@GuardSatisfied @CanShrink Queue this); @@ -230,7 +230,7 @@ public interface Queue extends Collection { * * @return the head of this queue, or {@code null} if this queue is empty */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E peek(); } diff --git a/src/java.base/share/classes/java/util/RegularEnumSet.java b/src/java.base/share/classes/java/util/RegularEnumSet.java index 9ecfbde70a4cd..caa15d17f8579 100644 --- a/src/java.base/share/classes/java/util/RegularEnumSet.java +++ b/src/java.base/share/classes/java/util/RegularEnumSet.java @@ -38,7 +38,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -64,20 +64,20 @@ final class RegularEnumSet> extends EnumSet { super(elementType, universe); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void addRange(E from, E to) { elements = (-1L >>> (from.ordinal() - to.ordinal() - 1)) << from.ordinal(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void addAll() { if (universe.length != 0) elements = -1L >>> -universe.length; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void complement() { if (universe.length != 0) { @@ -124,7 +124,7 @@ public boolean hasNext() { return unseen != 0; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @SuppressWarnings("unchecked") public E next(@NonEmpty EnumSetIterator this) { @@ -135,7 +135,7 @@ public E next(@NonEmpty EnumSetIterator this) { return (E) universe[Long.numberOfTrailingZeros(lastReturned)]; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastReturned == 0) @@ -195,7 +195,7 @@ public boolean contains(@GuardSatisfied @Nullable @UnknownSignedness Object e) { * @throws NullPointerException if {@code e} is null */ @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { typeCheck(e); @@ -211,7 +211,7 @@ public boolean add(E e) { * @param e element to be removed from this set, if present * @return {@code true} if the set contained the specified element */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @Nullable @UnknownSignedness Object e) { if (e == null) @@ -255,7 +255,7 @@ public boolean containsAll(Collection c) { * @throws NullPointerException if the specified collection or any * of its elements are null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { if (!(c instanceof RegularEnumSet es)) @@ -282,7 +282,7 @@ public boolean addAll(Collection c) { * @return {@code true} if this set changed as a result of the call * @throws NullPointerException if the specified collection is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { if (!(c instanceof RegularEnumSet es)) @@ -304,7 +304,7 @@ public boolean removeAll(Collection c) { * @return {@code true} if this set changed as a result of the call * @throws NullPointerException if the specified collection is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { if (!(c instanceof RegularEnumSet es)) @@ -324,7 +324,7 @@ public boolean retainAll(Collection c) { /** * Removes all of the elements from this set. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { elements = 0; diff --git a/src/java.base/share/classes/java/util/Scanner.java b/src/java.base/share/classes/java/util/Scanner.java index 6d70a6e416fb4..2d030b467120a 100644 --- a/src/java.base/share/classes/java/util/Scanner.java +++ b/src/java.base/share/classes/java/util/Scanner.java @@ -39,7 +39,7 @@ import org.checkerframework.common.value.qual.IntRange; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -1491,7 +1491,7 @@ public boolean hasNext(@GuardSatisfied Scanner this) { * @throws IllegalStateException if this scanner is closed * @see java.util.Iterator */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public String next(@GuardSatisfied @NonEmpty Scanner this) { ensureOpen(); @@ -1518,7 +1518,7 @@ public String next(@GuardSatisfied @NonEmpty Scanner this) { * @throws UnsupportedOperationException if this method is invoked. * @see java.util.Iterator */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove(@GuardSatisfied Scanner this) { throw new UnsupportedOperationException(); @@ -1557,7 +1557,7 @@ public boolean hasNext(@GuardSatisfied Scanner this, String pattern) { * @throws NoSuchElementException if no such tokens are available * @throws IllegalStateException if this scanner is closed */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public String next(@GuardSatisfied @NonEmpty Scanner this, String pattern) { return next(patternCache.forName(pattern)); @@ -1609,7 +1609,7 @@ public boolean hasNext(@GuardSatisfied Scanner this, Pattern pattern) { * @throws NoSuchElementException if no more tokens are available * @throws IllegalStateException if this scanner is closed */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public String next(@GuardSatisfied @NonEmpty Scanner this, Pattern pattern) { ensureOpen(); @@ -1684,7 +1684,7 @@ public boolean hasNextLine() { * @throws NoSuchElementException if no line was found * @throws IllegalStateException if this scanner is closed */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public String nextLine(@GuardSatisfied @NonEmpty Scanner this) { modCount++; if (hasNextPattern == linePattern()) @@ -1934,7 +1934,7 @@ public boolean hasNextBoolean(@GuardSatisfied Scanner this) { * @throws NoSuchElementException if input is exhausted * @throws IllegalStateException if this scanner is closed */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public boolean nextBoolean(@GuardSatisfied @NonEmpty Scanner this) { clearCaches(); return Boolean.parseBoolean(next(boolPattern())); @@ -2001,7 +2001,7 @@ public boolean hasNextByte(@GuardSatisfied Scanner this, @Positive @IntRange(fro * @throws NoSuchElementException if input is exhausted * @throws IllegalStateException if this scanner is closed */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public @PolySigned byte nextByte(@GuardSatisfied @NonEmpty Scanner this) { return nextByte(defaultRadix); } @@ -2037,7 +2037,7 @@ public boolean hasNextByte(@GuardSatisfied Scanner this, @Positive @IntRange(fro * @throws IllegalStateException if this scanner is closed * @throws IllegalArgumentException if the radix is out of range */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public @PolySigned byte nextByte(@GuardSatisfied @NonEmpty Scanner this, @Positive @IntRange(from = 2, to = 36) int radix) { // Check cached result if ((typeCache != null) && (typeCache instanceof Byte) @@ -2121,7 +2121,7 @@ public boolean hasNextShort(@GuardSatisfied Scanner this, @Positive @IntRange(fr * @throws NoSuchElementException if input is exhausted * @throws IllegalStateException if this scanner is closed */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public @PolySigned short nextShort(@GuardSatisfied @NonEmpty Scanner this) { return nextShort(defaultRadix); } @@ -2157,7 +2157,7 @@ public boolean hasNextShort(@GuardSatisfied Scanner this, @Positive @IntRange(fr * @throws IllegalStateException if this scanner is closed * @throws IllegalArgumentException if the radix is out of range */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public @PolySigned short nextShort(@GuardSatisfied @NonEmpty Scanner this, @Positive @IntRange(from = 2, to = 36) int radix) { // Check cached result if ((typeCache != null) && (typeCache instanceof Short) @@ -2265,7 +2265,7 @@ private String processIntegerToken(String token) { * @throws NoSuchElementException if input is exhausted * @throws IllegalStateException if this scanner is closed */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public @PolySigned int nextInt(@GuardSatisfied @NonEmpty Scanner this) { return nextInt(defaultRadix); } @@ -2301,7 +2301,7 @@ private String processIntegerToken(String token) { * @throws IllegalStateException if this scanner is closed * @throws IllegalArgumentException if the radix is out of range */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public @PolySigned int nextInt(@GuardSatisfied @NonEmpty Scanner this, @Positive @IntRange(from = 2, to = 36) int radix) { // Check cached result if ((typeCache != null) && (typeCache instanceof Integer) @@ -2385,7 +2385,7 @@ public boolean hasNextLong(@GuardSatisfied Scanner this, @Positive @IntRange(fro * @throws NoSuchElementException if input is exhausted * @throws IllegalStateException if this scanner is closed */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public @PolySigned long nextLong(@GuardSatisfied @NonEmpty Scanner this) { return nextLong(defaultRadix); } @@ -2421,7 +2421,7 @@ public boolean hasNextLong(@GuardSatisfied Scanner this, @Positive @IntRange(fro * @throws IllegalStateException if this scanner is closed * @throws IllegalArgumentException if the radix is out of range */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public @PolySigned long nextLong(@GuardSatisfied @NonEmpty Scanner this, @Positive @IntRange(from = 2, to = 36) int radix) { // Check cached result if ((typeCache != null) && (typeCache instanceof Long) @@ -2547,7 +2547,7 @@ public boolean hasNextFloat(@GuardSatisfied Scanner this) { * @throws NoSuchElementException if input is exhausted * @throws IllegalStateException if this scanner is closed */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public float nextFloat(@GuardSatisfied @NonEmpty Scanner this) { // Check cached result if ((typeCache != null) && (typeCache instanceof Float)) { @@ -2616,7 +2616,7 @@ public boolean hasNextDouble(@GuardSatisfied Scanner this) { * @throws NoSuchElementException if the input is exhausted * @throws IllegalStateException if this scanner is closed */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public double nextDouble(@GuardSatisfied @NonEmpty Scanner this) { // Check cached result if ((typeCache != null) && (typeCache instanceof Double)) { @@ -2701,7 +2701,7 @@ public boolean hasNextBigInteger(@GuardSatisfied Scanner this, @IntRange(from = * @throws NoSuchElementException if the input is exhausted * @throws IllegalStateException if this scanner is closed */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public BigInteger nextBigInteger(@GuardSatisfied @NonEmpty Scanner this) { return nextBigInteger(defaultRadix); } @@ -2732,7 +2732,7 @@ public BigInteger nextBigInteger(@GuardSatisfied @NonEmpty Scanner this) { * @throws IllegalStateException if this scanner is closed * @throws IllegalArgumentException if the radix is out of range */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public BigInteger nextBigInteger(@GuardSatisfied @NonEmpty Scanner this, @IntRange(from = 2, to = 36) int radix) { // Check cached result if ((typeCache != null) && (typeCache instanceof BigInteger val) @@ -2799,7 +2799,7 @@ public boolean hasNextBigDecimal(@GuardSatisfied Scanner this) { * @throws NoSuchElementException if the input is exhausted * @throws IllegalStateException if this scanner is closed */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public BigDecimal nextBigDecimal(@GuardSatisfied @NonEmpty Scanner this) { // Check cached result if ((typeCache != null) && (typeCache instanceof BigDecimal val)) { diff --git a/src/java.base/share/classes/java/util/SequencedCollection.java b/src/java.base/share/classes/java/util/SequencedCollection.java index 5f208d9701866..a08d233155f0e 100644 --- a/src/java.base/share/classes/java/util/SequencedCollection.java +++ b/src/java.base/share/classes/java/util/SequencedCollection.java @@ -89,7 +89,7 @@ public interface SequencedCollection extends Collection { * * @return a reverse-ordered view of this collection */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") SequencedCollection reversed(); @@ -107,7 +107,7 @@ public interface SequencedCollection extends Collection { * @throws UnsupportedOperationException if this collection implementation * does not support this operation */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default void addFirst(E e) { throw new UnsupportedOperationException(); @@ -127,7 +127,7 @@ default void addFirst(E e) { * @throws UnsupportedOperationException if this collection implementation * does not support this operation */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default void addLast(E e) { throw new UnsupportedOperationException(); @@ -180,7 +180,7 @@ default E getLast() { * @throws UnsupportedOperationException if this collection implementation * does not support this operation */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default E removeFirst() { var it = this.iterator(); @@ -204,7 +204,7 @@ default E removeFirst() { * @throws UnsupportedOperationException if this collection implementation * does not support this operation */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default E removeLast() { var it = this.reversed().iterator(); diff --git a/src/java.base/share/classes/java/util/SequencedMap.java b/src/java.base/share/classes/java/util/SequencedMap.java index cae0db2912404..3933603e15c6f 100644 --- a/src/java.base/share/classes/java/util/SequencedMap.java +++ b/src/java.base/share/classes/java/util/SequencedMap.java @@ -136,7 +136,7 @@ public interface SequencedMap extends Map { * * @return a reverse-ordered view of this map */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") SequencedMap reversed(); @@ -188,7 +188,7 @@ default Map.Entry lastEntry() { * @throws UnsupportedOperationException if this collection implementation does not * support this operation */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default Map.Entry pollFirstEntry() { var it = entrySet().iterator(); @@ -215,7 +215,7 @@ default Map.Entry pollFirstEntry() { * @throws UnsupportedOperationException if this collection implementation does not * support this operation */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default Map.Entry pollLastEntry() { var it = reversed().entrySet().iterator(); @@ -243,7 +243,7 @@ default Map.Entry pollLastEntry() { * @throws UnsupportedOperationException if this collection implementation does not * support this operation */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default V putFirst(K k, V v) { throw new UnsupportedOperationException(); @@ -264,7 +264,7 @@ default V putFirst(K k, V v) { * @throws UnsupportedOperationException if this collection implementation does not * support this operation */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default V putLast(K k, V v) { throw new UnsupportedOperationException(); @@ -284,7 +284,7 @@ default V putLast(K k, V v) { * * @return a {@code SequencedSet} view of this map's {@code keySet} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default SequencedSet sequencedKeySet() { class SeqKeySet extends AbstractMap.ViewCollection implements SequencedSet { @@ -319,7 +319,7 @@ public int hashCode() { * * @return a {@code SequencedCollection} view of this map's {@code values} collection */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default SequencedCollection sequencedValues() { class SeqValues extends AbstractMap.ViewCollection implements SequencedCollection { @@ -347,7 +347,7 @@ public SequencedCollection reversed() { * * @return a {@code SequencedSet} view of this map's {@code entrySet} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default SequencedSet> sequencedEntrySet() { class SeqEntrySet extends AbstractMap.ViewCollection> diff --git a/src/java.base/share/classes/java/util/SequencedSet.java b/src/java.base/share/classes/java/util/SequencedSet.java index 5bae493f95f6c..6a65d046fee3b 100644 --- a/src/java.base/share/classes/java/util/SequencedSet.java +++ b/src/java.base/share/classes/java/util/SequencedSet.java @@ -56,7 +56,7 @@ public interface SequencedSet extends SequencedCollection, Set { * * @return a reverse-ordered view of this collection, as a {@code SequencedSet} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") SequencedSet reversed(); } diff --git a/src/java.base/share/classes/java/util/ServiceLoader.java b/src/java.base/share/classes/java/util/ServiceLoader.java index 076d5a5e85f00..c1d32bfbff385 100644 --- a/src/java.base/share/classes/java/util/ServiceLoader.java +++ b/src/java.base/share/classes/java/util/ServiceLoader.java @@ -32,7 +32,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -979,7 +979,7 @@ public boolean hasNext() { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Provider next(@NonEmpty LayerLookupIterator this) { if (!hasNext()) @@ -1301,7 +1301,7 @@ public boolean hasNext() { @SuppressWarnings("removal") @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Provider next(@NonEmpty LazyClassPathLookupIterator this) { if (acc == null) { @@ -1333,7 +1333,7 @@ public boolean hasNext() { return (first.hasNext() || second.hasNext()); } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Provider next(/*@NonEmpty Iterator> this*/) { if (first.hasNext()) { @@ -1423,7 +1423,7 @@ public boolean hasNext() { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public S next(/*@NonEmpty Iterator this*/) { checkReloadCount(); diff --git a/src/java.base/share/classes/java/util/SortedMap.java b/src/java.base/share/classes/java/util/SortedMap.java index eb3a7110df2e1..4051fa9679b42 100644 --- a/src/java.base/share/classes/java/util/SortedMap.java +++ b/src/java.base/share/classes/java/util/SortedMap.java @@ -314,7 +314,7 @@ public interface SortedMap extends SequencedMap { * @throws UnsupportedOperationException always * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default V putFirst(K k, V v) { throw new UnsupportedOperationException(); @@ -331,7 +331,7 @@ default V putFirst(K k, V v) { * @throws UnsupportedOperationException always * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default V putLast(K k, V v) { throw new UnsupportedOperationException(); @@ -347,7 +347,7 @@ default V putLast(K k, V v) { * @return a reverse-ordered view of this map, as a {@code SortedMap} * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default SortedMap reversed() { return ReverseOrderSortedMapView.of(this); diff --git a/src/java.base/share/classes/java/util/SortedSet.java b/src/java.base/share/classes/java/util/SortedSet.java index 699b52fc394a0..bfcba3a5158a6 100644 --- a/src/java.base/share/classes/java/util/SortedSet.java +++ b/src/java.base/share/classes/java/util/SortedSet.java @@ -269,7 +269,7 @@ public interface SortedSet extends Set, SequencedSet { * @since 1.8 */ @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default Spliterator spliterator() { return new Spliterators.IteratorSpliterator( @@ -294,7 +294,7 @@ public Comparator getComparator() { * @throws UnsupportedOperationException always * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default void addFirst(E e) { throw new UnsupportedOperationException(); @@ -311,7 +311,7 @@ default void addFirst(E e) { * @throws UnsupportedOperationException always * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default void addLast(E e) { throw new UnsupportedOperationException(); @@ -355,7 +355,7 @@ default E getLast() { * @throws UnsupportedOperationException {@inheritDoc} * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default E removeFirst() { E e = this.first(); @@ -375,7 +375,7 @@ default E removeFirst() { * @throws UnsupportedOperationException {@inheritDoc} * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default E removeLast() { E e = this.last(); @@ -393,7 +393,7 @@ default E removeLast() { * @return a reverse-ordered view of this collection, as a {@code SortedSet} * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") default SortedSet reversed() { return ReverseOrderSortedSetView.of(this); diff --git a/src/java.base/share/classes/java/util/Spliterators.java b/src/java.base/share/classes/java/util/Spliterators.java index c9dc86621403a..947c091c4b649 100644 --- a/src/java.base/share/classes/java/util/Spliterators.java +++ b/src/java.base/share/classes/java/util/Spliterators.java @@ -28,7 +28,7 @@ import org.checkerframework.checker.nonempty.qual.NonEmpty; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.function.Consumer; import java.util.function.DoubleConsumer; @@ -697,7 +697,7 @@ public boolean hasNext() { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public T next(@NonEmpty Adapter this) { if (!valueReady && !hasNext()) @@ -760,7 +760,7 @@ public boolean hasNext() { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int nextInt(@NonEmpty Adapter this) { if (!valueReady && !hasNext()) @@ -819,7 +819,7 @@ public boolean hasNext() { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public long nextLong(@NonEmpty Adapter this) { if (!valueReady && !hasNext()) @@ -878,7 +878,7 @@ public boolean hasNext() { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public double nextDouble(@NonEmpty Adapter this) { if (!valueReady && !hasNext()) diff --git a/src/java.base/share/classes/java/util/Stack.java b/src/java.base/share/classes/java/util/Stack.java index ad74f5c9d75ab..5877afa458b70 100644 --- a/src/java.base/share/classes/java/util/Stack.java +++ b/src/java.base/share/classes/java/util/Stack.java @@ -76,7 +76,7 @@ public Stack() { * @return the {@code item} argument. * @see java.util.Vector#addElement */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E push(@GuardSatisfied Stack this, E item) { addElement(item); @@ -92,7 +92,7 @@ public E push(@GuardSatisfied Stack this, E item) { * of the {@code Vector} object). * @throws EmptyStackException if this stack is empty. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized E pop(@GuardSatisfied @NonEmpty @CanShrink Stack this) { E obj; diff --git a/src/java.base/share/classes/java/util/TreeMap.java b/src/java.base/share/classes/java/util/TreeMap.java index 58d1a5706ae52..d54e0f9fa9c06 100644 --- a/src/java.base/share/classes/java/util/TreeMap.java +++ b/src/java.base/share/classes/java/util/TreeMap.java @@ -38,7 +38,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -310,7 +310,7 @@ public boolean containsValue(@GuardSatisfied TreeMap this, @GuardSatisfied * and this map uses natural ordering, or its comparator * does not permit null keys */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V get(@GuardSatisfied TreeMap this, @UnknownSignedness @GuardSatisfied Object key) { Entry p = getEntry(key); @@ -344,7 +344,7 @@ public boolean containsValue(@GuardSatisfied TreeMap this, @GuardSatisfied * @throws UnsupportedOperationException always * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putFirst(K k, V v) { throw new UnsupportedOperationException(); @@ -358,7 +358,7 @@ public V putFirst(K k, V v) { * @throws UnsupportedOperationException always * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putLast(K k, V v) { throw new UnsupportedOperationException(); @@ -376,7 +376,7 @@ public V putLast(K k, V v) { * the specified map contains a null key and this map does not * permit null keys */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putAll(@GuardSatisfied TreeMap this, Map map) { int mapSize = map.size(); @@ -599,14 +599,14 @@ final Entry getLowerEntry(K key) { * does not permit null keys */ @EnsuresKeyFor(value={"#1"}, map={"this"}) - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V put(@GuardSatisfied TreeMap this, K key, V value) { return put(key, value, true); } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putIfAbsent(K key, V value) { return put(key, value, false); @@ -954,7 +954,7 @@ private V mergeValue(Entry t, V value, BiFunction this, @GuardSatisfied @UnknownSignedness Object key) { Entry p = getEntry(key); @@ -970,7 +970,7 @@ private V mergeValue(Entry t, V value, BiFunction this) { modCount++; @@ -984,7 +984,7 @@ public void clear(@GuardSatisfied TreeMap this) { * * @return a shallow copy of this map */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Object clone(@GuardSatisfied TreeMap this) { TreeMap clone; @@ -1030,7 +1030,7 @@ public Object clone(@GuardSatisfied TreeMap this) { /** * @since 1.6 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.@Nullable Entry pollFirstEntry(@GuardSatisfied TreeMap this) { Entry p = getFirstEntry(); @@ -1043,7 +1043,7 @@ public Object clone(@GuardSatisfied TreeMap this) { /** * @since 1.6 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.@Nullable Entry pollLastEntry(@GuardSatisfied TreeMap this) { Entry p = getLastEntry(); @@ -1177,7 +1177,7 @@ public Object clone(@GuardSatisfied TreeMap this) { * operations. It does not support the {@code add} or {@code addAll} * operations. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Set<@KeyFor({"this"}) K> keySet(@GuardSatisfied TreeMap this) { return navigableKeySet(); @@ -1353,7 +1353,7 @@ public SortedMap tailMap(@GuardSatisfied TreeMap this, K fromKey) { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { Entry p = getEntry(key); @@ -1365,7 +1365,7 @@ public boolean replace(K key, V oldValue, V newValue) { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { Entry p = getEntry(key); @@ -1424,7 +1424,7 @@ public boolean contains(@UnknownSignedness Object o) { return TreeMap.this.containsValue(o); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { for (Entry e = getFirstEntry(); e != null; e = successor(e)) { @@ -1436,7 +1436,7 @@ public boolean remove(@UnknownSignedness Object o) { return false; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { TreeMap.this.clear(); @@ -1464,7 +1464,7 @@ public boolean contains(@UnknownSignedness Object o) { return p != null && valEquals(p.getValue(), value); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { if (!(o instanceof Map.Entry entry)) @@ -1483,7 +1483,7 @@ public boolean remove(@UnknownSignedness Object o) { return TreeMap.this.size(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { TreeMap.this.clear(); @@ -1538,7 +1538,7 @@ public Iterator descendingIterator() { @Pure @EnsuresNonEmptyIf(result = true, expression = "this") public boolean contains(@UnknownSignedness Object o) { return m.containsKey(o); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { m.clear(); } public E lower(E e) { return m.lowerKey(e); } @@ -1556,7 +1556,7 @@ public E pollLast() { Map.Entry e = m.pollLastEntry(); return (e == null) ? null : e.getKey(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { int oldSize = size(); @@ -1613,7 +1613,7 @@ public final boolean hasNext() { return next != null; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") final Entry nextEntry() { Entry e = next; if (e == null) @@ -1625,7 +1625,7 @@ final Entry nextEntry() { return e; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") final Entry prevEntry() { Entry e = next; if (e == null) @@ -1637,7 +1637,7 @@ final Entry prevEntry() { return e; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastReturned == null) @@ -1657,7 +1657,7 @@ final class EntryIterator extends PrivateEntryIterator> { EntryIterator(Entry first) { super(first); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(@NonEmpty EntryIterator this) { return nextEntry(); @@ -1668,7 +1668,7 @@ final class ValueIterator extends PrivateEntryIterator { ValueIterator(Entry first) { super(first); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V next(@NonEmpty ValueIterator this) { return nextEntry().value; @@ -1679,7 +1679,7 @@ final class KeyIterator extends PrivateEntryIterator { KeyIterator(Entry first) { super(first); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty KeyIterator this) { return nextEntry().key; @@ -1690,12 +1690,12 @@ final class DescendingKeyIterator extends PrivateEntryIterator { DescendingKeyIterator(Entry first) { super(first); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty DescendingKeyIterator this) { return prevEntry().key; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastReturned == null) @@ -1945,7 +1945,7 @@ public final boolean containsKey(@UnknownSignedness Object key) { } @EnsuresKeyFor(value={"#1"}, map={"this"}) - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final V put(K key, V value) { if (!inRange(key)) @@ -1953,7 +1953,7 @@ public final V put(K key, V value) { return m.put(key, value); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putIfAbsent(K key, V value) { if (!inRange(key)) @@ -1999,7 +1999,7 @@ public final V get(Object key) { return !inRange(key) ? null : m.get(key); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final V remove(Object key) { return !inRange(key) ? null : m.remove(key); @@ -2146,7 +2146,7 @@ public boolean contains(@UnknownSignedness Object o) { valEquals(node.getValue(), entry.getValue()); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { if (!(o instanceof Entry entry)) @@ -2187,7 +2187,7 @@ public final boolean hasNext() { return next != null && next.key != fenceKey; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") final TreeMap.Entry nextEntry() { TreeMap.Entry e = next; if (e == null || e.key == fenceKey) @@ -2199,7 +2199,7 @@ final TreeMap.Entry nextEntry() { return e; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") final TreeMap.Entry prevEntry() { TreeMap.Entry e = next; if (e == null || e.key == fenceKey) @@ -2241,12 +2241,12 @@ final class SubMapEntryIterator extends SubMapIterator> { TreeMap.Entry fence) { super(first, fence); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(@NonEmpty SubMapEntryIterator this) { return nextEntry(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { removeAscending(); @@ -2259,12 +2259,12 @@ final class DescendingSubMapEntryIterator extends SubMapIterator> super(last, fence); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(@NonEmpty DescendingSubMapEntryIterator this) { return prevEntry(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { removeDescending(); @@ -2278,12 +2278,12 @@ final class SubMapKeyIterator extends SubMapIterator TreeMap.Entry fence) { super(first, fence); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty SubMapKeyIterator this) { return nextEntry().key; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { removeAscending(); @@ -2320,12 +2320,12 @@ final class DescendingSubMapKeyIterator extends SubMapIterator TreeMap.Entry fence) { super(last, fence); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty DescendingSubMapKeyIterator this) { return prevEntry().key; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { removeDescending(); diff --git a/src/java.base/share/classes/java/util/TreeSet.java b/src/java.base/share/classes/java/util/TreeSet.java index d3a076c8fed2a..0e90aeef805b6 100644 --- a/src/java.base/share/classes/java/util/TreeSet.java +++ b/src/java.base/share/classes/java/util/TreeSet.java @@ -210,7 +210,7 @@ public TreeSet(@Nullable Comparator comparator) { * @return an iterator over the elements in this set in descending order * @since 1.6 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @PolyGrowShrink @PolyNonEmpty Iterator descendingIterator(@PolyGrowShrink @PolyNonEmpty TreeSet this) { return m.descendingKeySet().iterator(); @@ -219,7 +219,7 @@ public TreeSet(@Nullable Comparator comparator) { /** * @since 1.6 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public NavigableSet descendingSet() { return new TreeSet<>(m.descendingMap()); @@ -285,7 +285,7 @@ public boolean contains(@GuardSatisfied TreeSet this, @GuardSatisfied @Unknow * does not permit null elements */ @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(@GuardSatisfied TreeSet this, E e) { return m.put(e, PRESENT)==null; @@ -308,7 +308,7 @@ public boolean add(@GuardSatisfied TreeSet this, E e) { * and this set uses natural ordering, or its comparator * does not permit null elements */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied TreeSet this, @GuardSatisfied @UnknownSignedness Object o) { return m.remove(o)==PRESENT; @@ -318,7 +318,7 @@ public boolean remove(@GuardSatisfied TreeSet this, @GuardSatisfied @UnknownS * Removes all of the elements from this set. * The set will be empty after this call returns. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied TreeSet this) { m.clear(); @@ -335,7 +335,7 @@ public void clear(@GuardSatisfied TreeSet this) { * if any element is null and this set uses natural ordering, or * its comparator does not permit null elements */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@GuardSatisfied TreeSet this, Collection c) { // Use linear-time version if applicable @@ -498,7 +498,7 @@ public E last(@GuardSatisfied @NonEmpty TreeSet this) { /** * @since 1.6 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollFirst(@GuardSatisfied TreeSet this) { Map.Entry e = m.pollFirstEntry(); @@ -508,7 +508,7 @@ public E last(@GuardSatisfied @NonEmpty TreeSet this) { /** * @since 1.6 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollLast(@GuardSatisfied TreeSet this) { Map.Entry e = m.pollLastEntry(); @@ -523,7 +523,7 @@ public E last(@GuardSatisfied @NonEmpty TreeSet this) { * @throws UnsupportedOperationException always * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { throw new UnsupportedOperationException(); @@ -537,7 +537,7 @@ public void addFirst(E e) { * @throws UnsupportedOperationException always * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { throw new UnsupportedOperationException(); @@ -635,7 +635,7 @@ private void readObject(java.io.ObjectInputStream s) * @return a {@code Spliterator} over the elements in this set * @since 1.8 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Spliterator spliterator() { return TreeMap.keySpliteratorFor(m); diff --git a/src/java.base/share/classes/java/util/Vector.java b/src/java.base/share/classes/java/util/Vector.java index dc94c56fcbaac..e3c57409c97f7 100644 --- a/src/java.base/share/classes/java/util/Vector.java +++ b/src/java.base/share/classes/java/util/Vector.java @@ -40,7 +40,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -549,7 +549,7 @@ public synchronized E lastElement(@NonEmpty Vector this) { * @throws ArrayIndexOutOfBoundsException if the index is out of range * ({@code index < 0 || index >= size()}) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized void setElementAt(@GuardSatisfied Vector this, E obj, @NonNegative int index) { if (index >= elementCount) { @@ -578,7 +578,7 @@ public synchronized void setElementAt(@GuardSatisfied Vector this, E obj, @No * @throws ArrayIndexOutOfBoundsException if the index is out of range * ({@code index < 0 || index >= size()}) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized void removeElementAt(@GuardSatisfied @CanShrink Vector this, @NonNegative int index) { if (index >= elementCount) { @@ -620,7 +620,7 @@ else if (index < 0) { * @throws ArrayIndexOutOfBoundsException if the index is out of range * ({@code index < 0 || index > size()}) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized void insertElementAt(@GuardSatisfied Vector this, E obj, @NonNegative int index) { if (index > elementCount) { @@ -650,7 +650,7 @@ public synchronized void insertElementAt(@GuardSatisfied Vector this, E obj, * * @param obj the component to be added */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized void addElement(@GuardSatisfied Vector this, E obj) { modCount++; @@ -672,7 +672,7 @@ public synchronized void addElement(@GuardSatisfied Vector this, E obj) { * @return {@code true} if the argument was a component of this * vector; {@code false} otherwise. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized boolean removeElement(@GuardSatisfied @CanShrink Vector this, Object obj) { modCount++; @@ -690,7 +690,7 @@ public synchronized boolean removeElement(@GuardSatisfied @CanShrink Vector t *

This method is identical in functionality to the {@link #clear} * method (which is part of the {@link List} interface). */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized void removeAllElements(@GuardSatisfied @CanShrink Vector this) { final Object[] es = elementData; @@ -811,7 +811,7 @@ public synchronized E get(@GuardSatisfied Vector this, @NonNegative int index * ({@code index < 0 || index >= size()}) * @since 1.2 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized E set(@GuardSatisfied Vector this, @NonNegative int index, E element) { if (index >= elementCount) @@ -841,9 +841,9 @@ private void add(E e, Object[] elementData, int s) { * @return {@code true} (as specified by {@link Collection#add}) * @since 1.2 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized boolean add(@GuardSatisfied Vector this, E e) { modCount++; @@ -862,7 +862,7 @@ public synchronized boolean add(@GuardSatisfied Vector this, E e) { * @return true if the Vector contained the specified element * @since 1.2 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @CanShrink Vector this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { return removeElement(o); @@ -879,7 +879,7 @@ public boolean remove(@GuardSatisfied @CanShrink Vector this, @GuardSatisfied * ({@code index < 0 || index > size()}) * @since 1.2 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(@GuardSatisfied Vector this, @NonNegative int index, E element) { insertElementAt(element, index); @@ -896,7 +896,7 @@ public void add(@GuardSatisfied Vector this, @NonNegative int index, E elemen * ({@code index < 0 || index >= size()}) * @since 1.2 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized E remove(@GuardSatisfied @CanShrink Vector this, @NonNegative int index) { modCount++; @@ -919,7 +919,7 @@ public synchronized E remove(@GuardSatisfied @CanShrink Vector this, @NonNega * * @since 1.2 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink Vector this) { removeAllElements(); @@ -955,7 +955,7 @@ public synchronized boolean containsAll(@GuardSatisfied Vector this, @GuardSa * @throws NullPointerException if the specified collection is null * @since 1.2 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(@GuardSatisfied Vector this, Collection c) { Object[] a = c.toArray(); @@ -991,7 +991,7 @@ public boolean addAll(@GuardSatisfied Vector this, Collection c) * or if the specified collection is null * @since 1.2 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(@GuardSatisfied @CanShrink Vector this, Collection c) { Objects.requireNonNull(c); @@ -1017,7 +1017,7 @@ public boolean removeAll(@GuardSatisfied @CanShrink Vector this, Collection this, Collection c) { Objects.requireNonNull(c); @@ -1029,7 +1029,7 @@ public boolean retainAll(@GuardSatisfied @CanShrink Vector this, Collection this, Predicate filter) { Objects.requireNonNull(filter); @@ -1100,7 +1100,7 @@ private synchronized boolean bulkRemove(Predicate filter) { * @throws NullPointerException if the specified collection is null * @since 1.2 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized boolean addAll(@GuardSatisfied Vector this, @NonNegative int index, Collection c) { if (index < 0 || index > elementCount) @@ -1207,7 +1207,7 @@ public synchronized String toString(@GuardSatisfied Vector this) { * This call shortens the list by {@code (toIndex - fromIndex)} elements. * (If {@code toIndex==fromIndex}, this operation has no effect.) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") protected synchronized void removeRange(@GuardSatisfied @CanShrink Vector this, int fromIndex, int toIndex) { modCount++; @@ -1326,7 +1326,7 @@ public boolean hasNext() { return cursor != elementCount; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty Itr this) { synchronized (Vector.this) { @@ -1339,7 +1339,7 @@ public E next(@NonEmpty Itr this) { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastRet == -1) @@ -1412,7 +1412,7 @@ public E previous() { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void set(E e) { if (lastRet == -1) @@ -1423,7 +1423,7 @@ public void set(E e) { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(E e) { int i = cursor; @@ -1474,7 +1474,7 @@ public synchronized void replaceAll(UnaryOperator operator) { @SuppressWarnings("unchecked") @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized void sort(Comparator c) { final int expectedModCount = modCount; diff --git a/src/java.base/share/classes/java/util/WeakHashMap.java b/src/java.base/share/classes/java/util/WeakHashMap.java index 7e8d3a46edade..aa52dae7a4516 100644 --- a/src/java.base/share/classes/java/util/WeakHashMap.java +++ b/src/java.base/share/classes/java/util/WeakHashMap.java @@ -38,7 +38,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -483,7 +483,7 @@ Entry getEntry(Object key) { * previously associated {@code null} with {@code key}.) */ @EnsuresKeyFor(value={"#1"}, map={"this"}) - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V put(@GuardSatisfied WeakHashMap this, K key, V value) { Object k = maskNull(key); @@ -577,7 +577,7 @@ private void transfer(Entry[] src, Entry[] dest) { * @param m mappings to be stored in this map. * @throws NullPointerException if the specified map is null. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putAll(@GuardSatisfied WeakHashMap this, Map m) { int numKeysToBeAdded = m.size(); @@ -628,7 +628,7 @@ public void putAll(@GuardSatisfied WeakHashMap this, Map this, @GuardSatisfied @Nullable @UnknownSignedness Object key) { Object k = maskNull(key); @@ -689,7 +689,7 @@ boolean removeMapping(Object o) { * Removes all of the mappings from this map. * The map will be empty after this call returns. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied WeakHashMap this) { // clear out ref queue. We don't need to expunge entries @@ -771,7 +771,7 @@ public V getValue() { return value; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V setValue(V newValue) { V oldValue = value; @@ -850,7 +850,7 @@ public boolean hasNext() { } /** The common parts of next() across different types of iterators */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") protected Entry nextEntry() { if (modCount != expectedModCount) throw new ConcurrentModificationException(); @@ -864,7 +864,7 @@ protected Entry nextEntry() { return lastReturned; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastReturned == null) @@ -881,7 +881,7 @@ public void remove() { } private class ValueIterator extends HashIterator { - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V next(@NonEmpty ValueIterator this) { return nextEntry().value; @@ -889,7 +889,7 @@ public V next(@NonEmpty ValueIterator this) { } private class KeyIterator extends HashIterator { - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty KeyIterator this) { return nextEntry().getKey(); @@ -897,7 +897,7 @@ public K next(@NonEmpty KeyIterator this) { } private class EntryIterator extends HashIterator> { - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(@NonEmpty EntryIterator this) { return nextEntry(); @@ -948,7 +948,7 @@ public boolean contains(@Nullable @UnknownSignedness Object o) { return containsKey(o); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { if (containsKey(o)) { @@ -959,7 +959,7 @@ public boolean remove(@Nullable @UnknownSignedness Object o) { return false; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { WeakHashMap.this.clear(); @@ -1011,7 +1011,7 @@ public boolean contains(@Nullable @UnknownSignedness Object o) { return containsValue(o); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { WeakHashMap.this.clear(); @@ -1057,7 +1057,7 @@ && getEntry(e.getKey()) != null && getEntry(e.getKey()).equals(e); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { return removeMapping(o); @@ -1068,7 +1068,7 @@ public boolean remove(@Nullable @UnknownSignedness Object o) { return WeakHashMap.this.size(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { WeakHashMap.this.clear(); diff --git a/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java index a0b197c8c675b..684b4b094df89 100644 --- a/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java @@ -48,7 +48,7 @@ import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; import org.checkerframework.dataflow.qual.Pure; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -344,7 +344,7 @@ public ArrayBlockingQueue(int capacity, boolean fair, * @throws NullPointerException if the specified element is null */ @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { return super.add(e); @@ -359,7 +359,7 @@ public boolean add(E e) { * * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { Objects.requireNonNull(e); @@ -384,7 +384,7 @@ public boolean offer(E e) { * @throws InterruptedException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void put(E e) throws InterruptedException { Objects.requireNonNull(e); @@ -407,7 +407,7 @@ public void put(E e) throws InterruptedException { * @throws InterruptedException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException { @@ -429,7 +429,7 @@ public boolean offer(E e, long timeout, TimeUnit unit) } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E poll(@GuardSatisfied @CanShrink ArrayBlockingQueue this) { final ReentrantLock lock = this.lock; @@ -441,7 +441,7 @@ public E poll(@GuardSatisfied @CanShrink ArrayBlockingQueue this) { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E take(@GuardSatisfied @CanShrink ArrayBlockingQueue this) throws InterruptedException { final ReentrantLock lock = this.lock; @@ -455,7 +455,7 @@ public E take(@GuardSatisfied @CanShrink ArrayBlockingQueue this) throws Inte } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E poll(@GuardSatisfied @CanShrink ArrayBlockingQueue this, long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); @@ -542,7 +542,7 @@ 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 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink ArrayBlockingQueue this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { if (o == null) return false; @@ -695,7 +695,7 @@ public String toString() { * Atomically removes all of the elements from this queue. * The queue will be empty after this call returns. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink ArrayBlockingQueue this) { final ReentrantLock lock = this.lock; @@ -736,7 +736,7 @@ private static void circularClear(Object[] items, int i, int end) { * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink ArrayBlockingQueue this, Collection c) { return drainTo(c, Integer.MAX_VALUE); @@ -748,7 +748,7 @@ public int drainTo(@GuardSatisfied @CanShrink ArrayBlockingQueue this, Collec * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink ArrayBlockingQueue this, Collection c, int maxElements) { Objects.requireNonNull(c); @@ -1256,7 +1256,7 @@ private void noNext() { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty Itr this) { final E e = nextItem; @@ -1316,7 +1316,7 @@ public void forEachRemaining(Consumer action) { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { final ReentrantLock lock = ArrayBlockingQueue.this.lock; @@ -1519,7 +1519,7 @@ public void forEach(Consumer action) { /** * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink ArrayBlockingQueue this, Predicate filter) { Objects.requireNonNull(filter); @@ -1529,7 +1529,7 @@ public boolean removeIf(@CanShrink ArrayBlockingQueue this, Predicate this, Collection c) { Objects.requireNonNull(c); @@ -1539,7 +1539,7 @@ public boolean removeAll(@CanShrink ArrayBlockingQueue this, Collection this, Collection c) { Objects.requireNonNull(c); diff --git a/src/java.base/share/classes/java/util/concurrent/BlockingDeque.java b/src/java.base/share/classes/java/util/concurrent/BlockingDeque.java index 38f993ecc10d2..5f626cc338dbf 100644 --- a/src/java.base/share/classes/java/util/concurrent/BlockingDeque.java +++ b/src/java.base/share/classes/java/util/concurrent/BlockingDeque.java @@ -232,7 +232,7 @@ public interface BlockingDeque extends BlockingQueue< * @throws NullPointerException if the specified element is null * @throws IllegalArgumentException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void addFirst(E e); @@ -249,7 +249,7 @@ public interface BlockingDeque extends BlockingQueue< * @throws NullPointerException if the specified element is null * @throws IllegalArgumentException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void addLast(E e); @@ -267,7 +267,7 @@ public interface BlockingDeque extends BlockingQueue< * @throws NullPointerException if the specified element is null * @throws IllegalArgumentException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean offerFirst(E e); @@ -285,7 +285,7 @@ public interface BlockingDeque extends BlockingQueue< * @throws NullPointerException if the specified element is null * @throws IllegalArgumentException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean offerLast(E e); @@ -301,7 +301,7 @@ public interface BlockingDeque extends BlockingQueue< * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void putFirst(E e) throws InterruptedException; @@ -317,7 +317,7 @@ public interface BlockingDeque extends BlockingQueue< * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void putLast(E e) throws InterruptedException; @@ -340,7 +340,7 @@ public interface BlockingDeque extends BlockingQueue< * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException; @@ -364,7 +364,7 @@ boolean offerFirst(E e, long timeout, TimeUnit unit) * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean offerLast(E e, long timeout, TimeUnit unit) throws InterruptedException; @@ -376,7 +376,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * @return the head of this deque * @throws InterruptedException if interrupted while waiting */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E takeFirst(@CanShrink BlockingDeque this) throws InterruptedException; @@ -387,7 +387,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * @return the tail of this deque * @throws InterruptedException if interrupted while waiting */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E takeLast(@CanShrink BlockingDeque this) throws InterruptedException; @@ -404,7 +404,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * waiting time elapses before an element is available * @throws InterruptedException if interrupted while waiting */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E pollFirst(@CanShrink BlockingDeque this, long timeout, TimeUnit unit) throws InterruptedException; @@ -422,7 +422,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * waiting time elapses before an element is available * @throws InterruptedException if interrupted while waiting */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E pollLast(@CanShrink BlockingDeque this, long timeout, TimeUnit unit) throws InterruptedException; @@ -443,7 +443,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * @throws NullPointerException if the specified element is null * (optional) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean removeFirstOccurrence(@CanShrink BlockingDeque this, Object o); @@ -463,7 +463,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * @throws NullPointerException if the specified element is null * (optional) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean removeLastOccurrence(@CanShrink BlockingDeque this, Object o); @@ -488,7 +488,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @EnsuresNonEmpty("this") boolean add(E e); @@ -511,7 +511,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean offer(E e); @@ -530,7 +530,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void put(E e) throws InterruptedException; @@ -552,7 +552,7 @@ boolean offerLast(E e, long timeout, TimeUnit unit) * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this deque */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException; @@ -568,7 +568,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * @return the head of the queue represented by this deque * @throws NoSuchElementException if this deque is empty */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E remove(@GuardSatisfied @NonEmpty @CanShrink BlockingDeque this); @@ -581,7 +581,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * * @return the head of this deque, or {@code null} if this deque is empty */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E poll(@CanShrink BlockingDeque this); @@ -595,7 +595,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * @return the head of this deque * @throws InterruptedException if interrupted while waiting */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E take(@CanShrink BlockingDeque this) throws InterruptedException; @@ -611,7 +611,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * specified waiting time elapses before an element is available * @throws InterruptedException if interrupted while waiting */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E poll(@CanShrink BlockingDeque this, long timeout, TimeUnit unit) throws InterruptedException; @@ -661,7 +661,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * @throws NullPointerException if the specified element is null * (optional) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean remove(@CanShrink BlockingDeque this, @UnknownSignedness Object o); @@ -714,7 +714,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * @throws NullPointerException if the specified element is null * @throws IllegalArgumentException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void push(E e); } diff --git a/src/java.base/share/classes/java/util/concurrent/BlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/BlockingQueue.java index 4c9ce10a7ed77..dc9b4edda9eb8 100644 --- a/src/java.base/share/classes/java/util/concurrent/BlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/BlockingQueue.java @@ -209,7 +209,7 @@ public interface BlockingQueue extends Queue { * element prevents it from being added to this queue */ @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean add(E e); @@ -230,7 +230,7 @@ public interface BlockingQueue extends Queue { * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this queue */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean offer(E e); @@ -246,7 +246,7 @@ public interface BlockingQueue extends Queue { * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this queue */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") void put(E e) throws InterruptedException; @@ -268,7 +268,7 @@ public interface BlockingQueue extends Queue { * @throws IllegalArgumentException if some property of the specified * element prevents it from being added to this queue */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException; @@ -280,7 +280,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * @return the head of this queue * @throws InterruptedException if interrupted while waiting */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") E take() throws InterruptedException; @@ -296,7 +296,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * specified waiting time elapses before an element is available * @throws InterruptedException if interrupted while waiting */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable E poll(long timeout, TimeUnit unit) throws InterruptedException; @@ -332,7 +332,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * @throws NullPointerException if the specified element is null * (optional) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean remove(@CanShrink BlockingQueue this, @UnknownSignedness Object o); @@ -376,7 +376,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * queue, or some property of an element of this queue prevents * it from being added to the specified collection */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") int drainTo(@GuardSatisfied @CanShrink BlockingQueue this, Collection c); @@ -403,7 +403,7 @@ boolean offer(E e, long timeout, TimeUnit unit) * queue, or some property of an element of this queue prevents * it from being added to the specified collection */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") int drainTo(@GuardSatisfied @CanShrink BlockingQueue this, Collection c, int maxElements); } diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java index d306545bacd63..b472783200544 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java @@ -50,7 +50,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -665,7 +665,7 @@ static class Node implements Map.Entry { public final String toString() { return Helpers.mapEntryToString(key, val); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final V setValue(V value) { throw new UnsupportedOperationException(); @@ -1032,7 +1032,7 @@ public boolean containsValue(@GuardSatisfied @UnknownSignedness Object value) { * @throws NullPointerException if the specified key or value is null */ @EnsuresKeyFor(value={"#1"}, map={"this"}) - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V put(K key, V value) { return putVal(key, value, false); @@ -1115,7 +1115,7 @@ else if (f instanceof ReservationNode) * * @param m mappings to be stored in this map */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putAll(Map m) { tryPresize(m.size()); @@ -1132,7 +1132,7 @@ public void putAll(Map m) { * {@code null} if there was no mapping for {@code key} * @throws NullPointerException if the specified key is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V remove(@GuardSatisfied @UnknownSignedness Object key) { return replaceNode(key, null, null); @@ -1219,7 +1219,7 @@ else if (f instanceof ReservationNode) /** * Removes all of the mappings from this map. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { long delta = 0L; // negative number of deletions @@ -1581,7 +1581,7 @@ private void readObject(java.io.ObjectInputStream s) * @throws NullPointerException if the specified key or value is null */ @EnsuresKeyFor(value={"#1"}, map={"this"}) - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V putIfAbsent(K key, V value) { return putVal(key, value, true); @@ -1592,7 +1592,7 @@ private void readObject(java.io.ObjectInputStream s) * * @throws NullPointerException if the specified key is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @UnknownSignedness Object key, @GuardSatisfied @UnknownSignedness Object value) { if (key == null) @@ -1605,7 +1605,7 @@ public boolean remove(@GuardSatisfied @UnknownSignedness Object key, @GuardSatis * * @throws NullPointerException if any of the arguments are null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { if (key == null || oldValue == null || newValue == null) @@ -1620,7 +1620,7 @@ public boolean replace(K key, V oldValue, V newValue) { * or {@code null} if there was no mapping for the key * @throws NullPointerException if the specified key or value is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable V replace(K key, V value) { if (key == null || value == null) @@ -3503,7 +3503,7 @@ static class BaseIterator extends Traverser { @Pure public final boolean hasMoreElements() { return next != null; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void remove() { Node p; @@ -3521,7 +3521,7 @@ static final class KeyIterator extends BaseIterator super(tab, size, index, limit, map); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final K next(@NonEmpty KeyIterator this) { Node p; @@ -3533,7 +3533,7 @@ public final K next(@NonEmpty KeyIterator this) { return k; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final K nextElement(@NonEmpty KeyIterator this) { return next(); } } @@ -3545,7 +3545,7 @@ static final class ValueIterator extends BaseIterator super(tab, size, index, limit, map); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final V next(@NonEmpty ValueIterator this) { Node p; @@ -3557,7 +3557,7 @@ public final V next(@NonEmpty ValueIterator this) { return v; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final V nextElement(@NonEmpty ValueIterator this) { return next(); } } @@ -3569,7 +3569,7 @@ static final class EntryIterator extends BaseIterator super(tab, size, index, limit, map); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final Map.Entry next(@NonEmpty EntryIterator this) { Node p; @@ -3619,7 +3619,7 @@ public boolean equals(Object o) { * could even have been removed, in which case the put will * re-establish). We do not and cannot guarantee more. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V setValue(V value) { if (value == null) throw new NullPointerException(); @@ -4512,7 +4512,7 @@ abstract static sealed class CollectionView * Removes all of the elements from this view, by removing all * the mappings from the map backing this view. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void clear() { map.clear(); } @Pure @@ -4536,7 +4536,7 @@ abstract static sealed class CollectionView @Pure @EnsuresNonEmptyIf(result = true, expression = "this") public abstract boolean contains(@UnknownSignedness Object o); - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public abstract boolean remove(@UnknownSignedness Object o); @@ -4634,7 +4634,7 @@ public final boolean containsAll(Collection c) { if (c == null) throw new NullPointerException(); @@ -4658,7 +4658,7 @@ public boolean removeAll(Collection c) { if (c == null) throw new NullPointerException(); @@ -4724,7 +4724,7 @@ public static final class KeySetView extends CollectionView * @return {@code true} if the backing map contained the specified key * @throws NullPointerException if the specified key is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { return map.remove(o) != null; } @@ -4750,7 +4750,7 @@ public Iterator iterator() { * for additions was provided */ @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(K e) { V v; @@ -4770,7 +4770,7 @@ public boolean add(K e) { * @throws UnsupportedOperationException if no default mapped value * for additions was provided */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { boolean added = false; @@ -4833,7 +4833,7 @@ public final boolean contains(@UnknownSignedness Object o) { return map.containsValue(o); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final boolean remove(@UnknownSignedness Object o) { if (o != null) { @@ -4856,12 +4856,12 @@ public final Iterator iterator() { } @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final boolean add(V e) { throw new UnsupportedOperationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final boolean addAll(Collection c) { throw new UnsupportedOperationException(); @@ -4879,7 +4879,7 @@ public final boolean addAll(Collection c) { return modified; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { return map.removeValueIf(filter); @@ -4926,7 +4926,7 @@ public boolean contains(@UnknownSignedness Object o) { (v == r || v.equals(r))); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { Object k, v; Map.Entry e; @@ -4948,13 +4948,13 @@ public Iterator> iterator() { } @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(Entry e) { return map.putVal(e.getKey(), e.getValue(), false) == null; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection> c) { boolean added = false; @@ -4965,7 +4965,7 @@ public boolean addAll(Collection> c) { return added; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate> filter) { return map.removeEntryIf(filter); diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java index 70b0e5b0bd81a..b1c1d1dc3b92c 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java @@ -50,7 +50,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -843,7 +843,7 @@ private void initHeadTail(Node h, Node t) { * * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { linkFirst(e); @@ -858,7 +858,7 @@ public void addFirst(E e) { * * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { linkLast(e); @@ -871,7 +871,7 @@ public void addLast(E e) { * @return {@code true} (as specified by {@link Deque#offerFirst}) * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offerFirst(E e) { linkFirst(e); @@ -887,7 +887,7 @@ public boolean offerFirst(E e) { * @return {@code true} (as specified by {@link Deque#offerLast}) * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offerLast(E e) { linkLast(e); @@ -940,7 +940,7 @@ public E getLast(@NonEmpty ConcurrentLinkedDeque this) { return screenNullResult(peekLast()); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollFirst(@GuardSatisfied @CanShrink ConcurrentLinkedDeque this) { restart: for (;;) { @@ -963,7 +963,7 @@ public E getLast(@NonEmpty ConcurrentLinkedDeque this) { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollLast(@GuardSatisfied @CanShrink ConcurrentLinkedDeque this) { restart: for (;;) { @@ -989,7 +989,7 @@ public E getLast(@NonEmpty ConcurrentLinkedDeque this) { /** * @throws NoSuchElementException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeFirst(@GuardSatisfied @NonEmpty @CanShrink ConcurrentLinkedDeque this) { return screenNullResult(pollFirst()); @@ -998,7 +998,7 @@ public E removeFirst(@GuardSatisfied @NonEmpty @CanShrink ConcurrentLinkedDeque< /** * @throws NoSuchElementException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeLast(@GuardSatisfied @NonEmpty @CanShrink ConcurrentLinkedDeque this) { return screenNullResult(pollLast()); @@ -1013,7 +1013,7 @@ public E removeLast(@GuardSatisfied @NonEmpty @CanShrink ConcurrentLinkedDeque this) { return pollFirst(); } @Pure @@ -1043,14 +1043,14 @@ public boolean add(E e) { /** * @throws NoSuchElementException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(@NonEmpty @CanShrink ConcurrentLinkedDeque this) { return removeFirst(); } /** * @throws NoSuchElementException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E pop(@GuardSatisfied @NonEmpty @CanShrink ConcurrentLinkedDeque this) { return removeFirst(); } @@ -1062,7 +1062,7 @@ public boolean add(E e) { /** * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void push(E e) { addFirst(e); } @@ -1078,7 +1078,7 @@ public boolean add(E e) { * @return {@code true} if the deque contained the specified element * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeFirstOccurrence(@CanShrink ConcurrentLinkedDeque this, Object o) { Objects.requireNonNull(o); @@ -1106,7 +1106,7 @@ public boolean removeFirstOccurrence(@CanShrink ConcurrentLinkedDeque this, O * @return {@code true} if the deque contained the specified element * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeLastOccurrence(@CanShrink ConcurrentLinkedDeque this, Object o) { Objects.requireNonNull(o); @@ -1200,7 +1200,7 @@ public int size() { * @return {@code true} if the deque contained the specified element * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink ConcurrentLinkedDeque this, @GuardSatisfied @UnknownSignedness Object o) { return removeFirstOccurrence(o); @@ -1218,7 +1218,7 @@ public boolean remove(@CanShrink ConcurrentLinkedDeque this, @GuardSatisfied * of its elements are null * @throws IllegalArgumentException if the collection is this deque */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { if (c == this) @@ -1274,7 +1274,7 @@ else if (p.prev == p) // NEXT_TERMINATOR /** * Removes all of the elements from this deque. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink ConcurrentLinkedDeque this) { while (pollFirst() != null) @@ -1484,7 +1484,7 @@ public boolean hasNext() { return nextItem != null; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty AbstractItr this) { E item = nextItem; @@ -1493,7 +1493,7 @@ public E next(@NonEmpty AbstractItr this) { return item; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { Node l = lastRet; @@ -1680,7 +1680,7 @@ private void readObject(java.io.ObjectInputStream s) /** * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink ConcurrentLinkedDeque this, Predicate filter) { Objects.requireNonNull(filter); @@ -1690,7 +1690,7 @@ public boolean removeIf(@CanShrink ConcurrentLinkedDeque this, Predicate this, Collection c) { Objects.requireNonNull(c); @@ -1700,7 +1700,7 @@ public boolean removeAll(@CanShrink ConcurrentLinkedDeque this, Collection this, Collection c) { Objects.requireNonNull(c); diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java index c5f44e2e63d60..25962bc5d6b74 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java @@ -49,7 +49,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -299,7 +299,7 @@ public ConcurrentLinkedQueue(Collection c) { * @throws NullPointerException if the specified element is null */ @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { return offer(e); @@ -373,7 +373,7 @@ private Node skipDeadNodes(Node pred, Node c, Node p, Node q) { * @return {@code true} (as specified by {@link Queue#offer}) * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { final Node newNode = new Node(Objects.requireNonNull(e)); @@ -404,7 +404,7 @@ else if (p == q) } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink ConcurrentLinkedQueue this) { restartFromHead: for (;;) { @@ -550,7 +550,7 @@ public boolean contains(@GuardSatisfied @UnknownSignedness Object o) { * @param o element to be removed from this queue, if present * @return {@code true} if this queue changed as a result of the call */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink ConcurrentLinkedQueue this, @GuardSatisfied @UnknownSignedness Object o) { if (o == null) return false; @@ -588,7 +588,7 @@ public boolean remove(@CanShrink ConcurrentLinkedQueue this, @GuardSatisfied * of its elements are null * @throws IllegalArgumentException if the collection is this queue */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { if (c == this) @@ -813,7 +813,7 @@ public boolean hasNext() { return nextItem != null; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty Itr this) { final Node pred = nextNode; @@ -837,7 +837,7 @@ public E next(@NonEmpty Itr this) { // Default implementation of forEachRemaining is "good enough". - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { Node l = lastRet; @@ -1005,7 +1005,7 @@ public Spliterator spliterator() { /** * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink ConcurrentLinkedQueue this, Predicate filter) { Objects.requireNonNull(filter); @@ -1015,7 +1015,7 @@ public boolean removeIf(@CanShrink ConcurrentLinkedQueue this, Predicate this, Collection c) { Objects.requireNonNull(c); @@ -1025,14 +1025,14 @@ public boolean removeAll(@CanShrink ConcurrentLinkedQueue this, Collection this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> !c.contains(e)); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink ConcurrentLinkedQueue this) { bulkRemove(e -> true); diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentMap.java index a50b12fcabdfa..c19b3b58ff04f 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentMap.java @@ -167,7 +167,7 @@ default void forEach(BiConsumer action) { * or value prevents it from being stored in this map */ @EnsuresKeyFor(value={"#1"}, map={"this"}) - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable V putIfAbsent(K key, V value); @@ -200,7 +200,7 @@ default void forEach(BiConsumer action) { * and this map does not permit null keys or values * (optional) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean remove(@UnknownSignedness Object key, @UnknownSignedness Object value); @@ -234,7 +234,7 @@ default void forEach(BiConsumer action) { * @throws IllegalArgumentException if some property of a specified key * or value prevents it from being stored in this map */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") boolean replace(K key, V oldValue, V newValue); @@ -268,7 +268,7 @@ default void forEach(BiConsumer action) { * @throws IllegalArgumentException if some property of the specified key * or value prevents it from being stored in this map */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @Nullable V replace(K key, V value); diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java index 89b7d80ebb258..982e87617f7d4 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java @@ -46,7 +46,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.lang.invoke.MethodHandles; @@ -1357,7 +1357,7 @@ public V getOrDefault(@GuardSatisfied @UnknownSignedness Object key, V defaultVa * with the keys currently in the map * @throws NullPointerException if the specified key or value is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V put(K key, V value) { if (value == null) @@ -1375,7 +1375,7 @@ public V put(K key, V value) { * with the keys currently in the map * @throws NullPointerException if the specified key is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V remove(@GuardSatisfied @UnknownSignedness Object key) { return doRemove(key, null); @@ -1432,7 +1432,7 @@ public boolean isEmpty() { /** * Removes all of the mappings from this map. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { Index h, r, d; Node b; @@ -1817,7 +1817,7 @@ public boolean equals(@Nullable Object o) { * with the keys currently in the map * @throws NullPointerException if the specified key or value is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putIfAbsent(K key, V value) { if (value == null) @@ -1832,7 +1832,7 @@ public V putIfAbsent(K key, V value) { * with the keys currently in the map * @throws NullPointerException if the specified key is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @UnknownSignedness Object key, @GuardSatisfied @UnknownSignedness Object value) { if (key == null) @@ -1847,7 +1847,7 @@ public boolean remove(@GuardSatisfied @UnknownSignedness Object key, @GuardSatis * with the keys currently in the map * @throws NullPointerException if any of the arguments are null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { if (key == null || oldValue == null || newValue == null) @@ -1874,7 +1874,7 @@ public boolean replace(K key, V oldValue, V newValue) { * with the keys currently in the map * @throws NullPointerException if the specified key or value is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { if (key == null || value == null) @@ -1922,7 +1922,7 @@ public K lastKey(@NonEmpty ConcurrentSkipListMap this) { * @throws UnsupportedOperationException always * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putFirst(K k, V v) { throw new UnsupportedOperationException(); @@ -1936,7 +1936,7 @@ public V putFirst(K k, V v) { * @throws UnsupportedOperationException always * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putLast(K k, V v) { throw new UnsupportedOperationException(); @@ -2136,7 +2136,7 @@ public Map.Entry lastEntry() { * The returned entry does not support * the {@code Entry.setValue} method. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry pollFirstEntry() { return doRemoveFirstEntry(); @@ -2148,7 +2148,7 @@ public Map.Entry pollFirstEntry() { * The returned entry does not support * the {@code Entry.setValue} method. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry pollLastEntry() { return doRemoveLastEntry(); @@ -2190,7 +2190,7 @@ final void advance(Node b) { next = n; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void remove() { Node n; K k; @@ -2204,7 +2204,7 @@ public final void remove() { } final class ValueIterator extends Iter { - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V next(@NonEmpty ValueIterator this) { V v; @@ -2216,7 +2216,7 @@ public V next(@NonEmpty ValueIterator this) { } final class KeyIterator extends Iter { - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty KeyIterator this) { Node n; @@ -2229,7 +2229,7 @@ public K next(@NonEmpty KeyIterator this) { } final class EntryIterator extends Iter> { - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(@NonEmpty EntryIterator this) { Node n; @@ -2270,10 +2270,10 @@ static final class KeySet @Pure @EnsuresNonEmptyIf(result = true, expression = "this") public boolean contains(@UnknownSignedness Object o) { return m.containsKey(o); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { return m.remove(o) != null; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { m.clear(); } public K lower(K e) { return m.lowerKey(e); } @@ -2283,13 +2283,13 @@ static final class KeySet public Comparator comparator() { return m.comparator(); } public K first() { return m.firstKey(); } public K last() { return m.lastKey(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public K pollFirst() { Map.Entry e = m.pollFirstEntry(); return (e == null) ? null : e.getKey(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public K pollLast() { Map.Entry e = m.pollLastEntry(); @@ -2368,7 +2368,7 @@ public Iterator iterator() { @Pure @EnsuresNonEmptyIf(result = true, expression = "this") public boolean contains(@UnknownSignedness Object o) { return m.containsValue(o); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { m.clear(); } public Object[] toArray() { return toList(this).toArray(); } @@ -2380,7 +2380,7 @@ public Spliterator spliterator() { : ((SubMap)m).new SubMapValueIterator(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { if (filter == null) throw new NullPointerException(); @@ -2420,7 +2420,7 @@ public boolean contains(@UnknownSignedness Object o) { V v = m.get(e.getKey()); return v != null && v.equals(e.getValue()); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object o) { if (!(o instanceof Map.Entry)) @@ -2438,7 +2438,7 @@ public boolean isEmpty() { public int size() { return m.size(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { m.clear(); @@ -2463,7 +2463,7 @@ public Spliterator> spliterator() { ? ((ConcurrentSkipListMap)m).entrySpliterator() : ((SubMap)m).new SubMapEntryIterator(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate> filter) { if (filter == null) throw new NullPointerException(); @@ -2751,14 +2751,14 @@ public V get(Object key) { return (!inBounds(key, m.comparator)) ? null : m.get(key); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V put(K key, V value) { checkKeyBounds(key, m.comparator); return m.put(key, value); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V remove(Object key) { return (!inBounds(key, m.comparator)) ? null : m.remove(key); @@ -2799,7 +2799,7 @@ public boolean containsValue(@UnknownSignedness Object value) { return false; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { Comparator cmp = m.comparator; @@ -2813,27 +2813,27 @@ public void clear() { /* ---------------- ConcurrentMap API methods -------------- */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V putIfAbsent(K key, V value) { checkKeyBounds(key, m.comparator); return m.putIfAbsent(key, value); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@UnknownSignedness Object key, @UnknownSignedness Object value) { return inBounds(key, m.comparator) && m.remove(key, value); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean replace(K key, V oldValue, V newValue) { checkKeyBounds(key, m.comparator); return m.replace(key, oldValue, newValue); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V replace(K key, V value) { checkKeyBounds(key, m.comparator); @@ -2984,13 +2984,13 @@ public Map.Entry lastEntry() { return isDescending ? lowestEntry() : highestEntry(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry pollFirstEntry() { return isDescending ? removeHighest() : removeLowest(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry pollLastEntry() { return isDescending ? removeLowest() : removeHighest(); @@ -3109,7 +3109,7 @@ private void descend() { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { Node l = lastReturned; @@ -3143,7 +3143,7 @@ public long estimateSize() { } final class SubMapValueIterator extends SubMapIter { - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public V next(@NonEmpty SubMapValueIterator this) { V v = nextValue; @@ -3156,7 +3156,7 @@ public int characteristics() { } final class SubMapKeyIterator extends SubMapIter { - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public K next(@NonEmpty SubMapKeyIterator this) { Node n = next; @@ -3173,7 +3173,7 @@ public final Comparator getComparator() { } final class SubMapEntryIterator extends SubMapIter> { - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Map.Entry next(@NonEmpty SubMapEntryIterator this) { Node n = next; diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java index c428db68c69c0..a5682c38b6b90 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java @@ -262,7 +262,7 @@ public boolean contains(@GuardSatisfied @UnknownSignedness Object o) { * @throws NullPointerException if the specified element is null */ @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { return m.putIfAbsent(e, Boolean.TRUE) == null; @@ -282,7 +282,7 @@ public boolean add(E e) { * with the elements currently in this set * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @UnknownSignedness Object o) { return m.remove(o, Boolean.TRUE); @@ -291,7 +291,7 @@ public boolean remove(@GuardSatisfied @UnknownSignedness Object o) { /** * Removes all of the elements from this set. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { m.clear(); @@ -361,7 +361,7 @@ public boolean equals(@Nullable Object o) { * @throws NullPointerException if the specified collection or any * of its elements are null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { // Override AbstractSet version to avoid unnecessary call to size() @@ -406,14 +406,14 @@ public E higher(E e) { return m.higherKey(e); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollFirst() { Map.Entry e = m.pollFirstEntry(); return (e == null) ? null : e.getKey(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollLast() { Map.Entry e = m.pollLastEntry(); diff --git a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java index 3b855eaad0d36..3c85dcccee7f2 100644 --- a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java +++ b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java @@ -49,7 +49,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.lang.invoke.VarHandle; @@ -460,7 +460,7 @@ public E getLast() { * * @throws IndexOutOfBoundsException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E set(int index, E element) { synchronized (lock) { @@ -484,7 +484,7 @@ public E set(int index, E element) { * @return {@code true} (as specified by {@link Collection#add}) */ @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { synchronized (lock) { @@ -504,7 +504,7 @@ public boolean add(E e) { * * @throws IndexOutOfBoundsException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(int index, E element) { synchronized (lock) { @@ -532,7 +532,7 @@ public void add(int index, E element) { * * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { add(0, e); @@ -543,7 +543,7 @@ public void addFirst(E e) { * * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { synchronized (lock) { @@ -558,7 +558,7 @@ public void addLast(E e) { * * @throws IndexOutOfBoundsException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @CanShrink CopyOnWriteArrayList this, int index) { synchronized (lock) { @@ -586,7 +586,7 @@ public E remove(@GuardSatisfied @CanShrink CopyOnWriteArrayList this, int ind * @throws NoSuchElementException {@inheritDoc} * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeFirst() { synchronized (lock) { @@ -603,7 +603,7 @@ public E removeFirst() { * @throws NoSuchElementException {@inheritDoc} * @since 21 */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeLast() { synchronized (lock) { @@ -627,7 +627,7 @@ public E removeLast() { * @param o element to be removed from this list, if present * @return {@code true} if this list contained the specified element */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink CopyOnWriteArrayList this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { Object[] snapshot = getArray(); @@ -709,7 +709,7 @@ void removeRange(@GuardSatisfied @CanShrink CopyOnWriteArrayList this, int fr * @param e element to be added to this list, if absent * @return {@code true} if the element was added */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addIfAbsent(E e) { Object[] snapshot = getArray(); @@ -779,7 +779,7 @@ public boolean containsAll(Collection c) { * or if the specified collection is null * @see #remove(Object) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(@CanShrink CopyOnWriteArrayList this, Collection c) { Objects.requireNonNull(c); @@ -802,7 +802,7 @@ public boolean removeAll(@CanShrink CopyOnWriteArrayList this, Collection this, Collection c) { Objects.requireNonNull(c); @@ -820,7 +820,7 @@ public boolean retainAll(@GuardSatisfied @CanShrink CopyOnWriteArrayList this * @throws NullPointerException if the specified collection is null * @see #addIfAbsent(Object) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int addAllAbsent(Collection c) { Object[] cs = c.toArray(); @@ -853,7 +853,7 @@ public int addAllAbsent(Collection c) { * Removes all of the elements from this list. * The list will be empty after this call returns. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink CopyOnWriteArrayList this) { synchronized (lock) { @@ -871,7 +871,7 @@ public void clear(@GuardSatisfied @CanShrink CopyOnWriteArrayList this) { * @throws NullPointerException if the specified collection is null * @see #add(Object) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { Object[] cs = (c.getClass() == CopyOnWriteArrayList.class) ? @@ -910,7 +910,7 @@ public boolean addAll(Collection c) { * @throws NullPointerException if the specified collection is null * @see #add(int,Object) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(int index, Collection c) { Object[] cs = c.toArray(); @@ -952,7 +952,7 @@ public void forEach(Consumer action) { /** * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink CopyOnWriteArrayList this, Predicate filter) { Objects.requireNonNull(filter); @@ -1027,7 +1027,7 @@ void replaceAllRange(UnaryOperator operator, int i, int end) { setArray(es); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void sort(Comparator c) { synchronized (lock) { @@ -1245,7 +1245,7 @@ public boolean hasPrevious() { } @SuppressWarnings("unchecked") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty COWIterator this) { if (! hasNext()) @@ -1254,7 +1254,7 @@ public E next(@NonEmpty COWIterator this) { } @SuppressWarnings("unchecked") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public E previous() { if (! hasPrevious()) throw new NoSuchElementException(); @@ -1276,7 +1276,7 @@ public int previousIndex() { * @throws UnsupportedOperationException always; {@code remove} * is not supported by this iterator. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { throw new UnsupportedOperationException(); @@ -1287,7 +1287,7 @@ public void remove() { * @throws UnsupportedOperationException always; {@code set} * is not supported by this iterator. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void set(E e) { throw new UnsupportedOperationException(); @@ -1298,7 +1298,7 @@ public void set(E e) { * @throws UnsupportedOperationException always; {@code add} * is not supported by this iterator. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(E e) { throw new UnsupportedOperationException(); @@ -1507,7 +1507,7 @@ public boolean equals(Object o) { return !it.hasNext(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E set(int index, E element) { synchronized (lock) { @@ -1554,7 +1554,7 @@ public int size() { } @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E element) { synchronized (lock) { @@ -1566,7 +1566,7 @@ public boolean add(E element) { return true; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(int index, E element) { synchronized (lock) { @@ -1578,13 +1578,13 @@ public void add(int index, E element) { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { add(0, e); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { synchronized (lock) { @@ -1592,7 +1592,7 @@ public void addLast(E e) { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { synchronized (lock) { @@ -1604,7 +1604,7 @@ public boolean addAll(Collection c) { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(int index, Collection c) { synchronized (lock) { @@ -1617,7 +1617,7 @@ public boolean addAll(int index, Collection c) { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { synchronized (lock) { @@ -1628,7 +1628,7 @@ public void clear() { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(int index) { synchronized (lock) { @@ -1641,7 +1641,7 @@ public E remove(int index) { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeFirst() { synchronized (lock) { @@ -1652,7 +1652,7 @@ public E removeFirst() { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeLast() { synchronized (lock) { @@ -1663,7 +1663,7 @@ public E removeLast() { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@Nullable @UnknownSignedness Object o) { synchronized (lock) { @@ -1723,7 +1723,7 @@ public void replaceAll(UnaryOperator operator) { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void sort(Comparator c) { synchronized (lock) { @@ -1733,21 +1733,21 @@ public void sort(Comparator c) { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> c.contains(e)); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> !c.contains(e)); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { Objects.requireNonNull(filter); @@ -1794,7 +1794,7 @@ public boolean hasNext() { return nextIndex() < size; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty COWSubListIterator this) { if (hasNext()) @@ -1878,10 +1878,10 @@ class DescendingIterator implements Iterator { } } public boolean hasNext() { return it.hasPrevious(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next() { return it.previous(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { it.remove(); } } @@ -1903,7 +1903,7 @@ public boolean hasNext() { return it.hasPrevious(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next() { return it.previous(); @@ -1925,19 +1925,19 @@ public int previousIndex() { return nextIndex() - 1; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { throw new UnsupportedOperationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void set(E e) { throw new UnsupportedOperationException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(E e) { throw new UnsupportedOperationException(); @@ -1962,14 +1962,14 @@ public Spliterator spliterator() { // ========== Collection ========== - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { base.add(0, e); return true; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { @SuppressWarnings("unchecked") @@ -1983,7 +1983,7 @@ public boolean addAll(Collection c) { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { base.clear(); @@ -2031,7 +2031,7 @@ public Stream parallelStream() { return StreamSupport.stream(spliterator(), true); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(Object o) { synchronized (lock) { @@ -2043,13 +2043,13 @@ public boolean remove(Object o) { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { return base.removeAll(c); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { return base.retainAll(c); @@ -2096,7 +2096,7 @@ public String toString() { // ========== List ========== - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void add(int index, E element) { synchronized (lock) { @@ -2104,19 +2104,19 @@ public void add(int index, E element) { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { base.add(e); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { base.add(0, e); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(int index, Collection c) { @SuppressWarnings("unchecked") @@ -2179,7 +2179,7 @@ public ListIterator listIterator(int index) { return new DescendingListIterator(index); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(int index) { synchronized (lock) { @@ -2187,7 +2187,7 @@ public E remove(int index) { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeFirst() { synchronized (lock) { @@ -2199,7 +2199,7 @@ public E removeFirst() { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeLast() { synchronized (lock) { @@ -2210,7 +2210,7 @@ public E removeLast() { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { return base.removeIf(filter); @@ -2221,13 +2221,13 @@ public void replaceAll(UnaryOperator operator) { base.replaceAll(operator); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void sort(Comparator c) { base.sort(Collections.reverseOrder(c)); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E set(int index, E element) { synchronized (lock) { diff --git a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java index 88e80923238e9..3e1358d2f5b70 100644 --- a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java +++ b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java @@ -247,7 +247,7 @@ public boolean contains(@GuardSatisfied @Nullable @UnknownSignedness Object o) { * Removes all of the elements from this set. * The set will be empty after this call returns. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { al.clear(); @@ -264,7 +264,7 @@ public void clear() { * @param o object to be removed from this set, if present * @return {@code true} if this set contained the specified element */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@GuardSatisfied @Nullable @UnknownSignedness Object o) { return al.remove(o); @@ -283,7 +283,7 @@ public boolean remove(@GuardSatisfied @Nullable @UnknownSignedness Object o) { * element */ @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { return al.addIfAbsent(e); @@ -355,7 +355,7 @@ private static int compareSets(Object[] snapshot, Set set) { * @throws NullPointerException if the specified collection is null * @see #add(Object) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { return al.addAllAbsent(c) > 0; @@ -378,7 +378,7 @@ public boolean addAll(Collection c) { * or if the specified collection is null * @see #remove(Object) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(Collection c) { return al.removeAll(c); @@ -403,7 +403,7 @@ public boolean removeAll(Collection c) { return al.retainAll(c); @@ -451,7 +451,7 @@ public boolean equals(@Nullable Object o) { /** * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(Predicate filter) { return al.removeIf(filter); diff --git a/src/java.base/share/classes/java/util/concurrent/DelayQueue.java b/src/java.base/share/classes/java/util/concurrent/DelayQueue.java index 54e1cd0118f5a..3549287b5b416 100644 --- a/src/java.base/share/classes/java/util/concurrent/DelayQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/DelayQueue.java @@ -45,7 +45,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import static java.util.concurrent.TimeUnit.NANOSECONDS; @@ -171,7 +171,7 @@ public DelayQueue(Collection c) { * @throws NullPointerException if the specified element is null */ @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { return offer(e); @@ -184,7 +184,7 @@ public boolean add(E e) { * @return {@code true} * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { final ReentrantLock lock = this.lock; @@ -208,7 +208,7 @@ public boolean offer(E e) { * @param e the element to add * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void put(E e) { offer(e); @@ -224,7 +224,7 @@ public void put(E e) { * @return {@code true} * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e, long timeout, TimeUnit unit) { return offer(e); @@ -238,7 +238,7 @@ public boolean offer(E e, long timeout, TimeUnit unit) { * @return the expired head of this queue, or {@code null} if this * queue has no elements with an expired delay */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink DelayQueue this) { final ReentrantLock lock = this.lock; @@ -261,7 +261,7 @@ public boolean offer(E e, long timeout, TimeUnit unit) { * @return the expired head of this queue * @throws InterruptedException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E take(@GuardSatisfied @CanShrink DelayQueue this) throws InterruptedException { final ReentrantLock lock = this.lock; @@ -308,7 +308,7 @@ public E take(@GuardSatisfied @CanShrink DelayQueue this) throws InterruptedE * an expired delay becomes available * @throws InterruptedException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink DelayQueue this, long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); @@ -360,7 +360,7 @@ public E take(@GuardSatisfied @CanShrink DelayQueue this) throws InterruptedE * @throws NoSuchElementException if this queue has no elements with an * expired delay */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove() { return super.remove(); @@ -403,7 +403,7 @@ public int size() { * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink DelayQueue this, Collection c) { return drainTo(c, Integer.MAX_VALUE); @@ -415,7 +415,7 @@ public int drainTo(@GuardSatisfied @CanShrink DelayQueue this, Collection this, Collection c, int maxElements) { Objects.requireNonNull(c); @@ -447,7 +447,7 @@ public int drainTo(@GuardSatisfied @CanShrink DelayQueue this, Collection this) { final ReentrantLock lock = this.lock; @@ -543,7 +543,7 @@ public int remainingCapacity() { * Removes a single instance of the specified element from this * queue, if it is present, whether or not it has expired. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink DelayQueue this, @UnknownSignedness Object o) { final ReentrantLock lock = this.lock; @@ -608,7 +608,7 @@ public boolean hasNext() { } @SuppressWarnings("unchecked") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty Itr this) { if (cursor >= array.length) @@ -616,7 +616,7 @@ public E next(@NonEmpty Itr this) { return (E)array[lastRet = cursor++]; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastRet < 0) diff --git a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java index 3e82a3e0d9a9a..b7d44834f4252 100644 --- a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java +++ b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java @@ -48,7 +48,7 @@ import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; import org.checkerframework.dataflow.qual.Pure; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -332,7 +332,7 @@ void unlink(@CanShrink LinkedBlockingDeque this, Node x) { * @throws IllegalStateException if this deque is full * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addFirst(E e) { if (!offerFirst(e)) @@ -343,7 +343,7 @@ public void addFirst(E e) { * @throws IllegalStateException if this deque is full * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void addLast(E e) { if (!offerLast(e)) @@ -353,7 +353,7 @@ public void addLast(E e) { /** * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offerFirst(E e) { if (e == null) throw new NullPointerException(); @@ -370,7 +370,7 @@ public boolean offerFirst(E e) { /** * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offerLast(E e) { if (e == null) throw new NullPointerException(); @@ -388,7 +388,7 @@ public boolean offerLast(E e) { * @throws NullPointerException {@inheritDoc} * @throws InterruptedException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putFirst(E e) throws InterruptedException { if (e == null) throw new NullPointerException(); @@ -407,7 +407,7 @@ public void putFirst(E e) throws InterruptedException { * @throws NullPointerException {@inheritDoc} * @throws InterruptedException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putLast(E e) throws InterruptedException { if (e == null) throw new NullPointerException(); @@ -426,7 +426,7 @@ public void putLast(E e) throws InterruptedException { * @throws NullPointerException {@inheritDoc} * @throws InterruptedException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException { @@ -451,7 +451,7 @@ public boolean offerFirst(E e, long timeout, TimeUnit unit) * @throws NullPointerException {@inheritDoc} * @throws InterruptedException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offerLast(E e, long timeout, TimeUnit unit) throws InterruptedException { @@ -475,7 +475,7 @@ public boolean offerLast(E e, long timeout, TimeUnit unit) /** * @throws NoSuchElementException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeFirst(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque this) { E x = pollFirst(); @@ -486,7 +486,7 @@ public E removeFirst(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque /** * @throws NoSuchElementException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E removeLast(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque this) { E x = pollLast(); @@ -494,7 +494,7 @@ public E removeLast(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque return x; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollFirst(@GuardSatisfied @CanShrink LinkedBlockingDeque this) { final ReentrantLock lock = this.lock; @@ -506,7 +506,7 @@ public E removeLast(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollLast(@GuardSatisfied @CanShrink LinkedBlockingDeque this) { final ReentrantLock lock = this.lock; @@ -518,7 +518,7 @@ public E removeLast(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E takeFirst(@GuardSatisfied @CanShrink LinkedBlockingDeque this) throws InterruptedException { final ReentrantLock lock = this.lock; @@ -533,7 +533,7 @@ public E takeFirst(@GuardSatisfied @CanShrink LinkedBlockingDeque this) throw } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E takeLast(@GuardSatisfied @CanShrink LinkedBlockingDeque this) throws InterruptedException { final ReentrantLock lock = this.lock; @@ -548,7 +548,7 @@ public E takeLast(@GuardSatisfied @CanShrink LinkedBlockingDeque this) throws } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollFirst(@GuardSatisfied @CanShrink LinkedBlockingDeque this, long timeout, TimeUnit unit) throws InterruptedException { @@ -568,7 +568,7 @@ public E takeLast(@GuardSatisfied @CanShrink LinkedBlockingDeque this) throws } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E pollLast(@GuardSatisfied @CanShrink LinkedBlockingDeque this, long timeout, TimeUnit unit) throws InterruptedException { @@ -628,7 +628,7 @@ public E getLast(@NonEmpty LinkedBlockingDeque this) { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeFirstOccurrence(@CanShrink LinkedBlockingDeque this, Object o) { if (o == null) return false; @@ -647,7 +647,7 @@ public boolean removeFirstOccurrence(@CanShrink LinkedBlockingDeque this, Obj } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeLastOccurrence(@CanShrink LinkedBlockingDeque this, Object o) { if (o == null) return false; @@ -679,7 +679,7 @@ public boolean removeLastOccurrence(@CanShrink LinkedBlockingDeque this, Obje * @throws NullPointerException if the specified element is null */ @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { addLast(e); @@ -689,7 +689,7 @@ public boolean add(E e) { /** * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { return offerLast(e); @@ -699,7 +699,7 @@ public boolean offer(E e) { * @throws NullPointerException {@inheritDoc} * @throws InterruptedException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void put(E e) throws InterruptedException { putLast(e); @@ -709,7 +709,7 @@ public void put(E e) throws InterruptedException { * @throws NullPointerException {@inheritDoc} * @throws InterruptedException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException { @@ -726,25 +726,25 @@ public boolean offer(E e, long timeout, TimeUnit unit) * @return the head of the queue represented by this deque * @throws NoSuchElementException if this deque is empty */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque this) { return removeFirst(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink LinkedBlockingDeque this) { return pollFirst(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E take(@GuardSatisfied @CanShrink LinkedBlockingDeque this) throws InterruptedException { return takeFirst(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink LinkedBlockingDeque this, long timeout, TimeUnit unit) throws InterruptedException { return pollFirst(timeout, unit); @@ -796,7 +796,7 @@ public int remainingCapacity() { * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink LinkedBlockingDeque this, Collection c) { return drainTo(c, Integer.MAX_VALUE); @@ -808,7 +808,7 @@ public int drainTo(@GuardSatisfied @CanShrink LinkedBlockingDeque this, Colle * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink LinkedBlockingDeque this, Collection c, int maxElements) { Objects.requireNonNull(c); @@ -836,7 +836,7 @@ public int drainTo(@GuardSatisfied @CanShrink LinkedBlockingDeque this, Colle * @throws IllegalStateException if this deque is full * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void push(E e) { addFirst(e); @@ -845,7 +845,7 @@ public void push(E e) { /** * @throws NoSuchElementException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E pop(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque this) { return removeFirst(); @@ -867,7 +867,7 @@ public E pop(@GuardSatisfied @NonEmpty @CanShrink LinkedBlockingDeque this) { * @param o element to be removed from this deque, if present * @return {@code true} if this deque changed as a result of the call */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink LinkedBlockingDeque this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { return removeFirstOccurrence(o); @@ -927,7 +927,7 @@ public boolean contains(@GuardSatisfied @Nullable @UnknownSignedness Object o) { * @throws IllegalStateException if this deque is full * @see #add(Object) */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean addAll(Collection c) { if (c == this) @@ -1066,7 +1066,7 @@ public String toString() { * Atomically removes all of the elements from this deque. * The deque will be empty after this call returns. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink LinkedBlockingDeque this) { final ReentrantLock lock = this.lock; @@ -1176,7 +1176,7 @@ public boolean hasNext() { return next != null; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty AbstractItr this) { Node p; @@ -1238,7 +1238,7 @@ public void forEachRemaining(Consumer action) { } while (n > 0 && p != null); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { Node n = lastRet; @@ -1427,7 +1427,7 @@ void forEachFrom(Consumer action, Node p) { /** * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink LinkedBlockingDeque this, Predicate filter) { Objects.requireNonNull(filter); @@ -1437,7 +1437,7 @@ public boolean removeIf(@CanShrink LinkedBlockingDeque this, Predicate this, Collection c) { Objects.requireNonNull(c); @@ -1447,7 +1447,7 @@ public boolean removeAll(@CanShrink LinkedBlockingDeque this, Collection this, Collection c) { Objects.requireNonNull(c); diff --git a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java index 871e06a13f53d..2fb3859c80b9c 100644 --- a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java @@ -47,7 +47,7 @@ import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; import org.checkerframework.dataflow.qual.Pure; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -341,7 +341,7 @@ public int remainingCapacity() { * @throws InterruptedException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void put(E e) throws InterruptedException { if (e == null) throw new NullPointerException(); @@ -382,7 +382,7 @@ public void put(E e) throws InterruptedException { * @throws InterruptedException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException { @@ -422,7 +422,7 @@ public boolean offer(E e, long timeout, TimeUnit unit) * * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { if (e == null) throw new NullPointerException(); @@ -448,7 +448,7 @@ public boolean offer(E e) { return true; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E take(@GuardSatisfied @CanShrink LinkedBlockingQueue this) throws InterruptedException { final E x; @@ -472,7 +472,7 @@ public E take(@GuardSatisfied @CanShrink LinkedBlockingQueue this) throws Int return x; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink LinkedBlockingQueue this, long timeout, TimeUnit unit) throws InterruptedException { final E x; @@ -499,7 +499,7 @@ public E take(@GuardSatisfied @CanShrink LinkedBlockingQueue this) throws Int return x; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink LinkedBlockingQueue this) { final AtomicInteger count = this.count; @@ -565,7 +565,7 @@ void unlink(Node p, Node pred) { * @param o element to be removed from this queue, if present * @return {@code true} if this queue changed as a result of the call */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink LinkedBlockingQueue this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { if (o == null) return false; @@ -698,7 +698,7 @@ public String toString() { * Atomically removes all of the elements from this queue. * The queue will be empty after this call returns. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink LinkedBlockingQueue this) { fullyLock(); @@ -722,7 +722,7 @@ public void clear(@GuardSatisfied @CanShrink LinkedBlockingQueue this) { * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink LinkedBlockingQueue this, Collection c) { return drainTo(c, Integer.MAX_VALUE); @@ -734,7 +734,7 @@ public int drainTo(@GuardSatisfied @CanShrink LinkedBlockingQueue this, Colle * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink LinkedBlockingQueue this, Collection c, int maxElements) { Objects.requireNonNull(c); @@ -829,7 +829,7 @@ public boolean hasNext() { return next != null; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(@NonEmpty Itr this) { Node p; @@ -889,7 +889,7 @@ public void forEachRemaining(Consumer action) { } while (n > 0 && p != null); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { Node p = lastRet; @@ -1064,7 +1064,7 @@ void forEachFrom(Consumer action, Node p) { /** * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink LinkedBlockingQueue this, Predicate filter) { Objects.requireNonNull(filter); @@ -1074,7 +1074,7 @@ public boolean removeIf(@CanShrink LinkedBlockingQueue this, Predicate this, Collection c) { Objects.requireNonNull(c); @@ -1084,7 +1084,7 @@ public boolean removeAll(@CanShrink LinkedBlockingQueue this, Collection this, Collection c) { Objects.requireNonNull(c); diff --git a/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java b/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java index c7448a8f93fcb..f885f950bc28f 100644 --- a/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java @@ -48,7 +48,7 @@ import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; import org.checkerframework.dataflow.qual.Pure; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.lang.invoke.MethodHandles; @@ -924,7 +924,7 @@ public final boolean hasNext() { return nextNode != null; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final E next(@NonEmpty Itr this) { final Node p; @@ -943,7 +943,7 @@ public void forEachRemaining(Consumer action) { lastRet = q; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public final void remove() { final Node lastRet = this.lastRet; @@ -1206,7 +1206,7 @@ public LinkedTransferQueue(Collection c) { * * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void put(E e) { xfer(e, true, ASYNC, 0L); @@ -1221,7 +1221,7 @@ public void put(E e) { * {@link BlockingQueue#offer(Object,long,TimeUnit) BlockingQueue.offer}) * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e, long timeout, TimeUnit unit) { xfer(e, true, ASYNC, 0L); @@ -1235,7 +1235,7 @@ public boolean offer(E e, long timeout, TimeUnit unit) { * @return {@code true} (as specified by {@link Queue#offer}) * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { xfer(e, true, ASYNC, 0L); @@ -1251,7 +1251,7 @@ public boolean offer(E e) { * @throws NullPointerException if the specified element is null */ @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { xfer(e, true, ASYNC, 0L); @@ -1268,7 +1268,7 @@ public boolean add(E e) { * * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean tryTransfer(@GuardSatisfied @CanShrink LinkedTransferQueue this, E e) { return xfer(e, true, NOW, 0L) == null; @@ -1285,7 +1285,7 @@ public boolean tryTransfer(@GuardSatisfied @CanShrink LinkedTransferQueue thi * * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void transfer(@GuardSatisfied @CanShrink LinkedTransferQueue this, E e) throws InterruptedException { if (xfer(e, true, SYNC, 0L) != null) { @@ -1308,7 +1308,7 @@ public void transfer(@GuardSatisfied @CanShrink LinkedTransferQueue this, E e * * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean tryTransfer(@GuardSatisfied @CanShrink LinkedTransferQueue this, E e, long timeout, TimeUnit unit) throws InterruptedException { @@ -1319,7 +1319,7 @@ public boolean tryTransfer(@GuardSatisfied @CanShrink LinkedTransferQueue thi throw new InterruptedException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E take(@GuardSatisfied @CanShrink LinkedTransferQueue this) throws InterruptedException { E e = xfer(null, false, SYNC, 0L); @@ -1329,7 +1329,7 @@ public E take(@GuardSatisfied @CanShrink LinkedTransferQueue this) throws Int throw new InterruptedException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E poll(@GuardSatisfied @CanShrink LinkedTransferQueue this, long timeout, TimeUnit unit) throws InterruptedException { E e = xfer(null, false, TIMED, unit.toNanos(timeout)); @@ -1338,7 +1338,7 @@ public E poll(@GuardSatisfied @CanShrink LinkedTransferQueue this, long timeo throw new InterruptedException(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E poll(@GuardSatisfied @CanShrink LinkedTransferQueue this) { return xfer(null, false, NOW, 0L); @@ -1348,7 +1348,7 @@ public E poll(@GuardSatisfied @CanShrink LinkedTransferQueue this) { * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink LinkedTransferQueue this, Collection c) { Objects.requireNonNull(c); @@ -1364,7 +1364,7 @@ public int drainTo(@GuardSatisfied @CanShrink LinkedTransferQueue this, Colle * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink LinkedTransferQueue this, Collection c, int maxElements) { Objects.requireNonNull(c); @@ -1469,7 +1469,7 @@ public int getWaitingConsumerCount() { * @param o element to be removed from this queue, if present * @return {@code true} if this queue changed as a result of the call */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink LinkedTransferQueue this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { if (o == null) return false; @@ -1591,7 +1591,7 @@ private void readObject(java.io.ObjectInputStream s) /** * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink LinkedTransferQueue this, Predicate filter) { Objects.requireNonNull(filter); @@ -1601,7 +1601,7 @@ public boolean removeIf(@CanShrink LinkedTransferQueue this, Predicate this, Collection c) { Objects.requireNonNull(c); @@ -1611,14 +1611,14 @@ public boolean removeAll(@CanShrink LinkedTransferQueue this, Collection this, Collection c) { Objects.requireNonNull(c); return bulkRemove(e -> !c.contains(e)); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink LinkedTransferQueue this) { bulkRemove(e -> true); diff --git a/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java index ca6d893f3fa50..ddf86b3f52f06 100644 --- a/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java @@ -48,7 +48,7 @@ import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; import org.checkerframework.dataflow.qual.Pure; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -464,7 +464,7 @@ private void heapify() { * @throws NullPointerException if the specified element is null */ @EnsuresNonEmpty("this") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean add(E e) { return offer(e); @@ -481,7 +481,7 @@ public boolean add(E e) { * priority queue's ordering * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { if (e == null) @@ -516,7 +516,7 @@ public boolean offer(E e) { * priority queue's ordering * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void put(E e) { offer(e); // never need to block @@ -537,13 +537,13 @@ public void put(E e) { * priority queue's ordering * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e, long timeout, TimeUnit unit) { return offer(e); // never need to block } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink PriorityBlockingQueue this) { final ReentrantLock lock = this.lock; @@ -555,7 +555,7 @@ public boolean offer(E e, long timeout, TimeUnit unit) { } } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E take(@GuardSatisfied @CanShrink PriorityBlockingQueue this) throws InterruptedException { final ReentrantLock lock = this.lock; @@ -570,7 +570,7 @@ public E take(@GuardSatisfied @CanShrink PriorityBlockingQueue this) throws I return result; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public @Nullable E poll(@GuardSatisfied @CanShrink PriorityBlockingQueue this, long timeout, TimeUnit unit) throws InterruptedException { long nanos = unit.toNanos(timeout); @@ -677,7 +677,7 @@ private void removeAt(int i) { * @param o element to be removed from this queue, if present * @return {@code true} if this queue changed as a result of the call */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink PriorityBlockingQueue this, @Nullable @UnknownSignedness Object o) { final ReentrantLock lock = this.lock; @@ -744,7 +744,7 @@ public String toString() { * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink PriorityBlockingQueue this, Collection c) { return drainTo(c, Integer.MAX_VALUE); @@ -756,7 +756,7 @@ public int drainTo(@GuardSatisfied @CanShrink PriorityBlockingQueue this, Col * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink PriorityBlockingQueue this, Collection c, int maxElements) { Objects.requireNonNull(c); @@ -782,7 +782,7 @@ public int drainTo(@GuardSatisfied @CanShrink PriorityBlockingQueue this, Col * Atomically removes all of the elements from this queue. * The queue will be empty after this call returns. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink PriorityBlockingQueue this) { final ReentrantLock lock = this.lock; @@ -904,14 +904,14 @@ public boolean hasNext() { return cursor < array.length; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public E next(@NonEmpty Itr this) { if (cursor >= array.length) throw new NoSuchElementException(); return (E)array[lastRet = cursor++]; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void remove() { if (lastRet < 0) @@ -1058,7 +1058,7 @@ public Spliterator spliterator() { /** * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeIf(@CanShrink PriorityBlockingQueue this, Predicate filter) { Objects.requireNonNull(filter); @@ -1068,7 +1068,7 @@ public boolean removeIf(@CanShrink PriorityBlockingQueue this, Predicate this, Collection c) { Objects.requireNonNull(c); @@ -1078,7 +1078,7 @@ public boolean removeAll(@CanShrink PriorityBlockingQueue this, Collection this, Collection c) { Objects.requireNonNull(c); diff --git a/src/java.base/share/classes/java/util/concurrent/ScheduledThreadPoolExecutor.java b/src/java.base/share/classes/java/util/concurrent/ScheduledThreadPoolExecutor.java index 2e9822843421e..a2eee3f15babb 100644 --- a/src/java.base/share/classes/java/util/concurrent/ScheduledThreadPoolExecutor.java +++ b/src/java.base/share/classes/java/util/concurrent/ScheduledThreadPoolExecutor.java @@ -42,7 +42,7 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; import org.checkerframework.dataflow.qual.Pure; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import static java.util.concurrent.TimeUnit.MILLISECONDS; @@ -1352,7 +1352,7 @@ public boolean hasNext() { return cursor < array.length; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Runnable next(@NonEmpty Itr this) { if (cursor >= array.length) diff --git a/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java b/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java index 40fb1f960b5f8..5c402e9431221 100644 --- a/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java @@ -850,7 +850,7 @@ public SynchronousQueue(boolean fair) { * @throws InterruptedException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void put(E e) throws InterruptedException { if (e == null) throw new NullPointerException(); @@ -869,7 +869,7 @@ public void put(E e) throws InterruptedException { * @throws InterruptedException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException { @@ -890,7 +890,7 @@ public boolean offer(E e, long timeout, TimeUnit unit) * {@code false} * @throws NullPointerException if the specified element is null */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean offer(E e) { if (e == null) throw new NullPointerException(); @@ -904,7 +904,7 @@ public boolean offer(E e) { * @return the head of this queue * @throws InterruptedException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E take(@GuardSatisfied @CanShrink SynchronousQueue this) throws InterruptedException { E e = transferer.transfer(null, false, 0); @@ -923,7 +923,7 @@ public E take(@GuardSatisfied @CanShrink SynchronousQueue this) throws Interr * specified waiting time elapses before an element is present * @throws InterruptedException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E poll(@GuardSatisfied @CanShrink SynchronousQueue this, long timeout, TimeUnit unit) throws InterruptedException { E e = transferer.transfer(null, true, unit.toNanos(timeout)); @@ -939,7 +939,7 @@ public E poll(@GuardSatisfied @CanShrink SynchronousQueue this, long timeout, * @return the head of this queue, or {@code null} if no * element is available */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E poll(@GuardSatisfied @CanShrink SynchronousQueue this) { return transferer.transfer(null, true, 0); @@ -982,7 +982,7 @@ public int remainingCapacity() { * Does nothing. * A {@code SynchronousQueue} has no internal capacity. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear(@GuardSatisfied @CanShrink SynchronousQueue this) { } @@ -1007,7 +1007,7 @@ public boolean contains(@GuardSatisfied @Nullable @UnknownSignedness Object o) { * @param o the element to remove * @return {@code false} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean remove(@CanShrink SynchronousQueue this, @GuardSatisfied @Nullable @UnknownSignedness Object o) { return false; @@ -1032,7 +1032,7 @@ public boolean containsAll(Collection c) { * @param c the collection * @return {@code false} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean removeAll(@CanShrink SynchronousQueue this, Collection c) { return false; @@ -1045,7 +1045,7 @@ public boolean removeAll(@CanShrink SynchronousQueue this, Collection this, Collection c) { return false; @@ -1124,7 +1124,7 @@ public String toString() { * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink SynchronousQueue this, Collection c) { Objects.requireNonNull(c); @@ -1142,7 +1142,7 @@ public int drainTo(@GuardSatisfied @CanShrink SynchronousQueue this, Collecti * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public int drainTo(@GuardSatisfied @CanShrink SynchronousQueue this, Collection c, int maxElements) { Objects.requireNonNull(c); diff --git a/src/java.base/share/classes/java/util/jar/Attributes.java b/src/java.base/share/classes/java/util/jar/Attributes.java index 4bd951b03173b..6e73d6ac15725 100644 --- a/src/java.base/share/classes/java/util/jar/Attributes.java +++ b/src/java.base/share/classes/java/util/jar/Attributes.java @@ -175,7 +175,7 @@ public String getValue(Name name) { * @throws ClassCastException if the name is not a Attributes.Name * or the value is not a String */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Object put(Object name, Object value) { return map.put((Attributes.Name)name, (String)value); @@ -208,7 +208,7 @@ public String putValue(String name, String value) { * @param name attribute name * @return the previous value of the attribute, or null if none */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public Object remove(@GuardSatisfied @Nullable @UnknownSignedness Object name) { return map.remove(name); @@ -245,7 +245,7 @@ public boolean containsKey(@GuardSatisfied @Nullable @UnknownSignedness Object n * @param attr the Attributes to be stored in this map * @throws ClassCastException if attr is not an Attributes */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void putAll(Map attr) { // ## javac bug? @@ -258,7 +258,7 @@ public void putAll(Map attr) { /** * Removes all attributes from this Map. */ - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { map.clear(); diff --git a/src/java.base/share/classes/java/util/regex/Matcher.java b/src/java.base/share/classes/java/util/regex/Matcher.java index 801ef291d3f41..85b57adefe8e6 100644 --- a/src/java.base/share/classes/java/util/regex/Matcher.java +++ b/src/java.base/share/classes/java/util/regex/Matcher.java @@ -35,7 +35,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -1356,7 +1356,7 @@ class MatchResultIterator implements Iterator { int expectedCount = -1; @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public MatchResult next(@NonEmpty MatchResultIterator this) { if (expectedCount >= 0 && expectedCount != modCount) diff --git a/src/java.base/share/classes/java/util/regex/Pattern.java b/src/java.base/share/classes/java/util/regex/Pattern.java index ea22bef401a8f..bdd31f0d613f4 100644 --- a/src/java.base/share/classes/java/util/regex/Pattern.java +++ b/src/java.base/share/classes/java/util/regex/Pattern.java @@ -35,7 +35,7 @@ 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.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -6086,7 +6086,7 @@ class MatcherIterator implements Iterator { // > 0 if there are N next empty elements private int emptyElementCount; - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public String next(@NonEmpty MatcherIterator this) { if (!hasNext()) diff --git a/src/java.base/share/classes/java/util/zip/ZipFile.java b/src/java.base/share/classes/java/util/zip/ZipFile.java index d318e73aa21d0..282978d2f4c85 100644 --- a/src/java.base/share/classes/java/util/zip/ZipFile.java +++ b/src/java.base/share/classes/java/util/zip/ZipFile.java @@ -36,7 +36,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.signedness.qual.SignedPositive; import org.checkerframework.dataflow.qual.Pure; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -523,7 +523,7 @@ public boolean hasNext() { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public T nextElement(@NonEmpty ZipEntryIterator this) { return next(); @@ -531,7 +531,7 @@ public T nextElement(@NonEmpty ZipEntryIterator this) { @Override @SuppressWarnings("unchecked") - @SideEffectsOnly("this") + // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public T next(@NonEmpty ZipEntryIterator this) { synchronized (ZipFile.this) { diff --git a/src/java.base/share/classes/javax/security/auth/Subject.java b/src/java.base/share/classes/javax/security/auth/Subject.java index 54a8c778242ea..0c5c919bf02a3 100644 --- a/src/java.base/share/classes/javax/security/auth/Subject.java +++ b/src/java.base/share/classes/javax/security/auth/Subject.java @@ -34,7 +34,7 @@ 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.dataflow.qual.SideEffectsOnly; import java.io.IOException; import java.io.ObjectInputStream; @@ -1207,7 +1207,7 @@ public boolean hasNext() { return i.hasNext(); } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public E next(/*@NonEmpty Iterator this*/) { if (which != Subject.PRIV_CREDENTIAL_SET) { return i.next(); diff --git a/src/java.base/share/classes/jdk/internal/icu/text/Replaceable.java b/src/java.base/share/classes/jdk/internal/icu/text/Replaceable.java index ebbf633f01a90..e35b3d86b6794 100644 --- a/src/java.base/share/classes/jdk/internal/icu/text/Replaceable.java +++ b/src/java.base/share/classes/jdk/internal/icu/text/Replaceable.java @@ -38,7 +38,7 @@ package jdk.internal.icu.text; import org.checkerframework.dataflow.qual.SideEffectFree; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; /** * Replaceable is an interface representing a diff --git a/src/java.base/share/classes/jdk/internal/icu/text/ReplaceableString.java b/src/java.base/share/classes/jdk/internal/icu/text/ReplaceableString.java index dfdfafb0cbfc8..b65bb18779dc1 100644 --- a/src/java.base/share/classes/jdk/internal/icu/text/ReplaceableString.java +++ b/src/java.base/share/classes/jdk/internal/icu/text/ReplaceableString.java @@ -33,7 +33,7 @@ package jdk.internal.icu.text; import org.checkerframework.dataflow.qual.SideEffectFree; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; /** * ReplaceableString is an adapter class that implements the diff --git a/src/java.base/share/classes/sun/net/www/HeaderParser.java b/src/java.base/share/classes/sun/net/www/HeaderParser.java index 2dc8d09fa18ac..6e6fff53188fe 100644 --- a/src/java.base/share/classes/sun/net/www/HeaderParser.java +++ b/src/java.base/share/classes/sun/net/www/HeaderParser.java @@ -26,7 +26,7 @@ package sun.net.www; import org.checkerframework.dataflow.qual.Pure; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.Iterator; @@ -209,7 +209,7 @@ class ParserIterator implements Iterator { public boolean hasNext () { return index next() { return new Map.Entry() { String k = i.next(); diff --git a/src/java.base/share/classes/sun/util/locale/StringTokenIterator.java b/src/java.base/share/classes/sun/util/locale/StringTokenIterator.java index 7d0ab20964113..5d1d4aa12c2b1 100644 --- a/src/java.base/share/classes/sun/util/locale/StringTokenIterator.java +++ b/src/java.base/share/classes/sun/util/locale/StringTokenIterator.java @@ -31,7 +31,7 @@ package sun.util.locale; import org.checkerframework.dataflow.qual.Pure; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; public class StringTokenIterator { private String text; @@ -74,7 +74,7 @@ public boolean isDone() { return done; } - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public String next() { if (hasNext()) { start = end + 1; diff --git a/src/java.base/share/classes/sun/util/resources/ParallelListResourceBundle.java b/src/java.base/share/classes/sun/util/resources/ParallelListResourceBundle.java index e372d57d22263..0de7491fc9c2f 100644 --- a/src/java.base/share/classes/sun/util/resources/ParallelListResourceBundle.java +++ b/src/java.base/share/classes/sun/util/resources/ParallelListResourceBundle.java @@ -28,7 +28,7 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.signedness.qual.UnknownSignedness; import org.checkerframework.dataflow.qual.Pure; -import org.checkerframework.dataflow.qual.SideEffectsOnly; +// import org.checkerframework.dataflow.qual.SideEffectsOnly; import java.util.AbstractSet; import java.util.Collections; @@ -240,7 +240,7 @@ public boolean hasNext() { } @Override - @SideEffectsOnly("this") + // @SideEffectsOnly("this") public String next() { if (hasNext()) { return itr.next(); From 1d08f20d10457ee9ec158a3963908adbf87dc25e Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 19 May 2026 13:09:29 -0700 Subject: [PATCH 08/15] Remove incorrect `@SideEffectsOnly` annotations --- src/java.base/share/classes/java/util/Properties.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/java.base/share/classes/java/util/Properties.java b/src/java.base/share/classes/java/util/Properties.java index a877b1a0cdc4a..407b6ab699e30 100644 --- a/src/java.base/share/classes/java/util/Properties.java +++ b/src/java.base/share/classes/java/util/Properties.java @@ -1550,7 +1550,6 @@ public synchronized Object replace(Object key, Object value) { } @Override - // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized @PolyNull Object computeIfAbsent(Object key, Function mappingFunction) { @@ -1558,7 +1557,6 @@ public synchronized Object replace(Object key, Object value) { } @Override - // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized @PolyNull Object computeIfPresent(Object key, BiFunction remappingFunction) { @@ -1566,7 +1564,6 @@ public synchronized Object replace(Object key, Object value) { } @Override - // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public synchronized @PolyNull Object compute(Object key, BiFunction remappingFunction) { From 59902fc04d60735e56941335eed179ef96aa9091 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 19 May 2026 13:18:15 -0700 Subject: [PATCH 09/15] Methods that take a function as an argument --- src/java.base/share/classes/java/security/Provider.java | 6 ++++++ src/java.base/share/classes/java/util/List.java | 1 + .../share/classes/java/util/ReverseOrderListView.java | 2 ++ .../share/classes/com/sun/net/httpserver/Headers.java | 2 ++ 4 files changed, 11 insertions(+) diff --git a/src/java.base/share/classes/java/security/Provider.java b/src/java.base/share/classes/java/security/Provider.java index 22ebc08a5c8a4..9cba2a016e10a 100644 --- a/src/java.base/share/classes/java/security/Provider.java +++ b/src/java.base/share/classes/java/security/Provider.java @@ -28,6 +28,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.UnknownSignedness; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import jdk.internal.event.SecurityProviderServiceEvent; @@ -635,6 +636,7 @@ public synchronized Object replace(Object key, Object value) { * @since 1.8 */ @Override + @DoesNotUnrefineReceiver("modifiability") public synchronized void replaceAll(BiFunction function) { check("putProviderProperty." + name); @@ -663,6 +665,7 @@ public synchronized void replaceAll(BiFunction remappingFunction) { check("putProviderProperty." + name); @@ -693,6 +696,7 @@ public synchronized void replaceAll(BiFunction mappingFunction) { check("putProviderProperty." + name); @@ -722,6 +726,7 @@ public synchronized void replaceAll(BiFunction remappingFunction) { @@ -755,6 +760,7 @@ public synchronized void replaceAll(BiFunction remappingFunction) { diff --git a/src/java.base/share/classes/java/util/List.java b/src/java.base/share/classes/java/util/List.java index 56524e6e35d08..f7d60fab9f4c3 100644 --- a/src/java.base/share/classes/java/util/List.java +++ b/src/java.base/share/classes/java/util/List.java @@ -486,6 +486,7 @@ public interface List extends SequencedCollection { * (optional) * @since 1.8 */ + @DoesNotUnrefineReceiver("modifiability") default void replaceAll(UnaryOperator operator) { Objects.requireNonNull(operator); final ListIterator li = this.listIterator(); diff --git a/src/java.base/share/classes/java/util/ReverseOrderListView.java b/src/java.base/share/classes/java/util/ReverseOrderListView.java index 0f7409bef16d0..44139d8278e1b 100644 --- a/src/java.base/share/classes/java/util/ReverseOrderListView.java +++ b/src/java.base/share/classes/java/util/ReverseOrderListView.java @@ -26,6 +26,7 @@ package java.util; import java.util.Objects; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.function.Consumer; import java.util.function.IntFunction; import java.util.function.Predicate; @@ -374,6 +375,7 @@ public boolean removeIf(Predicate filter) { return base.removeIf(filter); } + @DoesNotUnrefineReceiver("modifiability") public void replaceAll(UnaryOperator operator) { checkModifiable(); base.replaceAll(operator); diff --git a/src/jdk.httpserver/share/classes/com/sun/net/httpserver/Headers.java b/src/jdk.httpserver/share/classes/com/sun/net/httpserver/Headers.java index 4c82b904d5f9d..596c8ad22261a 100644 --- a/src/jdk.httpserver/share/classes/com/sun/net/httpserver/Headers.java +++ b/src/jdk.httpserver/share/classes/com/sun/net/httpserver/Headers.java @@ -26,6 +26,7 @@ package com.sun.net.httpserver; import org.checkerframework.dataflow.qual.Pure; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.Arrays; import java.util.Collection; @@ -263,6 +264,7 @@ public Set>> entrySet() { } @Override + @DoesNotUnrefineReceiver("modifiability") public void replaceAll(BiFunction, ? extends List> function) { var f = function.andThen(values -> { Objects.requireNonNull(values); From beda6f18d0de0c14ac8bde2db40fec5bfc6e2ffb Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 19 May 2026 16:21:55 -0700 Subject: [PATCH 10/15] Checkpoint --- .../share/classes/java/util/AbstractList.java | 5 ++ .../share/classes/java/util/AbstractMap.java | 6 ++ .../share/classes/java/util/ArrayDeque.java | 3 + .../share/classes/java/util/ArrayList.java | 15 ++++ .../share/classes/java/util/Collections.java | 79 +++++++++++++++++++ .../share/classes/java/util/EnumMap.java | 9 +++ .../share/classes/java/util/HashMap.java | 4 + .../share/classes/java/util/Hashtable.java | 5 ++ .../classes/java/util/IdentityHashMap.java | 6 ++ .../java/util/ImmutableCollections.java | 30 +++++++ .../classes/java/util/LinkedHashMap.java | 15 ++++ .../classes/java/util/LinkedHashSet.java | 4 + .../share/classes/java/util/LinkedList.java | 22 ++++++ .../share/classes/java/util/Properties.java | 6 ++ .../classes/java/util/ServiceLoader.java | 3 + .../share/classes/java/util/SortedSet.java | 2 + .../share/classes/java/util/TreeMap.java | 10 +++ .../share/classes/java/util/Vector.java | 5 ++ .../share/classes/java/util/WeakHashMap.java | 4 + .../util/concurrent/ConcurrentHashMap.java | 18 +++++ .../concurrent/ConcurrentLinkedDeque.java | 3 + .../concurrent/ConcurrentSkipListMap.java | 7 ++ .../util/concurrent/CopyOnWriteArrayList.java | 34 ++++++++ .../util/concurrent/LinkedBlockingDeque.java | 3 + .../concurrent/PriorityBlockingQueue.java | 2 + .../ScheduledThreadPoolExecutor.java | 1 + .../classes/java/util/jar/Attributes.java | 6 ++ .../share/classes/java/util/zip/ZipFile.java | 4 + 28 files changed, 311 insertions(+) diff --git a/src/java.base/share/classes/java/util/AbstractList.java b/src/java.base/share/classes/java/util/AbstractList.java index c5e394168c8e1..423db23761629 100644 --- a/src/java.base/share/classes/java/util/AbstractList.java +++ b/src/java.base/share/classes/java/util/AbstractList.java @@ -452,6 +452,7 @@ private class ListItr extends Itr implements ListIterator { cursor = index; } + @Pure public boolean hasPrevious() { return cursor != 0; } @@ -469,10 +470,12 @@ public E previous() { } } + @Pure public int nextIndex() { return cursor; } + @Pure public int previousIndex() { return cursor-1; } @@ -786,6 +789,7 @@ public int characteristics() { return Spliterator.ORDERED | Spliterator.SIZED | Spliterator.SUBSIZED; } + @Pure private static E get(List list, int i) { try { return list.get(i); @@ -838,6 +842,7 @@ public E set(int index, E element) { return root.set(offset + index, element); } + @Pure public E get(int index) { Objects.checkIndex(index, size); checkForComodification(); diff --git a/src/java.base/share/classes/java/util/AbstractMap.java b/src/java.base/share/classes/java/util/AbstractMap.java index 70a70fe2dcae0..ec20d28ca4421 100644 --- a/src/java.base/share/classes/java/util/AbstractMap.java +++ b/src/java.base/share/classes/java/util/AbstractMap.java @@ -431,6 +431,7 @@ public void clear() { } @EnsuresNonEmptyIf(result = true, expression = "this") + @Pure public boolean contains(@UnknownSignedness Object k) { return AbstractMap.this.containsKey(k); } @@ -503,6 +504,7 @@ public void clear() { } @EnsuresNonEmptyIf(result = true, expression = "this") + @Pure public boolean contains(@UnknownSignedness Object v) { return AbstractMap.this.containsValue(v); } @@ -991,9 +993,12 @@ public String toString(AbstractMap.@GuardSatisfied SimpleImmutableEntry th // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { view().clear(); } + @Pure public boolean contains(Object o) { return view().contains(o); } + @Pure public boolean containsAll(Collection c) { return view().containsAll(c); } public void forEach(Consumer c) { view().forEach(c); } + @Pure public boolean isEmpty() { return view().isEmpty(); } public Iterator iterator() { return view().iterator(); } public Stream parallelStream() { return view().parallelStream(); } @@ -1009,6 +1014,7 @@ public String toString(AbstractMap.@GuardSatisfied SimpleImmutableEntry th // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public boolean retainAll(Collection c) { return view().retainAll(c); } + @Pure public int size() { return view().size(); } public Spliterator spliterator() { return view().spliterator(); } public Stream stream() { return view().stream(); } diff --git a/src/java.base/share/classes/java/util/ArrayDeque.java b/src/java.base/share/classes/java/util/ArrayDeque.java index b005423e281db..ab4ab1881f697 100644 --- a/src/java.base/share/classes/java/util/ArrayDeque.java +++ b/src/java.base/share/classes/java/util/ArrayDeque.java @@ -435,6 +435,7 @@ public E removeLast(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { /** * @throws NoSuchElementException {@inheritDoc} */ + @Pure public E getFirst(@GuardSatisfied @NonEmpty ArrayDeque this) { E e = elementAt(elements, head); if (e == null) @@ -445,6 +446,7 @@ public E getFirst(@GuardSatisfied @NonEmpty ArrayDeque this) { /** * @throws NoSuchElementException {@inheritDoc} */ + @Pure public E getLast(@GuardSatisfied @NonEmpty ArrayDeque this) { final Object[] es = elements; E e = elementAt(es, dec(tail, es.length)); @@ -601,6 +603,7 @@ public E remove(@GuardSatisfied @NonEmpty @CanShrink ArrayDeque this) { * @return the head of the queue represented by this deque * @throws NoSuchElementException {@inheritDoc} */ + @Pure public E element(@GuardSatisfied @NonEmpty ArrayDeque this) { return getFirst(); } diff --git a/src/java.base/share/classes/java/util/ArrayList.java b/src/java.base/share/classes/java/util/ArrayList.java index 2375ea57ade26..5393cace995ed 100644 --- a/src/java.base/share/classes/java/util/ArrayList.java +++ b/src/java.base/share/classes/java/util/ArrayList.java @@ -472,6 +472,7 @@ public E get(@GuardSatisfied ArrayList this, @NonNegative int index) { * @throws NoSuchElementException {@inheritDoc} * @since 21 */ + @Pure public E getFirst() { if (size == 0) { throw new NoSuchElementException(); @@ -486,6 +487,7 @@ public E getFirst() { * @throws NoSuchElementException {@inheritDoc} * @since 21 */ + @Pure public E getLast() { int last = size - 1; if (last < 0) { @@ -718,6 +720,7 @@ private void checkForComodification(final int expectedModCount) { /** * {@inheritDoc} */ + @Pure public int hashCode() { int expectedModCount = modCount; int hash = hashCodeRange(0, size); @@ -1184,18 +1187,21 @@ private class ListItr extends Itr implements ListIterator { cursor = index; } + @Pure public boolean hasPrevious() { return cursor != 0; } // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") + @Pure public int nextIndex() { return cursor; } // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") + @Pure public int previousIndex() { return cursor - 1; } @@ -1320,6 +1326,7 @@ public E set(@NonNegative int index, E element) { return oldValue; } + @Pure public E get(@NonNegative int index) { Objects.checkIndex(index, size); checkForComodification(); @@ -1433,6 +1440,7 @@ public boolean removeIf(Predicate filter) { return a; } + @Pure public boolean equals(@Nullable Object o) { if (o == this) { return true; @@ -1447,18 +1455,21 @@ public boolean equals(@Nullable Object o) { return equal; } + @Pure public int hashCode() { int hash = root.hashCodeRange(offset, offset + size); checkForComodification(); return hash; } + @Pure public int indexOf(@GuardSatisfied @Nullable @UnknownSignedness Object o) { int index = root.indexOfRange(o, offset, offset + size); checkForComodification(); return index >= 0 ? index - offset : -1; } + @Pure public int lastIndexOf(@GuardSatisfied @Nullable @UnknownSignedness Object o) { int index = root.lastIndexOfRange(o, offset, offset + size); checkForComodification(); @@ -1466,6 +1477,7 @@ public int lastIndexOf(@GuardSatisfied @Nullable @UnknownSignedness Object o) { } @EnsuresNonEmptyIf(result = true, expression = "this") + @Pure public boolean contains(@Nullable @UnknownSignedness Object o) { return indexOf(o) >= 0; } @@ -1504,6 +1516,7 @@ public E next(/*@NonEmpty ListIterator this*/) { return (E) elementData[offset + (lastRet = i)]; } + @Pure public boolean hasPrevious() { return cursor != 0; } @@ -1538,10 +1551,12 @@ public void forEachRemaining(Consumer action) { } } + @Pure public int nextIndex() { return cursor; } + @Pure public int previousIndex() { return cursor - 1; } diff --git a/src/java.base/share/classes/java/util/Collections.java b/src/java.base/share/classes/java/util/Collections.java index 01197ac12ca44..88678893f7cb7 100644 --- a/src/java.base/share/classes/java/util/Collections.java +++ b/src/java.base/share/classes/java/util/Collections.java @@ -291,6 +291,7 @@ else if (cmp > 0) * Gets the ith element from the given list by repositioning the specified * list listIterator. */ + @Pure private static T get(ListIterator i, int index) { T obj; int pos = i.nextIndex(); @@ -1281,10 +1282,12 @@ public void addLast(E e) { throw new UnsupportedOperationException(); } + @Pure public E getFirst() { return sc().getFirst(); } + @Pure public E getLast() { return sc().getLast(); } @@ -1335,7 +1338,9 @@ static class UnmodifiableSet extends UnmodifiableCollection private static final long serialVersionUID = -9215047833775013803L; UnmodifiableSet(Set s) {super(s);} + @Pure public boolean equals(Object o) {return o == this || c.equals(o);} + @Pure public int hashCode() {return c.hashCode();} } @@ -1373,7 +1378,9 @@ static class UnmodifiableSequencedSet extends UnmodifiableSequencedCollection private static final long serialVersionUID = -2153469532349793522L; UnmodifiableSequencedSet(SequencedSet s) {super(s);} + @Pure public boolean equals(Object o) {return o == this || c.equals(o);} + @Pure public int hashCode() {return c.hashCode();} @SuppressWarnings("unchecked") @@ -1429,6 +1436,7 @@ static class UnmodifiableSortedSet UnmodifiableSortedSet(SortedSet s) {super(s); ss = s;} + @Pure public Comparator comparator() {return ss.comparator();} // @SideEffectsOnly("this") @@ -1604,9 +1612,12 @@ static class UnmodifiableList extends UnmodifiableCollection this.list = list; } + @Pure public boolean equals(Object o) {return o == this || list.equals(o);} + @Pure public int hashCode() {return list.hashCode();} + @Pure public E get(int index) {return list.get(index);} // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @@ -1623,7 +1634,9 @@ public void add(int index, E element) { public E remove(int index) { throw new UnsupportedOperationException(); } + @Pure public int indexOf(Object o) {return list.indexOf(o);} + @Pure public int lastIndexOf(Object o) {return list.lastIndexOf(o);} // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @@ -1840,7 +1853,9 @@ public Collection values() { return values; } + @Pure public boolean equals(Object o) {return o == this || m.equals(o);} + @Pure public int hashCode() {return m.hashCode();} public String toString() {return m.toString();} @@ -2078,6 +2093,7 @@ public Object[] toArray() { * setValue method. */ @EnsuresNonEmptyIf(result = true, expression = "this") + @Pure public boolean contains(@UnknownSignedness Object o) { if (!(o instanceof Map.Entry)) return false; @@ -2098,6 +2114,7 @@ public boolean containsAll(Collection coll) } return true; } + @Pure public boolean equals(Object o) { if (o == this) return true; @@ -2120,12 +2137,16 @@ private static class UnmodifiableEntry implements Map.Entry { UnmodifiableEntry(Map.Entry e) {this.e = Objects.requireNonNull(e);} + @Pure public K getKey() {return e.getKey();} + @Pure public V getValue() {return e.getValue();} public V setValue(V value) { throw new UnsupportedOperationException(); } + @Pure public int hashCode() {return e.hashCode();} + @Pure public boolean equals(Object o) { if (this == o) return true; @@ -2252,6 +2273,7 @@ static class UnmodifiableSortedMap private final SortedMap sm; UnmodifiableSortedMap(SortedMap m) {super(m); sm = m; } + @Pure public Comparator comparator() { return sm.comparator(); } @SideEffectFree public SortedMap subMap(K fromKey, K toKey) @@ -2643,11 +2665,13 @@ static class SynchronizedSet super(s, mutex); } + @Pure public boolean equals(Object o) { if (this == o) return true; synchronized (mutex) {return c.equals(o);} } + @Pure public int hashCode() { synchronized (mutex) {return c.hashCode();} } @@ -2718,6 +2742,7 @@ static class SynchronizedSortedSet ss = s; } + @Pure public Comparator comparator() { synchronized (mutex) {return ss.comparator();} } @@ -2929,15 +2954,18 @@ static class SynchronizedList this.list = list; } + @Pure public boolean equals(Object o) { if (this == o) return true; synchronized (mutex) {return list.equals(o);} } + @Pure public int hashCode() { synchronized (mutex) {return list.hashCode();} } + @Pure public E get(int index) { synchronized (mutex) {return list.get(index);} } @@ -2957,9 +2985,11 @@ public E remove(int index) { synchronized (mutex) {return list.remove(index);} } + @Pure public int indexOf(Object o) { synchronized (mutex) {return list.indexOf(o);} } + @Pure public int lastIndexOf(Object o) { synchronized (mutex) {return list.lastIndexOf(o);} } @@ -3184,11 +3214,13 @@ public Collection values() { } } + @Pure public boolean equals(Object o) { if (this == o) return true; synchronized (mutex) {return m.equals(o);} } + @Pure public int hashCode() { synchronized (mutex) {return m.hashCode();} } @@ -3338,6 +3370,7 @@ static class SynchronizedSortedMap sm = m; } + @Pure public Comparator comparator() { synchronized (mutex) {return sm.comparator();} } @@ -3817,6 +3850,7 @@ static class CheckedQueue this.queue = queue; } + @Pure public E element() {return queue.element();} @Pure public boolean equals(Object o) {return o == this || c.equals(o);} @@ -3877,7 +3911,9 @@ static class CheckedSet extends CheckedCollection CheckedSet(Set s, Class elementType) { super(s, elementType); } + @Pure public boolean equals(Object o) { return o == this || c.equals(o); } + @Pure public int hashCode() { return c.hashCode(); } } @@ -3931,6 +3967,7 @@ static class CheckedSortedSet extends CheckedSet ss = s; } + @Pure public Comparator comparator() { return ss.comparator(); } public E first() { return ss.first(); } public E last() { return ss.last(); } @@ -4080,13 +4117,18 @@ static class CheckedList this.list = list; } + @Pure public boolean equals(Object o) { return o == this || list.equals(o); } + @Pure public int hashCode() { return list.hashCode(); } + @Pure public E get(int index) { return list.get(index); } // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E remove(int index) { return list.remove(index); } + @Pure public int indexOf(Object o) { return list.indexOf(o); } + @Pure public int lastIndexOf(Object o) { return list.lastIndexOf(o); } // @SideEffectsOnly("this") @@ -4118,9 +4160,12 @@ public ListIterator listIterator(final int index) { // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public E next(/*@NonEmpty ListIterator this*/) { return i.next(); } + @Pure public boolean hasPrevious() { return i.hasPrevious(); } public E previous() { return i.previous(); } + @Pure public int nextIndex() { return i.nextIndex(); } + @Pure public int previousIndex() { return i.previousIndex(); } // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @@ -4303,7 +4348,9 @@ private String badValueMsg(Object value) { public void clear() { m.clear(); } public Set keySet() { return m.keySet(); } public Collection values() { return m.values(); } + @Pure public boolean equals(Object o) { return o == this || m.equals(o); } + @Pure public int hashCode() { return m.hashCode(); } public String toString() { return m.toString(); } @@ -4588,6 +4635,7 @@ private boolean batchRemove(Collection c, boolean complement) { return modified; } + @Pure public boolean equals(Object o) { if (o == this) return true; @@ -4617,8 +4665,11 @@ private static class CheckedEntry implements Map.Entry { this.valueType = Objects.requireNonNull(valueType); } + @Pure public K getKey() { return e.getKey(); } + @Pure public V getValue() { return e.getValue(); } + @Pure public int hashCode() { return e.hashCode(); } public String toString() { return e.toString(); } @@ -4633,6 +4684,7 @@ private String badValueMsg(Object value) { " value into map with value type " + valueType; } + @Pure public boolean equals(Object o) { if (o == this) return true; @@ -4705,6 +4757,7 @@ static class CheckedSortedMap extends CheckedMap sm = m; } + @Pure public Comparator comparator() { return sm.comparator(); } public K firstKey() { return sm.firstKey(); } public K lastKey() { return sm.lastKey(); } @@ -4784,6 +4837,7 @@ static class CheckedNavigableMap extends CheckedSortedMap nm = m; } + @Pure public Comparator comparator() { return nm.comparator(); } public K firstKey() { return nm.firstKey(); } public K lastKey() { return nm.lastKey(); } @@ -4995,9 +5049,12 @@ private static class EmptyListIterator static final EmptyListIterator EMPTY_ITERATOR = new EmptyListIterator<>(); + @Pure public boolean hasPrevious() { return false; } public E previous() { throw new NoSuchElementException(); } + @Pure public int nextIndex() { return 0; } + @Pure public int previousIndex() { return -1; } // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @@ -5035,6 +5092,7 @@ private static class EmptyEnumeration implements Enumeration { = new EmptyEnumeration<>(); @EnsuresNonEmptyIf(result = true, expression = "this") + @Pure public boolean hasMoreElements() { return false; } public E nextElement(@NonEmpty EmptyEnumeration this) { throw new NoSuchElementException(); } public Iterator asIterator() { return emptyIterator(); } @@ -5130,6 +5188,7 @@ private Object readResolve() { } @Override + @Pure public int hashCode() { return 0; } @@ -5253,14 +5312,17 @@ public void clear() {} return a; } + @Pure public E get(int index) { throw new IndexOutOfBoundsException("Index: "+index); } + @Pure public boolean equals(Object o) { return (o instanceof List) && ((List)o).isEmpty(); } + @Pure public int hashCode() { return 1; } @Override @@ -5397,10 +5459,12 @@ public void clear() {} @SideEffectFree public Set> entrySet() {return emptySet();} + @Pure public boolean equals(Object o) { return (o instanceof Map) && ((Map)o).isEmpty(); } + @Pure public int hashCode() {return 0;} // Override default methods in Map @@ -5621,6 +5685,7 @@ public boolean removeIf(Predicate filter) { throw new UnsupportedOperationException(); } @Override + @Pure public int hashCode() { return Objects.hashCode(element); } @@ -5699,6 +5764,7 @@ public Spliterator spliterator() { return singletonSpliterator(element); } @Override + @Pure public int hashCode() { return 31 + Objects.hashCode(element); } @@ -5851,6 +5917,7 @@ public V replace(K key, V value) { } @Override + @Pure public int hashCode() { return Objects.hashCode(k) ^ Objects.hashCode(v); } @@ -5912,14 +5979,17 @@ public boolean contains(@UnknownSignedness Object obj) { return n != 0 && eq(obj, element); } + @Pure public int indexOf(Object o) { return contains(o) ? 0 : -1; } + @Pure public int lastIndexOf(Object o) { return contains(o) ? n - 1 : -1; } + @Pure public E get(int index) { Objects.checkIndex(index, n); return element; @@ -5972,6 +6042,7 @@ public List subList(int fromIndex, int toIndex) { } @Override + @Pure public int hashCode() { if (n == 0) return 1; // hashCode of n repeating elements is 31^n + elementHash * Sum(31^k, k = 0..n-1) @@ -5991,6 +6062,7 @@ public int hashCode() { } @Override + @Pure public boolean equals(Object o) { if (o == this) return true; @@ -6167,12 +6239,14 @@ public int compare(T t1, T t2) { return cmp.compare(t2, t1); } + @Pure public boolean equals(Object o) { return (o == this) || (o instanceof ReverseComparator2 that && cmp.equals(that.cmp)); } + @Pure public int hashCode() { return cmp.hashCode() ^ Integer.MIN_VALUE; } @@ -6203,6 +6277,7 @@ public static Enumeration enumeration(final Collection c) { private final Iterator i = c.iterator(); @EnsuresNonEmptyIf(result = true, expression = "this") + @Pure public boolean hasMoreElements() { return i.hasNext(); } @@ -6468,7 +6543,9 @@ private static class SetFromMap extends AbstractSet @SideEffectFree public @Nullable T[] toArray(@PolyNull T[] a) { return s.toArray(a); } public String toString() { return s.toString(); } + @Pure public int hashCode() { return s.hashCode(); } + @Pure public boolean equals(Object o) { return o == this || s.equals(o); } @Pure public boolean containsAll(Collection c) {return s.containsAll(c);} @@ -6582,7 +6659,9 @@ private SequencedMap map() { public void addFirst(E e) { map().putFirst(e, Boolean.TRUE); } public void addLast(E e) { map().putLast(e, Boolean.TRUE); } + @Pure public E getFirst() { return nsee(map().firstEntry()); } + @Pure public E getLast() { return nsee(map().lastEntry()); } public E removeFirst() { return nsee(map().pollFirstEntry()); } public E removeLast() { return nsee(map().pollLastEntry()); } diff --git a/src/java.base/share/classes/java/util/EnumMap.java b/src/java.base/share/classes/java/util/EnumMap.java index 9df266b7be679..e736eff8f56c8 100644 --- a/src/java.base/share/classes/java/util/EnumMap.java +++ b/src/java.base/share/classes/java/util/EnumMap.java @@ -128,6 +128,7 @@ public class EnumMap, V> extends AbstractMap * Distinguished non-null value for representing null values. */ private static final Object NULL = new Object() { + @Pure public int hashCode() { return 0; } @@ -265,6 +266,7 @@ private boolean containsMapping(@GuardSatisfied @UnknownSignedness Object key, @ * The {@link #containsKey containsKey} operation may be used to * distinguish these two cases. */ + @Pure public @Nullable V get(@UnknownSignedness @Nullable Object key) { return (isValidKey(key) ? unmaskNull(vals[((Enum)key).ordinal()]) : null); @@ -671,6 +673,7 @@ private Entry(int index) { this.index = index; } + @Pure public K getKey() { checkIndexForEntryUse(); return keyUniverse[index]; @@ -679,6 +682,7 @@ public K getKey() { @CFComment({"nullness: Value returned by unmaskNull", "will be of type V (not @Nullable V) for mapped value"}) @SuppressWarnings("nullness:return") + @Pure public V getValue() { checkIndexForEntryUse(); return unmaskNull(vals[index]); @@ -694,6 +698,7 @@ public V setValue(V value) { return oldValue; } + @Pure public boolean equals(Object o) { if (index < 0) return o == this; @@ -708,6 +713,7 @@ public boolean equals(Object o) { (ourValue != null && ourValue.equals(hisValue)))); } + @Pure public int hashCode() { if (index < 0) return super.hashCode(); @@ -741,6 +747,7 @@ private void checkIndexForEntryUse() { * @param o the object to be compared for equality with this map * @return {@code true} if the specified object is equal to this map */ + @Pure public boolean equals(@Nullable Object o) { if (this == o) return true; @@ -769,6 +776,7 @@ public boolean equals(@Nullable Object o) { return true; } + @Pure private boolean equals(EnumMap em) { if (em.size != size) return false; @@ -791,6 +799,7 @@ private boolean equals(EnumMap em) { * Returns the hash code value for this map. The hash code of a map is * defined to be the sum of the hash codes of each entry in the map. */ + @Pure public int hashCode() { int h = 0; diff --git a/src/java.base/share/classes/java/util/HashMap.java b/src/java.base/share/classes/java/util/HashMap.java index 5af06bf32997b..64b781daad6a3 100644 --- a/src/java.base/share/classes/java/util/HashMap.java +++ b/src/java.base/share/classes/java/util/HashMap.java @@ -311,10 +311,13 @@ static class Node implements Map.Entry { this.next = next; } + @Pure public final K getKey() { return key; } + @Pure public final V getValue() { return value; } public final String toString() { return key + "=" + value; } + @Pure public final int hashCode() { return Objects.hashCode(key) ^ Objects.hashCode(value); } @@ -327,6 +330,7 @@ public final V setValue(V newValue) { return oldValue; } + @Pure public final boolean equals(Object o) { if (o == this) return true; diff --git a/src/java.base/share/classes/java/util/Hashtable.java b/src/java.base/share/classes/java/util/Hashtable.java index ac6afe1422b2d..274f725406908 100644 --- a/src/java.base/share/classes/java/util/Hashtable.java +++ b/src/java.base/share/classes/java/util/Hashtable.java @@ -1472,10 +1472,12 @@ protected Object clone() { // Map.Entry Ops + @Pure public K getKey() { return key; } + @Pure public V getValue() { return value; } @@ -1491,6 +1493,7 @@ public V setValue(V value) { return oldValue; } + @Pure public boolean equals(Object o) { if (!(o instanceof Map.Entry e)) return false; @@ -1499,6 +1502,7 @@ public boolean equals(Object o) { (value==null ? e.getValue()==null : value.equals(e.getValue())); } + @Pure public int hashCode() { return hash ^ Objects.hashCode(value); } @@ -1546,6 +1550,7 @@ private class Enumerator implements Enumeration, Iterator { } @EnsuresNonEmptyIf(result = true, expression = "this") + @Pure public boolean hasMoreElements() { Entry e = entry; int i = index; diff --git a/src/java.base/share/classes/java/util/IdentityHashMap.java b/src/java.base/share/classes/java/util/IdentityHashMap.java index 5ef7004af3355..8db4424d978b6 100644 --- a/src/java.base/share/classes/java/util/IdentityHashMap.java +++ b/src/java.base/share/classes/java/util/IdentityHashMap.java @@ -792,6 +792,7 @@ public boolean hasNext() { } // @SideEffectsOnly("this") + @Pure protected int nextIndex(@NonEmpty IdentityHashMapIterator this) { if (modCount != expectedModCount) throw new ConcurrentModificationException(); @@ -932,12 +933,14 @@ private Entry(int index) { } @SuppressWarnings("unchecked") + @Pure public K getKey() { checkIndexForEntryUse(); return (K) unmaskNull(traversalTable[index]); } @SuppressWarnings("unchecked") + @Pure public V getValue() { checkIndexForEntryUse(); return (V) traversalTable[index+1]; @@ -956,6 +959,7 @@ public V setValue(V value) { return oldValue; } + @Pure public boolean equals(@Nullable Object o) { if (index < 0) return super.equals(o); @@ -965,6 +969,7 @@ public boolean equals(@Nullable Object o) { && e.getValue() == traversalTable[index+1]; } + @Pure public int hashCode() { if (lastReturnedIndex < 0) return super.hashCode(); @@ -1089,6 +1094,7 @@ public boolean removeAll(Collection c) { public void clear() { IdentityHashMap.this.clear(); } + @Pure public int hashCode() { int result = 0; for (K key : this) diff --git a/src/java.base/share/classes/java/util/ImmutableCollections.java b/src/java.base/share/classes/java/util/ImmutableCollections.java index 559f30657d04a..8cb34b961735e 100644 --- a/src/java.base/share/classes/java/util/ImmutableCollections.java +++ b/src/java.base/share/classes/java/util/ImmutableCollections.java @@ -313,6 +313,7 @@ public ListIterator listIterator(final int index) { } @Override + @Pure public boolean equals(Object o) { if (o == this) { return true; @@ -332,6 +333,7 @@ public boolean equals(Object o) { } @Override + @Pure public int hashCode() { int hash = 1; for (int i = 0, s = size(); i < s; i++) { @@ -407,6 +409,7 @@ public void remove() { throw uoe(); } + @Pure public boolean hasPrevious() { if (!isListIterator) { throw uoe(); @@ -428,6 +431,7 @@ public E previous() { } } + @Pure public int nextIndex() { if (!isListIterator) { throw uoe(); @@ -435,6 +439,7 @@ public int nextIndex() { return cursor; } + @Pure public int previousIndex() { if (!isListIterator) { throw uoe(); @@ -485,6 +490,7 @@ static SubList fromList(AbstractImmutableList list, int fromIndex, int return new SubList<>(list, fromIndex, toIndex - fromIndex); } + @Pure public E get(int index) { Objects.checkIndex(index, size); return root.get(offset + index); @@ -520,6 +526,7 @@ private boolean allowNulls() { } @Override + @Pure public int indexOf(Object o) { if (!allowNulls() && o == null) { throw new NullPointerException(); @@ -533,6 +540,7 @@ public int indexOf(Object o) { } @Override + @Pure public int lastIndexOf(Object o) { if (!allowNulls() && o == null) { throw new NullPointerException(); @@ -600,12 +608,14 @@ public int size() { @Override @EnsuresNonEmptyIf(result = false, expression = "this") + @Pure public boolean isEmpty() { return false; } @Override @SuppressWarnings("unchecked") + @Pure public E get(int index) { if (index == 0) { return e0; @@ -616,6 +626,7 @@ public E get(int index) { } @Override + @Pure public int indexOf(Object o) { Objects.requireNonNull(o); if (o.equals(e0)) { @@ -628,6 +639,7 @@ public int indexOf(Object o) { } @Override + @Pure public int lastIndexOf(Object o) { Objects.requireNonNull(o); if (e1 != EMPTY && o.equals(e1)) { @@ -709,6 +721,7 @@ public int size() { } @Override + @Pure public E get(int index) { return elements[index]; } @@ -744,6 +757,7 @@ public Object[] toArray() { } @Override + @Pure public int indexOf(Object o) { if (!allowNulls && o == null) { throw new NullPointerException(); @@ -758,6 +772,7 @@ public int indexOf(Object o) { } @Override + @Pure public int lastIndexOf(Object o) { if (!allowNulls && o == null) { throw new NullPointerException(); @@ -779,6 +794,7 @@ abstract static class AbstractImmutableSet extends AbstractImmutableCollectio implements Set { @Override + @Pure public boolean equals(Object o) { if (o == this) { return true; @@ -799,6 +815,7 @@ public boolean equals(Object o) { } @Override + @Pure public abstract int hashCode(); } @@ -836,6 +853,7 @@ public int size() { @Override @EnsuresNonEmptyIf(result = false, expression = "this") + @Pure public boolean isEmpty() { return false; } @@ -848,6 +866,7 @@ public boolean contains(@UnknownSignedness Object o) { } @Override + @Pure public int hashCode() { return e0.hashCode() + (e1 == EMPTY ? 0 : e1.hashCode()); } @@ -971,6 +990,7 @@ public int size() { @Override @EnsuresNonEmptyIf(result = false, expression = "this") + @Pure public boolean isEmpty() { return size == 0; } @@ -1038,6 +1058,7 @@ public Iterator iterator() { } @Override + @Pure public int hashCode() { int h = 0; for (E e : elements) { @@ -1134,6 +1155,7 @@ abstract static class AbstractImmutableMap extends AbstractMap impleme * value should be returned. */ @Override + @Pure public V getOrDefault(Object key, V defaultValue) { V v; return ((v = get(key)) != null) @@ -1161,6 +1183,7 @@ public Set> entrySet() { } @Override + @Pure public V get(Object o) { return o.equals(k0) ? v0 : null; // implicit nullcheck of o } @@ -1178,12 +1201,14 @@ public boolean containsValue(@UnknownSignedness Object o) { } @Override + @Pure public int size() { return 1; } @Override @EnsuresNonEmptyIf(result = false, expression = "this") + @Pure public boolean isEmpty() { return false; } @@ -1199,6 +1224,7 @@ private Object writeReplace() { } @Override + @Pure public int hashCode() { return k0.hashCode() ^ v0.hashCode(); } @@ -1269,6 +1295,7 @@ public boolean containsValue(@UnknownSignedness Object o) { } @Override + @Pure public int hashCode() { int hash = 0; for (int i = 0; i < table.length; i += 2) { @@ -1282,6 +1309,7 @@ public int hashCode() { @Override @SuppressWarnings("unchecked") + @Pure public V get(Object o) { if (size == 0) { Objects.requireNonNull(o); @@ -1303,6 +1331,7 @@ public int size() { @Override @EnsuresNonEmptyIf(result = false, expression = "this") + @Pure public boolean isEmpty() { return size == 0; } @@ -1329,6 +1358,7 @@ public boolean hasNext() { // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") + @Pure private int nextIndex() { int idx = this.idx; if (REVERSE) { diff --git a/src/java.base/share/classes/java/util/LinkedHashMap.java b/src/java.base/share/classes/java/util/LinkedHashMap.java index bae7f8b5d8a75..6714c0aa3fdc7 100644 --- a/src/java.base/share/classes/java/util/LinkedHashMap.java +++ b/src/java.base/share/classes/java/util/LinkedHashMap.java @@ -769,7 +769,9 @@ public final void forEach(Consumer action) { } public final void addFirst(K k) { throw new UnsupportedOperationException(); } public final void addLast(K k) { throw new UnsupportedOperationException(); } + @Pure public final K getFirst() { return nsee(reversed ? tail : head).key; } + @Pure public final K getLast() { return nsee(reversed ? head : tail).key; } // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @@ -885,7 +887,9 @@ public final void forEach(Consumer action) { } public final void addFirst(V v) { throw new UnsupportedOperationException(); } public final void addLast(V v) { throw new UnsupportedOperationException(); } + @Pure public final V getFirst() { return nsee(reversed ? tail : head).value; } + @Pure public final V getLast() { return nsee(reversed ? head : tail).value; } // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @@ -1018,7 +1022,9 @@ final Node nsee(Node e) { } public final void addFirst(Map.Entry e) { throw new UnsupportedOperationException(); } public final void addLast(Map.Entry e) { throw new UnsupportedOperationException(); } + @Pure public final Map.Entry getFirst() { return nsee(reversed ? tail : head); } + @Pure public final Map.Entry getLast() { return nsee(reversed ? head : tail); } // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @@ -1119,6 +1125,7 @@ final class LinkedKeyIterator extends LinkedHashIterator LinkedKeyIterator(boolean reversed) { super(reversed); } // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") + @Pure public final K next(@NonEmpty LinkedKeyIterator this) { return nextNode().getKey(); } } @@ -1185,32 +1192,39 @@ static class ReversedLinkedHashMapView extends AbstractMap // Object // inherit toString() from AbstractMap; it depends on entrySet() + @Pure public boolean equals(Object o) { return base.equals(o); } + @Pure public int hashCode() { return base.hashCode(); } // Map + @Pure public int size() { return base.size(); } + @Pure public boolean isEmpty() { return base.isEmpty(); } + @Pure public boolean containsKey(Object key) { return base.containsKey(key); } + @Pure public boolean containsValue(Object value) { return base.containsValue(value); } + @Pure public V get(Object key) { return base.get(key); } @@ -1251,6 +1265,7 @@ public Set> entrySet() { return base.sequencedEntrySet().reversed(); } + @Pure public V getOrDefault(Object key, V defaultValue) { return base.getOrDefault(key, defaultValue); } diff --git a/src/java.base/share/classes/java/util/LinkedHashSet.java b/src/java.base/share/classes/java/util/LinkedHashSet.java index b87c6b391220a..9a1fd11ec516b 100644 --- a/src/java.base/share/classes/java/util/LinkedHashSet.java +++ b/src/java.base/share/classes/java/util/LinkedHashSet.java @@ -328,16 +328,20 @@ public E removeLast() { @DoesNotUnrefineReceiver("modifiability") public SequencedSet reversed() { class ReverseLinkedHashSetView extends AbstractSet implements SequencedSet { + @Pure public int size() { return LinkedHashSet.this.size(); } public Iterator iterator() { return map().sequencedKeySet().reversed().iterator(); } public boolean add(E e) { return LinkedHashSet.this.add(e); } public void addFirst(E e) { LinkedHashSet.this.addLast(e); } public void addLast(E e) { LinkedHashSet.this.addFirst(e); } + @Pure public E getFirst() { return LinkedHashSet.this.getLast(); } + @Pure public E getLast() { return LinkedHashSet.this.getFirst(); } public E removeFirst() { return LinkedHashSet.this.removeLast(); } public E removeLast() { return LinkedHashSet.this.removeFirst(); } public SequencedSet reversed() { return LinkedHashSet.this; } + @Pure public Object[] toArray() { return map().keysToArray(new Object[map.size()], true); } public T[] toArray(T[] a) { return map().keysToArray(map.prepareArray(a), true); } } diff --git a/src/java.base/share/classes/java/util/LinkedList.java b/src/java.base/share/classes/java/util/LinkedList.java index 8b97ec19f8b2b..925b958e28411 100644 --- a/src/java.base/share/classes/java/util/LinkedList.java +++ b/src/java.base/share/classes/java/util/LinkedList.java @@ -272,6 +272,7 @@ E unlink(Node x) { * @return the first element in this list * @throws NoSuchElementException if this list is empty */ + @Pure public E getFirst(@GuardSatisfied @NonEmpty LinkedList this) { final Node f = first; if (f == null) @@ -285,6 +286,7 @@ public E getFirst(@GuardSatisfied @NonEmpty LinkedList this) { * @return the last element in this list * @throws NoSuchElementException if this list is empty */ + @Pure public E getLast(@GuardSatisfied @NonEmpty LinkedList this) { final Node l = last; if (l == null) @@ -727,6 +729,7 @@ Node node(@NonNegative int index) { * @throws NoSuchElementException if this list is empty * @since 1.5 */ + @Pure public E element(@GuardSatisfied @NonEmpty LinkedList this) { return getFirst(); } @@ -991,6 +994,7 @@ public E next(@NonEmpty ListItr this) { return lastReturned.item; } + @Pure public boolean hasPrevious() { return nextIndex > 0; } @@ -1007,10 +1011,12 @@ public E previous() { return lastReturned.item; } + @Pure public int nextIndex() { return nextIndex; } + @Pure public int previousIndex() { return nextIndex - 1; } @@ -1094,6 +1100,7 @@ private static class Node { * Adapter to provide descending iterators via ListItr.previous */ private class DescendingIterator implements Iterator { + @Pure private final ListItr itr = new ListItr(size()); @Pure @EnsuresNonEmptyIf(result = true, expression = "this") @@ -1419,10 +1426,12 @@ public boolean removeAll(Collection c) { return rlist.removeAll(c); } + @Pure public boolean containsAll(Collection c) { return rlist.containsAll(c); } + @Pure public boolean isEmpty() { return rlist.isEmpty(); } @@ -1453,10 +1462,12 @@ public Iterator iterator() { return rlist.iterator(); } + @Pure public int hashCode() { return rlist.hashCode(); } + @Pure public boolean equals(Object o) { return rlist.equals(o); } @@ -1540,10 +1551,12 @@ public E pollFirst() { return rdeque.pollFirst(); } + @Pure public E peekLast() { return rdeque.peekLast(); } + @Pure public E peekFirst() { return rdeque.peekFirst(); } @@ -1578,18 +1591,22 @@ public E poll() { return rdeque.poll(); } + @Pure public E element() { return rdeque.element(); } + @Pure public E peek() { return rdeque.peek(); } + @Pure public int lastIndexOf(Object o) { return rlist.lastIndexOf(o); } + @Pure public int indexOf(Object o) { return rlist.indexOf(o); } @@ -1612,6 +1629,7 @@ public E set(int index, E element) { return rlist.set(index, element); } + @Pure public E get(int index) { return rlist.get(index); } @@ -1646,10 +1664,12 @@ public boolean add(E e) { return rlist.add(e); } + @Pure public int size() { return rlist.size(); } + @Pure public boolean contains(Object o) { return rlist.contains(o); } @@ -1678,10 +1698,12 @@ public E removeFirst() { return rdeque.removeFirst(); } + @Pure public E getLast() { return rdeque.getLast(); } + @Pure public E getFirst() { return rdeque.getFirst(); } diff --git a/src/java.base/share/classes/java/util/Properties.java b/src/java.base/share/classes/java/util/Properties.java index a877b1a0cdc4a..b65ff2cfe6a81 100644 --- a/src/java.base/share/classes/java/util/Properties.java +++ b/src/java.base/share/classes/java/util/Properties.java @@ -1361,6 +1361,7 @@ public boolean containsKey(@GuardSatisfied @Nullable @UnknownSignedness Object k } @Override + @Pure public @Nullable Object get(Object key) { return map.get(key); } @@ -1426,6 +1427,7 @@ private EntrySet(Set> entrySet) { this.entrySet = entrySet; } + @Pure @Pure @Override public int size() { return entrySet.size(); } @Pure @EnsuresNonEmptyIf(result = false, expression = "this") @@ -1459,11 +1461,13 @@ public boolean containsAll(Collection c) { } @Override + @Pure public boolean equals(Object o) { return o == this || entrySet.equals(o); } @Override + @Pure public int hashCode() { return entrySet.hashCode(); } @@ -1494,11 +1498,13 @@ public Iterator> iterator() { } @Override + @Pure public synchronized boolean equals(Object o) { return map.equals(o); } @Override + @Pure public synchronized int hashCode() { return map.hashCode(); } diff --git a/src/java.base/share/classes/java/util/ServiceLoader.java b/src/java.base/share/classes/java/util/ServiceLoader.java index c1d32bfbff385..3a43f94a57b30 100644 --- a/src/java.base/share/classes/java/util/ServiceLoader.java +++ b/src/java.base/share/classes/java/util/ServiceLoader.java @@ -734,6 +734,7 @@ public Class type() { } @Override + @Pure public S get() { if (factoryMethod != null) { return invokeFactoryMethod(); @@ -833,11 +834,13 @@ public S run() throws Exception { // when running with a security manager. @Override + @Pure public int hashCode() { return Objects.hash(service, type, acc); } @Override + @Pure public boolean equals(Object ob) { return ob instanceof @SuppressWarnings("unchecked")ProviderImpl that && this.service == that.service diff --git a/src/java.base/share/classes/java/util/SortedSet.java b/src/java.base/share/classes/java/util/SortedSet.java index bfcba3a5158a6..7b71cd5f774c1 100644 --- a/src/java.base/share/classes/java/util/SortedSet.java +++ b/src/java.base/share/classes/java/util/SortedSet.java @@ -326,6 +326,7 @@ default void addLast(E e) { * @throws NoSuchElementException {@inheritDoc} * @since 21 */ + @Pure default E getFirst() { return this.first(); } @@ -339,6 +340,7 @@ default E getFirst() { * @throws NoSuchElementException {@inheritDoc} * @since 21 */ + @Pure default E getLast() { return this.last(); } diff --git a/src/java.base/share/classes/java/util/TreeMap.java b/src/java.base/share/classes/java/util/TreeMap.java index d54e0f9fa9c06..46ce4bf140a00 100644 --- a/src/java.base/share/classes/java/util/TreeMap.java +++ b/src/java.base/share/classes/java/util/TreeMap.java @@ -312,6 +312,7 @@ public boolean containsValue(@GuardSatisfied TreeMap this, @GuardSatisfied */ // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") + @Pure public @Nullable V get(@GuardSatisfied TreeMap this, @UnknownSignedness @GuardSatisfied Object key) { Entry p = getEntry(key); return (p==null ? null : p.value); @@ -1547,6 +1548,7 @@ public Iterator descendingIterator() { public E higher(E e) { return m.higherKey(e); } public E first() { return m.firstKey(); } public E last() { return m.lastKey(); } + @Pure public Comparator comparator() { return m.comparator(); } public E pollFirst() { Map.Entry e = m.pollFirstEntry(); @@ -1995,6 +1997,7 @@ public V computeIfPresent(K key, BiFunction r return !inRange(key) ? null : m.computeIfPresent(key, remappingFunction); } + @Pure public final V get(Object key) { return !inRange(key) ? null : m.get(key); } @@ -2366,6 +2369,7 @@ static final class AscendingSubMap extends NavigableSubMap { super(m, fromStart, lo, loInclusive, toEnd, hi, hiInclusive); } + @Pure public Comparator comparator() { return m.comparator(); } @@ -2458,6 +2462,7 @@ static final class DescendingSubMap extends NavigableSubMap { private final Comparator reverseComparator = Collections.reverseOrder(m.comparator); + @Pure public Comparator comparator() { return reverseComparator; } @@ -2568,6 +2573,7 @@ private Object readResolve() { public SortedMap headMap(K toKey) { throw new InternalError(); } @SideEffectFree public SortedMap tailMap(K fromKey) { throw new InternalError(); } + @Pure public Comparator comparator() { throw new InternalError(); } } @@ -2605,6 +2611,7 @@ static final class Entry implements Map.Entry { * * @return the key */ + @Pure public K getKey() { return key; } @@ -2614,6 +2621,7 @@ public K getKey() { * * @return the value associated with the key */ + @Pure public V getValue() { return value; } @@ -2631,12 +2639,14 @@ public V setValue(V value) { return oldValue; } + @Pure public boolean equals(Object o) { return o instanceof Map.Entry e && valEquals(key,e.getKey()) && valEquals(value,e.getValue()); } + @Pure public int hashCode() { int keyHash = (key==null ? 0 : key.hashCode()); int valueHash = (value==null ? 0 : value.hashCode()); diff --git a/src/java.base/share/classes/java/util/Vector.java b/src/java.base/share/classes/java/util/Vector.java index e3c57409c97f7..adf96dabf9d58 100644 --- a/src/java.base/share/classes/java/util/Vector.java +++ b/src/java.base/share/classes/java/util/Vector.java @@ -357,6 +357,7 @@ public synchronized boolean isEmpty(@GuardSatisfied Vector this) { int count = 0; @EnsuresNonEmptyIf(result = true, expression = "this") + @Pure public boolean hasMoreElements() { return count < elementCount; } @@ -493,6 +494,7 @@ public boolean contains(@GuardSatisfied Vector this, @GuardSatisfied @Nullabl * @throws ArrayIndexOutOfBoundsException if the index is out of range * ({@code index < 0 || index >= size()}) */ + @Pure public synchronized E elementAt(@NonNegative int index) { if (index >= elementCount) { throw new ArrayIndexOutOfBoundsException(index + " >= " + elementCount); @@ -1389,14 +1391,17 @@ final class ListItr extends Itr implements ListIterator { cursor = index; } + @Pure public boolean hasPrevious() { return cursor != 0; } + @Pure public int nextIndex() { return cursor; } + @Pure public int previousIndex() { return cursor - 1; } diff --git a/src/java.base/share/classes/java/util/WeakHashMap.java b/src/java.base/share/classes/java/util/WeakHashMap.java index aa52dae7a4516..4cb4c820bf1d0 100644 --- a/src/java.base/share/classes/java/util/WeakHashMap.java +++ b/src/java.base/share/classes/java/util/WeakHashMap.java @@ -763,10 +763,12 @@ private static class Entry extends WeakReference implements Map.Ent } @SuppressWarnings("unchecked") + @Pure public K getKey() { return (K) WeakHashMap.unmaskNull(get()); } + @Pure public V getValue() { return value; } @@ -779,6 +781,7 @@ public V setValue(V newValue) { return oldValue; } + @Pure public boolean equals(Object o) { if (!(o instanceof Map.Entry e)) return false; @@ -793,6 +796,7 @@ public boolean equals(Object o) { return false; } + @Pure public int hashCode() { K k = getKey(); V v = getValue(); diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java index b472783200544..bd1b8fef0cc90 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java @@ -659,8 +659,11 @@ static class Node implements Map.Entry { this.next = next; } + @Pure public final K getKey() { return key; } + @Pure public final V getValue() { return val; } + @Pure public final int hashCode() { return key.hashCode() ^ val.hashCode(); } public final String toString() { return Helpers.mapEntryToString(key, val); @@ -671,6 +674,7 @@ public final V setValue(V value) { throw new UnsupportedOperationException(); } + @Pure public final boolean equals(Object o) { Object k, v, u; Map.Entry e; return ((o instanceof Map.Entry) && @@ -845,6 +849,7 @@ static final void setTabAt(Node[] tab, int i, Node v) { /* ---------------- Public operations -------------- */ /** + @Pure * Creates a new, empty map with the default initial table size (16). */ public ConcurrentHashMap() { @@ -1334,6 +1339,7 @@ public Collection values() { * * @return the hash code value for this map */ + @Pure public int hashCode() { int h = 0; Node[] t; @@ -3595,13 +3601,17 @@ static final class MapEntry implements Map.Entry { this.val = val; this.map = map; } + @Pure public K getKey() { return key; } + @Pure public V getValue() { return val; } + @Pure public int hashCode() { return key.hashCode() ^ val.hashCode(); } public String toString() { return Helpers.mapEntryToString(key, val); } + @Pure public boolean equals(Object o) { Object k, v; Map.Entry e; return ((o instanceof Map.Entry) && @@ -4784,6 +4794,7 @@ public boolean addAll(Collection c) { return added; } + @Pure public int hashCode() { int h = 0; for (K e : this) @@ -4791,6 +4802,7 @@ public int hashCode() { return h; } + @Pure public boolean equals(Object o) { Set c; return ((o instanceof Set) && @@ -4971,6 +4983,7 @@ public boolean removeIf(Predicate> filter) { return map.removeEntryIf(filter); } + @Pure public final int hashCode() { int h = 0; Node[] t; @@ -4983,6 +4996,7 @@ public final int hashCode() { return h; } + @Pure public final boolean equals(Object o) { Set c; return ((o instanceof Set) && @@ -5365,6 +5379,7 @@ static final class SearchKeysTask super(p, b, i, f, t); this.searchFunction = searchFunction; this.result = result; } + @Pure public final U getRawResult() { return result.get(); } public final void compute() { final Function searchFunction; @@ -5409,6 +5424,7 @@ static final class SearchValuesTask super(p, b, i, f, t); this.searchFunction = searchFunction; this.result = result; } + @Pure public final U getRawResult() { return result.get(); } public final void compute() { final Function searchFunction; @@ -5453,6 +5469,7 @@ static final class SearchEntriesTask super(p, b, i, f, t); this.searchFunction = searchFunction; this.result = result; } + @Pure public final U getRawResult() { return result.get(); } public final void compute() { final Function, ? extends U> searchFunction; @@ -5497,6 +5514,7 @@ static final class SearchMappingsTask super(p, b, i, f, t); this.searchFunction = searchFunction; this.result = result; } + @Pure public final U getRawResult() { return result.get(); } public final void compute() { final BiFunction searchFunction; diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java index b1c1d1dc3b92c..571a27f9446ed 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java @@ -929,6 +929,7 @@ public boolean offerLast(E e) { /** * @throws NoSuchElementException {@inheritDoc} */ + @Pure public E getFirst(@NonEmpty ConcurrentLinkedDeque this) { return screenNullResult(peekFirst()); } @@ -936,6 +937,7 @@ public E getFirst(@NonEmpty ConcurrentLinkedDeque this) { /** * @throws NoSuchElementException {@inheritDoc} */ + @Pure public E getLast(@NonEmpty ConcurrentLinkedDeque this) { return screenNullResult(peekLast()); } @@ -1057,6 +1059,7 @@ public boolean add(E e) { /** * @throws NoSuchElementException {@inheritDoc} */ + @Pure public E element(@NonEmpty ConcurrentLinkedDeque this) { return getFirst(); } /** diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java index 982e87617f7d4..9deac7e18d5ce 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java @@ -1323,6 +1323,7 @@ public boolean containsKey(@GuardSatisfied @UnknownSignedness Object key) { * with the keys currently in the map * @throws NullPointerException if the specified key is null */ + @Pure public V get(Object key) { return doGet(key); } @@ -1890,6 +1891,7 @@ public V replace(K key, V value) { /* ------ SortedMap API methods ------ */ + @Pure public Comparator comparator() { return comparator; } @@ -2280,6 +2282,7 @@ static final class KeySet public K floor(K e) { return m.floorKey(e); } public K ceiling(K e) { return m.ceilingKey(e); } public K higher(K e) { return m.higherKey(e); } + @Pure public Comparator comparator() { return m.comparator(); } public K first() { return m.firstKey(); } public K last() { return m.lastKey(); } @@ -2300,6 +2303,7 @@ public Iterator iterator() { ? ((ConcurrentSkipListMap)m).new KeyIterator() : ((SubMap)m).new SubMapKeyIterator(); } + @Pure public boolean equals(Object o) { if (o == this) return true; @@ -2443,6 +2447,7 @@ public int size() { public void clear() { m.clear(); } + @Pure public boolean equals(Object o) { if (o == this) return true; @@ -2746,6 +2751,7 @@ public boolean containsKey(@UnknownSignedness Object key) { return inBounds(key, m.comparator) && m.containsKey(key); } + @Pure public V get(Object key) { if (key == null) throw new NullPointerException(); return (!inBounds(key, m.comparator)) ? null : m.get(key); @@ -2842,6 +2848,7 @@ public V replace(K key, V value) { /* ---------------- SortedMap API methods -------------- */ + @Pure public Comparator comparator() { Comparator cmp = m.comparator(); if (isDescending) diff --git a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java index 3c85dcccee7f2..2c814b2222dce 100644 --- a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java +++ b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java @@ -261,6 +261,7 @@ public boolean contains(@GuardSatisfied @Nullable @UnknownSignedness Object o) { /** * {@inheritDoc} */ + @Pure public int indexOf(@GuardSatisfied @Nullable @UnknownSignedness Object o) { Object[] es = getArray(); return indexOfRange(o, es, 0, es.length); @@ -281,6 +282,7 @@ public int indexOf(@GuardSatisfied @Nullable @UnknownSignedness Object o) { * {@code -1} if the element is not found. * @throws IndexOutOfBoundsException if the specified index is negative */ + @Pure public int indexOf(E e, int index) { Object[] es = getArray(); return indexOfRange(e, es, index, es.length); @@ -289,6 +291,7 @@ public int indexOf(E e, int index) { /** * {@inheritDoc} */ + @Pure public int lastIndexOf(@GuardSatisfied @Nullable @UnknownSignedness Object o) { Object[] es = getArray(); return lastIndexOfRange(o, es, 0, es.length); @@ -310,6 +313,7 @@ public int lastIndexOf(@GuardSatisfied @Nullable @UnknownSignedness Object o) { * @throws IndexOutOfBoundsException if the specified index is greater * than or equal to the current size of this list */ + @Pure public int lastIndexOf(E e, int index) { Object[] es = getArray(); return lastIndexOfRange(e, es, 0, index + 1); @@ -422,6 +426,7 @@ static String outOfBounds(int index, int size) { * * @throws IndexOutOfBoundsException {@inheritDoc} */ + @Pure public E get(int index) { return elementAt(getArray(), index); } @@ -432,6 +437,7 @@ public E get(int index) { * @throws NoSuchElementException {@inheritDoc} * @since 21 */ + @Pure public E getFirst() { Object[] es = getArray(); if (es.length == 0) @@ -446,6 +452,7 @@ public E getFirst() { * @throws NoSuchElementException {@inheritDoc} * @since 21 */ + @Pure public E getLast() { Object[] es = getArray(); if (es.length == 0) @@ -1153,6 +1160,7 @@ private static int hashCodeOfRange(Object[] es, int from, int to) { * * @return the hash code value for this list */ + @Pure public int hashCode() { Object[] es = getArray(); return hashCodeOfRange(es, 0, es.length); @@ -1415,6 +1423,7 @@ public Object[] toArray() { } } + @Pure public int indexOf(Object o) { final Object[] es; final int offset; @@ -1428,6 +1437,7 @@ public int indexOf(Object o) { return (i == -1) ? -1 : i - offset; } + @Pure public int lastIndexOf(Object o) { final Object[] es; final int offset; @@ -1473,6 +1483,7 @@ public String toString() { return Arrays.toString(toArray()); } + @Pure public int hashCode() { final Object[] es; final int offset; @@ -1485,6 +1496,7 @@ public int hashCode() { return hashCodeOfRange(es, offset, offset + size); } + @Pure public boolean equals(Object o) { if (o == this) return true; @@ -1519,6 +1531,7 @@ public E set(int index, E element) { } } + @Pure public E get(int index) { synchronized (lock) { rangeCheck(index); @@ -1537,6 +1550,7 @@ public E getFirst() { } } + @Pure public E getLast() { synchronized (lock) { if (size == 0) @@ -1546,6 +1560,7 @@ public E getLast() { } } + @Pure public int size() { synchronized (lock) { checkForComodification(); @@ -1803,6 +1818,7 @@ public E next(@NonEmpty COWSubListIterator this) { throw new NoSuchElementException(); } + @Pure public boolean hasPrevious() { return previousIndex() >= 0; } @@ -1814,10 +1830,12 @@ public E previous() { throw new NoSuchElementException(); } + @Pure public int nextIndex() { return it.nextIndex() - offset; } + @Pure public int previousIndex() { return it.previousIndex() - offset; } @@ -1877,6 +1895,7 @@ class DescendingIterator implements Iterator { it = base.listIterator(base.size()); } } + @Pure public boolean hasNext() { return it.hasPrevious(); } // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @@ -1899,6 +1918,7 @@ class DescendingListIterator implements ListIterator { } } + @Pure public boolean hasNext() { return it.hasPrevious(); } @@ -1909,6 +1929,7 @@ public E next() { return it.previous(); } + @Pure public boolean hasPrevious() { return it.hasNext(); } @@ -1917,10 +1938,12 @@ public E previous() { return it.next(); } + @Pure public int nextIndex() { return size - it.nextIndex(); } + @Pure public int previousIndex() { return nextIndex() - 1; } @@ -1989,15 +2012,18 @@ public void clear() { base.clear(); } + @Pure public boolean contains(Object o) { return base.contains(o); } + @Pure public boolean containsAll(Collection c) { return base.containsAll(c); } // copied from AbstractList + @Pure public boolean equals(Object o) { if (o == this) return true; @@ -2016,6 +2042,7 @@ public boolean equals(Object o) { } // copied from AbstractList + @Pure public int hashCode() { int hashCode = 1; for (E e : this) @@ -2023,6 +2050,7 @@ public int hashCode() { return hashCode; } + @Pure public boolean isEmpty() { return base.isEmpty(); } @@ -2055,6 +2083,7 @@ public boolean retainAll(Collection c) { return base.retainAll(c); } + @Pure public int size() { return base.size(); } @@ -2132,12 +2161,14 @@ public boolean addAll(int index, Collection c) { } } + @Pure public E get(int i) { synchronized (lock) { return base.get(base.size() - i - 1); } } + @Pure public E getFirst() { synchronized (lock) { int size = base.size(); @@ -2148,6 +2179,7 @@ public E getFirst() { } } + @Pure public E getLast() { synchronized (lock) { if (base.size() == 0) @@ -2157,6 +2189,7 @@ public E getLast() { } } + @Pure public int indexOf(Object o) { synchronized (lock) { int i = base.lastIndexOf(o); @@ -2164,6 +2197,7 @@ public int indexOf(Object o) { } } + @Pure public int lastIndexOf(Object o) { synchronized (lock) { int i = base.indexOf(o); diff --git a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java index b7d44834f4252..d8457b2fa0a9d 100644 --- a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java +++ b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java @@ -591,6 +591,7 @@ public E takeLast(@GuardSatisfied @CanShrink LinkedBlockingDeque this) throws /** * @throws NoSuchElementException {@inheritDoc} */ + @Pure public E getFirst(@NonEmpty LinkedBlockingDeque this) { E x = peekFirst(); if (x == null) throw new NoSuchElementException(); @@ -600,6 +601,7 @@ public E getFirst(@NonEmpty LinkedBlockingDeque this) { /** * @throws NoSuchElementException {@inheritDoc} */ + @Pure public E getLast(@NonEmpty LinkedBlockingDeque this) { E x = peekLast(); if (x == null) throw new NoSuchElementException(); @@ -760,6 +762,7 @@ public E take(@GuardSatisfied @CanShrink LinkedBlockingDeque this) throws Int * @return the head of the queue represented by this deque * @throws NoSuchElementException if this deque is empty */ + @Pure public E element(@NonEmpty LinkedBlockingDeque this) { return getFirst(); } diff --git a/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java index ddf86b3f52f06..2deb1a5df2090 100644 --- a/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java @@ -606,6 +606,7 @@ public E take(@GuardSatisfied @CanShrink PriorityBlockingQueue this) throws I * or {@code null} if this queue uses the natural * ordering of its elements */ + @Pure public Comparator comparator() { return comparator; } @@ -630,6 +631,7 @@ public int remainingCapacity() { return Integer.MAX_VALUE; } + @Pure private int indexOf(@GuardSatisfied @Nullable @UnknownSignedness Object o) { if (o != null) { final Object[] es = queue; diff --git a/src/java.base/share/classes/java/util/concurrent/ScheduledThreadPoolExecutor.java b/src/java.base/share/classes/java/util/concurrent/ScheduledThreadPoolExecutor.java index a2eee3f15babb..6015ffd22f0bd 100644 --- a/src/java.base/share/classes/java/util/concurrent/ScheduledThreadPoolExecutor.java +++ b/src/java.base/share/classes/java/util/concurrent/ScheduledThreadPoolExecutor.java @@ -1024,6 +1024,7 @@ private void grow() { /** * Finds index of given object, or -1 if absent. */ + @Pure private int indexOf(Object x) { if (x != null) { if (x instanceof ScheduledFutureTask) { diff --git a/src/java.base/share/classes/java/util/jar/Attributes.java b/src/java.base/share/classes/java/util/jar/Attributes.java index 6e73d6ac15725..58dba2a49cf49 100644 --- a/src/java.base/share/classes/java/util/jar/Attributes.java +++ b/src/java.base/share/classes/java/util/jar/Attributes.java @@ -124,6 +124,7 @@ public Attributes(Attributes attr) { * @return the value of the specified attribute name, or null if * not found. */ + @Pure public Object get(Object name) { return map.get(name); } @@ -143,6 +144,7 @@ public Object get(Object name) { * not found. * @throws IllegalArgumentException if the attribute name is invalid */ + @Pure public String getValue(String name) { return (String)get(Name.of(name)); } @@ -160,6 +162,7 @@ public String getValue(String name) { * @return the String value of the specified Attribute.Name, or null if * not found. */ + @Pure public String getValue(Name name) { return (String)get(name); } @@ -322,6 +325,7 @@ public boolean equals(@Nullable Object o) { /** * Returns the hash code value for this Map. */ + @Pure public int hashCode() { return map.hashCode(); } @@ -549,6 +553,7 @@ private final int hash(String name) { * @return true if this attribute name is equal to the * specified attribute object */ + @Pure public boolean equals(Object o) { if (this == o) { return true; @@ -560,6 +565,7 @@ public boolean equals(Object o) { /** * Computes the hash value for this attribute name. */ + @Pure public int hashCode() { return hashCode; } diff --git a/src/java.base/share/classes/java/util/zip/ZipFile.java b/src/java.base/share/classes/java/util/zip/ZipFile.java index 282978d2f4c85..222c6d4a0c605 100644 --- a/src/java.base/share/classes/java/util/zip/ZipFile.java +++ b/src/java.base/share/classes/java/util/zip/ZipFile.java @@ -511,6 +511,7 @@ public ZipEntryIterator(int entryCount) { @Override @EnsuresNonEmptyIf(result = true, expression = "this") + @Pure public boolean hasMoreElements() { return hasNext(); } @@ -1025,6 +1026,7 @@ public int available() { return rem > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) rem; } + @Pure public long size() { return size; } @@ -1272,12 +1274,14 @@ public Key(File file, BasicFileAttributes attrs, ZipCoder zc) { this.utf8 = zc.isUTF8(); } + @Pure public int hashCode() { long t = utf8 ? 0 : Long.MAX_VALUE; t += attrs.lastModifiedTime().toMillis(); return ((int)(t ^ (t >>> 32))) + file.hashCode(); } + @Pure public boolean equals(Object obj) { if (obj instanceof Key key) { if (key.utf8 != utf8) { From 5a4edbea91726c8a17a312816d2d60f4d6ade759 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 19 May 2026 17:07:00 -0700 Subject: [PATCH 11/15] Checkpoint --- .../share/classes/java/io/BufferedReader.java | 2 +- .../share/classes/java/lang/Class.java | 2 +- .../share/classes/java/lang/String.java | 4 +-- .../share/classes/java/util/AbstractMap.java | 6 ++--- .../classes/java/util/AbstractQueue.java | 2 ++ .../share/classes/java/util/ArrayList.java | 3 ++- .../share/classes/java/util/Collections.java | 18 ++++++++++--- .../share/classes/java/util/Deque.java | 6 +++++ .../share/classes/java/util/EnumMap.java | 2 +- .../share/classes/java/util/HashMap.java | 2 +- .../share/classes/java/util/Hashtable.java | 6 ++--- .../classes/java/util/IdentityHashMap.java | 4 +-- .../java/util/ImmutableCollections.java | 10 ++++---- .../share/classes/java/util/Map.java | 6 +++-- .../share/classes/java/util/Objects.java | 6 ++--- .../classes/java/util/PriorityQueue.java | 1 + .../share/classes/java/util/Queue.java | 2 ++ .../java/util/ReverseOrderDequeView.java | 11 ++++++++ .../java/util/ReverseOrderListView.java | 15 +++++++++++ .../java/util/ReverseOrderSortedMapView.java | 25 +++++++++++++++++++ .../java/util/ReverseOrderSortedSetView.java | 12 +++++++++ .../java/util/SequencedCollection.java | 3 +++ .../share/classes/java/util/SequencedMap.java | 5 ++++ .../share/classes/java/util/Set.java | 2 +- .../share/classes/java/util/Vector.java | 3 ++- .../share/classes/java/util/WeakHashMap.java | 2 +- .../util/concurrent/ConcurrentHashMap.java | 3 +-- .../util/concurrent/CopyOnWriteArrayList.java | 1 + .../java/util/stream/SpinedBuffer.java | 5 ++++ .../share/classes/java/util/zip/ZipFile.java | 2 +- 30 files changed, 137 insertions(+), 34 deletions(-) diff --git a/src/java.base/share/classes/java/io/BufferedReader.java b/src/java.base/share/classes/java/io/BufferedReader.java index 498c3677a49ce..168f571e45c35 100644 --- a/src/java.base/share/classes/java/io/BufferedReader.java +++ b/src/java.base/share/classes/java/io/BufferedReader.java @@ -511,8 +511,8 @@ private long implSkip(long n) throws IOException { * * @throws IOException If an I/O error occurs */ - @EnsuresNonNullIf(expression={"readLine()"}, result=true) @Pure + @EnsuresNonNullIf(expression={"readLine()"}, result=true) public boolean ready(@GuardSatisfied BufferedReader this) throws IOException { Object lock = this.lock; if (lock instanceof InternalLock locker) { diff --git a/src/java.base/share/classes/java/lang/Class.java b/src/java.base/share/classes/java/lang/Class.java index 7e7cabd891789..4353f31e9d743 100644 --- a/src/java.base/share/classes/java/lang/Class.java +++ b/src/java.base/share/classes/java/lang/Class.java @@ -840,8 +840,8 @@ public Void run() { * {@code false} otherwise. * @since 1.1 */ - @EnsuresNonNullIf(expression={"getComponentType()"}, result=true) @Pure + @EnsuresNonNullIf(expression={"getComponentType()"}, result=true) @IntrinsicCandidate public native boolean isArray(@GuardSatisfied Class this); diff --git a/src/java.base/share/classes/java/lang/String.java b/src/java.base/share/classes/java/lang/String.java index 985accbb2669a..0a6d2f8f404aa 100644 --- a/src/java.base/share/classes/java/lang/String.java +++ b/src/java.base/share/classes/java/lang/String.java @@ -1945,8 +1945,8 @@ public void getBytes(@IndexOrHigh({"this"}) int srcBegin, @IndexOrHigh({"this"}) * @see #compareTo(String) * @see #equalsIgnoreCase(String) */ - @EnsuresNonNullIf(expression={"#1"}, result=true) @Pure + @EnsuresNonNullIf(expression={"#1"}, result=true) @StaticallyExecutable public boolean equals(@GuardSatisfied @Nullable Object anObject) { if (this == anObject) { @@ -2084,8 +2084,8 @@ public boolean contentEquals(@GuardSatisfied CharSequence cs) { * @see #equals(Object) * @see #codePoints() */ - @EnsuresNonNullIf(expression={"#1"}, result=true) @Pure + @EnsuresNonNullIf(expression={"#1"}, result=true) @StaticallyExecutable public boolean equalsIgnoreCase(@Nullable String anotherString) { return (this == anotherString) ? true diff --git a/src/java.base/share/classes/java/util/AbstractMap.java b/src/java.base/share/classes/java/util/AbstractMap.java index ec20d28ca4421..b8462e5fe9f10 100644 --- a/src/java.base/share/classes/java/util/AbstractMap.java +++ b/src/java.base/share/classes/java/util/AbstractMap.java @@ -168,8 +168,8 @@ public boolean containsValue(@GuardSatisfied AbstractMap this, @GuardSatis * @throws ClassCastException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ - @EnsuresKeyForIf(expression={"#1"}, result=true, map={"this"}) @Pure + @EnsuresKeyForIf(expression={"#1"}, result=true, map={"this"}) public boolean containsKey(@GuardSatisfied AbstractMap this, @GuardSatisfied @UnknownSignedness Object key) { Iterator> i = entrySet().iterator(); if (key==null) { @@ -430,8 +430,8 @@ public void clear() { AbstractMap.this.clear(); } - @EnsuresNonEmptyIf(result = true, expression = "this") @Pure + @EnsuresNonEmptyIf(result = true, expression = "this") public boolean contains(@UnknownSignedness Object k) { return AbstractMap.this.containsKey(k); } @@ -503,8 +503,8 @@ public void clear() { AbstractMap.this.clear(); } - @EnsuresNonEmptyIf(result = true, expression = "this") @Pure + @EnsuresNonEmptyIf(result = true, expression = "this") public boolean contains(@UnknownSignedness Object v) { return AbstractMap.this.containsValue(v); } diff --git a/src/java.base/share/classes/java/util/AbstractQueue.java b/src/java.base/share/classes/java/util/AbstractQueue.java index dc006f3509487..c349250b238ae 100644 --- a/src/java.base/share/classes/java/util/AbstractQueue.java +++ b/src/java.base/share/classes/java/util/AbstractQueue.java @@ -39,6 +39,7 @@ import org.checkerframework.checker.lock.qual.GuardSatisfied; import org.checkerframework.checker.nonempty.qual.EnsuresNonEmpty; import org.checkerframework.checker.nonempty.qual.NonEmpty; +import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; @@ -141,6 +142,7 @@ public E remove(@GuardSatisfied @NonEmpty @CanShrink AbstractQueue this) { * @return the head of this queue * @throws NoSuchElementException if this queue is empty */ + @Pure public E element(@GuardSatisfied @NonEmpty AbstractQueue this) { E x = peek(); if (x != null) diff --git a/src/java.base/share/classes/java/util/ArrayList.java b/src/java.base/share/classes/java/util/ArrayList.java index 5393cace995ed..dd0ea7e78e5ff 100644 --- a/src/java.base/share/classes/java/util/ArrayList.java +++ b/src/java.base/share/classes/java/util/ArrayList.java @@ -449,6 +449,7 @@ E elementData(@NonNegative int index) { } @SuppressWarnings("unchecked") + @Pure static E elementAt(Object[] es, int index) { return (E) es[index]; } @@ -1476,8 +1477,8 @@ public int lastIndexOf(@GuardSatisfied @Nullable @UnknownSignedness Object o) { return index >= 0 ? index - offset : -1; } - @EnsuresNonEmptyIf(result = true, expression = "this") @Pure + @EnsuresNonEmptyIf(result = true, expression = "this") public boolean contains(@Nullable @UnknownSignedness Object o) { return indexOf(o) >= 0; } diff --git a/src/java.base/share/classes/java/util/Collections.java b/src/java.base/share/classes/java/util/Collections.java index 88678893f7cb7..8bfa36ea789bf 100644 --- a/src/java.base/share/classes/java/util/Collections.java +++ b/src/java.base/share/classes/java/util/Collections.java @@ -292,6 +292,7 @@ else if (cmp > 0) * list listIterator. */ @Pure + @SideEffectsOnly("#1") private static T get(ListIterator i, int index) { T obj; int pos = i.nextIndex(); @@ -1675,7 +1676,9 @@ public ListIterator listIterator(final int index) { public boolean hasPrevious() {return i.hasPrevious();} // @SideEffectsOnly("this") public E previous() {return i.previous();} + @Pure public int nextIndex() {return i.nextIndex();} + @Pure public int previousIndex() {return i.previousIndex();} // @SideEffectsOnly("this") @@ -1806,6 +1809,7 @@ private static class UnmodifiableMap implements Map, Serializable { public boolean containsKey(@UnknownSignedness Object key) {return m.containsKey(key);} @Pure public boolean containsValue(@UnknownSignedness Object val) {return m.containsValue(val);} + @Pure public V get(Object key) {return m.get(key);} // @SideEffectsOnly("this") @@ -2092,8 +2096,8 @@ public Object[] toArray() { * that the equality-candidate is Map.Entry and calls its * setValue method. */ - @EnsuresNonEmptyIf(result = true, expression = "this") @Pure + @EnsuresNonEmptyIf(result = true, expression = "this") public boolean contains(@UnknownSignedness Object o) { if (!(o instanceof Map.Entry)) return false; @@ -3159,6 +3163,7 @@ public boolean containsKey(@UnknownSignedness Object key) { public boolean containsValue(@UnknownSignedness Object value) { synchronized (mutex) {return m.containsValue(value);} } + @Pure public V get(Object key) { synchronized (mutex) {return m.get(key);} } @@ -4339,6 +4344,7 @@ private String badValueMsg(Object value) { public boolean containsKey(@UnknownSignedness Object key) { return m.containsKey(key); } @Pure public boolean containsValue(@UnknownSignedness Object v) { return m.containsValue(v); } + @Pure public V get(Object key) { return m.get(key); } // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @@ -4497,7 +4503,9 @@ static class CheckedEntrySet implements Set> { @Pure @EnsuresNonEmptyIf(result = false, expression = "this") public boolean isEmpty() { return s.isEmpty(); } + @SideEffectFree public String toString() { return s.toString(); } + @Pure public int hashCode() { return s.hashCode(); } // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @@ -5091,8 +5099,8 @@ private static class EmptyEnumeration implements Enumeration { static final EmptyEnumeration EMPTY_ENUMERATION = new EmptyEnumeration<>(); - @EnsuresNonEmptyIf(result = true, expression = "this") @Pure + @EnsuresNonEmptyIf(result = true, expression = "this") public boolean hasMoreElements() { return false; } public E nextElement(@NonEmpty EmptyEnumeration this) { throw new NoSuchElementException(); } public Iterator asIterator() { return emptyIterator(); } @@ -5453,6 +5461,7 @@ public void clear() {} public boolean containsKey(@UnknownSignedness Object key) {return false;} @Pure public boolean containsValue(@UnknownSignedness Object value) {return false;} + @Pure public V get(Object key) {return null;} public Set keySet() {return emptySet();} public Collection values() {return emptySet();} @@ -5733,6 +5742,7 @@ public Iterator iterator() { @EnsuresNonEmptyIf(result = true, expression = "this") public boolean contains(@UnknownSignedness Object obj) {return eq(obj, element);} + @Pure public E get(int index) { if (index != 0) throw new IndexOutOfBoundsException("Index: "+index+", Size: 1"); @@ -5815,6 +5825,7 @@ private static class SingletonMap public boolean containsKey(@UnknownSignedness Object key) {return eq(key, k);} @Pure public boolean containsValue(@UnknownSignedness Object value) {return eq(value, v);} + @Pure public V get(Object key) {return (eq(key, k) ? v : null);} private transient Set keySet; @@ -6276,8 +6287,8 @@ public static Enumeration enumeration(final Collection c) { return new Enumeration<>() { private final Iterator i = c.iterator(); - @EnsuresNonEmptyIf(result = true, expression = "this") @Pure + @EnsuresNonEmptyIf(result = true, expression = "this") public boolean hasMoreElements() { return i.hasNext(); } @@ -6714,6 +6725,7 @@ static class AsLIFOQueue extends AbstractQueue public E remove() { return q.removeFirst(); } @Pure public E peek() { return q.peekFirst(); } + @Pure public E element() { return q.getFirst(); } public void clear() { q.clear(); } @Pure diff --git a/src/java.base/share/classes/java/util/Deque.java b/src/java.base/share/classes/java/util/Deque.java index c288e0162b2c1..486ce85966b30 100644 --- a/src/java.base/share/classes/java/util/Deque.java +++ b/src/java.base/share/classes/java/util/Deque.java @@ -359,6 +359,7 @@ public interface Deque extends Queue, SequencedCollection { * @return the head of this deque * @throws NoSuchElementException if this deque is empty */ + @Pure @EnsuresNonEmpty("this") E getFirst(@GuardSatisfied @NonEmpty @CanShrink Deque this); @@ -370,6 +371,7 @@ public interface Deque extends Queue, SequencedCollection { * @return the tail of this deque * @throws NoSuchElementException if this deque is empty */ + @Pure @EnsuresNonEmpty("this") E getLast(@GuardSatisfied @NonEmpty @CanShrink Deque this); @@ -381,6 +383,7 @@ public interface Deque extends Queue, SequencedCollection { */ // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") + @Pure @Nullable E peekFirst(); /** @@ -391,6 +394,7 @@ public interface Deque extends Queue, SequencedCollection { */ // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") + @Pure @Nullable E peekLast(); /** @@ -531,6 +535,7 @@ public interface Deque extends Queue, SequencedCollection { */ // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") + @Pure E element(@GuardSatisfied @NonEmpty Deque this); /** @@ -545,6 +550,7 @@ public interface Deque extends Queue, SequencedCollection { */ // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") + @Pure @Nullable E peek(); /** diff --git a/src/java.base/share/classes/java/util/EnumMap.java b/src/java.base/share/classes/java/util/EnumMap.java index e736eff8f56c8..bfdda342b7e6a 100644 --- a/src/java.base/share/classes/java/util/EnumMap.java +++ b/src/java.base/share/classes/java/util/EnumMap.java @@ -240,8 +240,8 @@ public boolean containsValue(@GuardSatisfied @Nullable @UnknownSignedness Object * @return {@code true} if this map contains a mapping for the specified * key */ - @EnsuresKeyForIf(expression={"#1"}, result=true, map={"this"}) @Pure + @EnsuresKeyForIf(expression={"#1"}, result=true, map={"this"}) public boolean containsKey(@GuardSatisfied @UnknownSignedness Object key) { return isValidKey(key) && vals[((Enum)key).ordinal()] != null; } diff --git a/src/java.base/share/classes/java/util/HashMap.java b/src/java.base/share/classes/java/util/HashMap.java index 64b781daad6a3..b60cbfca9cfdb 100644 --- a/src/java.base/share/classes/java/util/HashMap.java +++ b/src/java.base/share/classes/java/util/HashMap.java @@ -628,8 +628,8 @@ final Node getNode(@Nullable Object key) { * @return {@code true} if this map contains a mapping for the specified * key. */ - @EnsuresKeyForIf(expression={"#1"}, result=true, map={"this"}) @Pure + @EnsuresKeyForIf(expression={"#1"}, result=true, map={"this"}) public boolean containsKey(@GuardSatisfied HashMap this, @GuardSatisfied @Nullable @UnknownSignedness Object key) { return getNode(key) != null; } diff --git a/src/java.base/share/classes/java/util/Hashtable.java b/src/java.base/share/classes/java/util/Hashtable.java index 274f725406908..1ead43be81d6e 100644 --- a/src/java.base/share/classes/java/util/Hashtable.java +++ b/src/java.base/share/classes/java/util/Hashtable.java @@ -375,8 +375,8 @@ public boolean containsValue(@GuardSatisfied Hashtable this, @GuardSatisfi * @throws NullPointerException if the key is {@code null} * @see #contains(Object) */ - @EnsuresKeyForIf(expression={"#1"}, result=true, map={"this"}) @Pure + @EnsuresKeyForIf(expression={"#1"}, result=true, map={"this"}) public synchronized boolean containsKey(@GuardSatisfied Hashtable this, @GuardSatisfied @UnknownSignedness Object key) { Entry tab[] = table; int hash = key.hashCode(); @@ -404,8 +404,8 @@ public synchronized boolean containsKey(@GuardSatisfied Hashtable this, @G * @throws NullPointerException if the specified key is null * @see #put(Object, Object) */ - @Pure @SuppressWarnings("unchecked") + @Pure public synchronized @Nullable V get(@GuardSatisfied Hashtable this, @UnknownSignedness @GuardSatisfied Object key) { Entry tab[] = table; int hash = key.hashCode(); @@ -1549,8 +1549,8 @@ private class Enumerator implements Enumeration, Iterator { this.iterator = iterator; } - @EnsuresNonEmptyIf(result = true, expression = "this") @Pure + @EnsuresNonEmptyIf(result = true, expression = "this") public boolean hasMoreElements() { Entry e = entry; int i = index; diff --git a/src/java.base/share/classes/java/util/IdentityHashMap.java b/src/java.base/share/classes/java/util/IdentityHashMap.java index 8db4424d978b6..45670034dee2e 100644 --- a/src/java.base/share/classes/java/util/IdentityHashMap.java +++ b/src/java.base/share/classes/java/util/IdentityHashMap.java @@ -354,8 +354,8 @@ private static int nextKeyIndex(int i, int len) { * * @see #put(Object, Object) */ - @Pure @SuppressWarnings("unchecked") + @Pure public @Nullable V get(@GuardSatisfied IdentityHashMap this, @UnknownSignedness @GuardSatisfied @Nullable Object key) { Object k = maskNull(key); Object[] tab = table; @@ -381,8 +381,8 @@ private static int nextKeyIndex(int i, int len) { * in this map * @see #containsValue(Object) */ - @EnsuresKeyForIf(expression={"#1"}, result=true, map={"this"}) @Pure + @EnsuresKeyForIf(expression={"#1"}, result=true, map={"this"}) public boolean containsKey(@GuardSatisfied IdentityHashMap this, @GuardSatisfied @Nullable @UnknownSignedness Object key) { Object k = maskNull(key); Object[] tab = table; diff --git a/src/java.base/share/classes/java/util/ImmutableCollections.java b/src/java.base/share/classes/java/util/ImmutableCollections.java index 8cb34b961735e..f4310924b44e0 100644 --- a/src/java.base/share/classes/java/util/ImmutableCollections.java +++ b/src/java.base/share/classes/java/util/ImmutableCollections.java @@ -607,8 +607,8 @@ public int size() { } @Override - @EnsuresNonEmptyIf(result = false, expression = "this") @Pure + @EnsuresNonEmptyIf(result = false, expression = "this") public boolean isEmpty() { return false; } @@ -852,8 +852,8 @@ public int size() { } @Override - @EnsuresNonEmptyIf(result = false, expression = "this") @Pure + @EnsuresNonEmptyIf(result = false, expression = "this") public boolean isEmpty() { return false; } @@ -989,8 +989,8 @@ public int size() { } @Override - @EnsuresNonEmptyIf(result = false, expression = "this") @Pure + @EnsuresNonEmptyIf(result = false, expression = "this") public boolean isEmpty() { return size == 0; } @@ -1207,8 +1207,8 @@ public int size() { } @Override - @EnsuresNonEmptyIf(result = false, expression = "this") @Pure + @EnsuresNonEmptyIf(result = false, expression = "this") public boolean isEmpty() { return false; } @@ -1330,8 +1330,8 @@ public int size() { } @Override - @EnsuresNonEmptyIf(result = false, expression = "this") @Pure + @EnsuresNonEmptyIf(result = false, expression = "this") public boolean isEmpty() { return size == 0; } diff --git a/src/java.base/share/classes/java/util/Map.java b/src/java.base/share/classes/java/util/Map.java index 6249e66a0e1f9..e3c9cc7635068 100644 --- a/src/java.base/share/classes/java/util/Map.java +++ b/src/java.base/share/classes/java/util/Map.java @@ -223,8 +223,8 @@ public interface Map { */ @CFComment("nullness: key is not @Nullable because this map might not permit null values") @EnsuresKeyForIf(expression={"#1"}, result=true, map={"this"}) - @EnsuresNonEmptyIf(result=true, expression={"this"}) @Pure + @EnsuresNonEmptyIf(result=true, expression={"this"}) boolean containsKey(@GuardSatisfied Map this, @GuardSatisfied @UnknownSignedness Object key); /** @@ -243,8 +243,8 @@ public interface Map { * @throws NullPointerException if the specified value is null and this * map does not permit null values ({@linkplain Collection##optional-restrictions optional}) */ - @EnsuresNonEmptyIf(result=true, expression={"this"}) @Pure + @EnsuresNonEmptyIf(result=true, expression={"this"}) boolean containsValue(@GuardSatisfied Map this, @GuardSatisfied @UnknownSignedness Object value); /** @@ -707,6 +707,7 @@ public static Comparator> comparingByValue(Comparator this, @GuardSatisfied @Nullable Object o); /** @@ -722,6 +723,7 @@ public static Comparator> comparingByValue(Comparator this); // Defaultable methods diff --git a/src/java.base/share/classes/java/util/Objects.java b/src/java.base/share/classes/java/util/Objects.java index 9544c1cce499e..c33b12a060453 100644 --- a/src/java.base/share/classes/java/util/Objects.java +++ b/src/java.base/share/classes/java/util/Objects.java @@ -301,8 +301,8 @@ public static int compare(@GuardSatisfied @Nullable @UnknownSignedness T a, * @see java.util.function.Predicate * @since 1.8 */ - @EnsuresNonNullIf(expression={"#1"}, result=false) @Pure + @EnsuresNonNullIf(expression={"#1"}, result=false) public static boolean isNull(@GuardSatisfied @Nullable @UnknownSignedness Object obj) { return obj == null; } @@ -321,8 +321,8 @@ public static boolean isNull(@GuardSatisfied @Nullable @UnknownSignedness Object * @see java.util.function.Predicate * @since 1.8 */ - @EnsuresNonNullIf(expression={"#1"}, result=true) @Pure + @EnsuresNonNullIf(expression={"#1"}, result=true) public static boolean nonNull(@GuardSatisfied @Nullable @UnknownSignedness Object obj) { return obj != null; } @@ -385,8 +385,8 @@ public static boolean nonNull(@GuardSatisfied @Nullable @UnknownSignedness Objec * @throws NullPointerException if {@code obj} is {@code null} * @since 1.8 */ - @EnsuresNonNull("#1") @Pure + @EnsuresNonNull("#1") public static @NonNull T requireNonNull(@GuardSatisfied @NonNull @UnknownSignedness T obj, @GuardSatisfied Supplier messageSupplier) { if (obj == null) throw new NullPointerException(messageSupplier == null ? diff --git a/src/java.base/share/classes/java/util/PriorityQueue.java b/src/java.base/share/classes/java/util/PriorityQueue.java index 165a4ee9f35cb..4d1225c89d839 100644 --- a/src/java.base/share/classes/java/util/PriorityQueue.java +++ b/src/java.base/share/classes/java/util/PriorityQueue.java @@ -365,6 +365,7 @@ public boolean offer(E e) { return (E) queue[0]; } + @Pure private int indexOf(@GuardSatisfied @Nullable @UnknownSignedness Object o) { if (o != null) { final Object[] es = queue; diff --git a/src/java.base/share/classes/java/util/Queue.java b/src/java.base/share/classes/java/util/Queue.java index f27b0261692b0..c3051c1b7489a 100644 --- a/src/java.base/share/classes/java/util/Queue.java +++ b/src/java.base/share/classes/java/util/Queue.java @@ -222,6 +222,7 @@ public interface Queue extends Collection { * @return the head of this queue * @throws NoSuchElementException if this queue is empty */ + @Pure E element(@GuardSatisfied @NonEmpty Queue this); /** @@ -232,5 +233,6 @@ public interface Queue extends Collection { */ // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") + @Pure @Nullable E peek(); } diff --git a/src/java.base/share/classes/java/util/ReverseOrderDequeView.java b/src/java.base/share/classes/java/util/ReverseOrderDequeView.java index a580ad8f7db3c..654420802de26 100644 --- a/src/java.base/share/classes/java/util/ReverseOrderDequeView.java +++ b/src/java.base/share/classes/java/util/ReverseOrderDequeView.java @@ -30,6 +30,7 @@ import java.util.stream.Stream; import java.util.stream.StreamSupport; import jdk.internal.util.ArraysSupport; +import org.checkerframework.dataflow.qual.Pure; /** * Provides a reverse-ordered view of any Deque. Not serializable. @@ -84,14 +85,17 @@ public void clear() { base.clear(); } + @Pure public boolean contains(Object o) { return base.contains(o); } + @Pure public boolean containsAll(Collection c) { return base.containsAll(c); } + @Pure public boolean isEmpty() { return base.isEmpty(); } @@ -149,6 +153,7 @@ public boolean retainAll(Collection c) { return modified; } + @Pure public int size() { return base.size(); } @@ -201,14 +206,17 @@ public Iterator descendingIterator() { return base.iterator(); } + @Pure public E element() { return base.getLast(); } + @Pure public E getFirst() { return base.getLast(); } + @Pure public E getLast() { return base.getFirst(); } @@ -225,14 +233,17 @@ public boolean offerLast(E e) { return base.offerFirst(e); } + @Pure public E peek() { return base.peekLast(); } + @Pure public E peekFirst() { return base.peekLast(); } + @Pure public E peekLast() { return base.peekFirst(); } diff --git a/src/java.base/share/classes/java/util/ReverseOrderListView.java b/src/java.base/share/classes/java/util/ReverseOrderListView.java index 0f7409bef16d0..e8b4c66c6f90c 100644 --- a/src/java.base/share/classes/java/util/ReverseOrderListView.java +++ b/src/java.base/share/classes/java/util/ReverseOrderListView.java @@ -33,6 +33,7 @@ import java.util.stream.Stream; import java.util.stream.StreamSupport; import jdk.internal.util.ArraysSupport; +import org.checkerframework.dataflow.qual.Pure; /** * Provides a reverse-ordered view of a List. Not serializable. @@ -80,6 +81,7 @@ void checkModifiable() { class DescendingIterator implements Iterator { final ListIterator it = base.listIterator(base.size()); + @Pure public boolean hasNext() { return it.hasPrevious(); } public E next() { return it.previous(); } public void remove() { @@ -98,6 +100,7 @@ class DescendingListIterator implements ListIterator { it = base.listIterator(size - pos); } + @Pure public boolean hasNext() { return it.hasPrevious(); } @@ -106,6 +109,7 @@ public E next() { return it.previous(); } + @Pure public boolean hasPrevious() { return it.hasNext(); } @@ -114,10 +118,12 @@ public E previous() { return it.next(); } + @Pure public int nextIndex() { return base.size() - it.nextIndex(); } + @Pure public int previousIndex() { return nextIndex() - 1; } @@ -181,15 +187,18 @@ public void clear() { base.clear(); } + @Pure public boolean contains(Object o) { return base.contains(o); } + @Pure public boolean containsAll(Collection c) { return base.containsAll(c); } // copied from AbstractList + @Pure public boolean equals(Object o) { if (o == this) return true; @@ -208,6 +217,7 @@ public boolean equals(Object o) { } // copied from AbstractList + @Pure public int hashCode() { int hashCode = 1; for (E e : this) @@ -215,6 +225,7 @@ public int hashCode() { return hashCode; } + @Pure public boolean isEmpty() { return base.isEmpty(); } @@ -275,6 +286,7 @@ public boolean retainAll(Collection c) { return modified; } + @Pure public int size() { return base.size(); } @@ -336,17 +348,20 @@ public boolean addAll(int index, Collection c) { } } + @Pure public E get(int i) { int size = base.size(); Objects.checkIndex(i, size); return base.get(size - i - 1); } + @Pure public int indexOf(Object o) { int i = base.lastIndexOf(o); return i == -1 ? -1 : base.size() - i - 1; } + @Pure public int lastIndexOf(Object o) { int i = base.indexOf(o); return i == -1 ? -1 : base.size() - i - 1; diff --git a/src/java.base/share/classes/java/util/ReverseOrderSortedMapView.java b/src/java.base/share/classes/java/util/ReverseOrderSortedMapView.java index 404950e8fd54e..1a15d09236e63 100644 --- a/src/java.base/share/classes/java/util/ReverseOrderSortedMapView.java +++ b/src/java.base/share/classes/java/util/ReverseOrderSortedMapView.java @@ -25,6 +25,8 @@ package java.util; +import org.checkerframework.dataflow.qual.Pure; + /** * Provides a reversed-ordered view of a SortedMap. Not serializable. * @@ -63,18 +65,22 @@ public void clear() { base.clear(); } + @Pure public boolean containsKey(Object key) { return base.containsKey(key); } + @Pure public boolean containsValue(Object value) { return base.containsValue(value); } + @Pure public V get(Object key) { return base.get(key); } + @Pure public boolean isEmpty() { return base.isEmpty(); } @@ -91,6 +97,7 @@ public V remove(Object key) { return base.remove(key); } + @Pure public int size() { return base.size(); } @@ -99,8 +106,10 @@ public Set keySet() { return new AbstractSet<>() { // inherit add(), which throws UOE public Iterator iterator() { return descendingKeyIterator(base); } + @Pure public int size() { return base.size(); } public void clear() { base.keySet().clear(); } + @Pure public boolean contains(Object o) { return base.keySet().contains(o); } public boolean remove(Object o) { return base.keySet().remove(o); } }; @@ -110,8 +119,10 @@ public Collection values() { return new AbstractCollection<>() { // inherit add(), which throws UOE public Iterator iterator() { return descendingValueIterator(base); } + @Pure public int size() { return base.size(); } public void clear() { base.values().clear(); } + @Pure public boolean contains(Object o) { return base.values().contains(o); } public boolean remove(Object o) { return base.values().remove(o); } }; @@ -121,8 +132,10 @@ public Set> entrySet() { return new AbstractSet<>() { // inherit add(), which throws UOE public Iterator> iterator() { return descendingEntryIterator(base); } + @Pure public int size() { return base.size(); } public void clear() { base.entrySet().clear(); } + @Pure public boolean contains(Object o) { return base.entrySet().contains(o); } public boolean remove(Object o) { return base.entrySet().remove(o); } }; @@ -168,6 +181,7 @@ public V putLast(K k, V v) { // ========== SortedMap ========== + @Pure public Comparator comparator() { return cmp; } @@ -196,6 +210,7 @@ static Iterator descendingKeyIterator(SortedMap map) { SortedMap view = map; K prev = null; + @Pure public boolean hasNext() { return ! view.isEmpty(); } @@ -223,6 +238,7 @@ static Iterator descendingValueIterator(SortedMap map) { return new Iterator<>() { Iterator keyIterator = descendingKeyIterator(map); + @Pure public boolean hasNext() { return keyIterator.hasNext(); } @@ -241,6 +257,7 @@ static Iterator> descendingEntryIterator(SortedMap return new Iterator<>() { Iterator keyIterator = descendingKeyIterator(map); + @Pure public boolean hasNext() { return keyIterator.hasNext(); } @@ -267,16 +284,20 @@ static class ViewEntry implements Map.Entry { this.value = value; } + @Pure public K getKey() { return key; } + @Pure public V getValue() { return value; } public V setValue(V newValue) { return map.put(key, newValue); } + @Pure public boolean equals(Object o) { return o instanceof Map.Entry e && Objects.equals(key, e.getKey()) && Objects.equals(value, e.getValue()); } + @Pure public int hashCode() { return Objects.hashCode(key) ^ Objects.hashCode(value); } @@ -337,6 +358,7 @@ Iterator> entryIterator() { boolean dead = false; Iterator> it = descendingEntryIterator(base); + @Pure public boolean hasNext() { if (dead) return false; @@ -397,6 +419,7 @@ public Iterator> iterator() { return entryIterator(); } + @Pure public int size() { int sz = 0; for (var it = entryIterator(); it.hasNext();) { @@ -424,10 +447,12 @@ public V remove(Object o) { return null; } + @Pure public int size() { return entrySet().size(); } + @Pure public Comparator comparator() { return cmp; } diff --git a/src/java.base/share/classes/java/util/ReverseOrderSortedSetView.java b/src/java.base/share/classes/java/util/ReverseOrderSortedSetView.java index 678c82fc311e4..bd3f00c97f7c1 100644 --- a/src/java.base/share/classes/java/util/ReverseOrderSortedSetView.java +++ b/src/java.base/share/classes/java/util/ReverseOrderSortedSetView.java @@ -30,6 +30,7 @@ import java.util.stream.Stream; import java.util.stream.StreamSupport; import jdk.internal.util.ArraysSupport; +import org.checkerframework.dataflow.qual.Pure; /** * Provides a reversed-ordered view of a SortedSet. Not serializable. @@ -54,6 +55,7 @@ public static SortedSet of(SortedSet set) { // ========== Object ========== // copied from AbstractSet + @Pure public boolean equals(Object o) { if (o == this) return true; @@ -71,6 +73,7 @@ public boolean equals(Object o) { } // copied from AbstractSet + @Pure public int hashCode() { int h = 0; Iterator i = iterator(); @@ -129,14 +132,17 @@ public void clear() { base.clear(); } + @Pure public boolean contains(Object o) { return base.contains(o); } + @Pure public boolean containsAll(Collection c) { return base.containsAll(c); } + @Pure public boolean isEmpty() { return base.isEmpty(); } @@ -158,6 +164,7 @@ public boolean retainAll(Collection c) { return base.retainAll(c); } + @Pure public int size() { return base.size(); } @@ -181,6 +188,7 @@ public T[] toArray(IntFunction generator) { // ========== SortedSet ========== + @Pure public Comparator comparator() { return comp; } @@ -209,6 +217,7 @@ static Iterator descendingIterator(SortedSet set) { SortedSet view = set; T prev = null; + @Pure public boolean hasNext() { return ! view.isEmpty(); } @@ -267,6 +276,7 @@ public Iterator iterator() { boolean dead = false; Iterator it = descendingIterator(base); + @Pure public boolean hasNext() { if (dead) return false; @@ -320,6 +330,7 @@ public boolean remove(Object o) { return false; } + @Pure public int size() { int sz = 0; for (E e : this) @@ -327,6 +338,7 @@ public int size() { return sz; } + @Pure public Comparator comparator() { return ReverseOrderSortedSetView.this.comparator(); } diff --git a/src/java.base/share/classes/java/util/SequencedCollection.java b/src/java.base/share/classes/java/util/SequencedCollection.java index a08d233155f0e..a424be88c5806 100644 --- a/src/java.base/share/classes/java/util/SequencedCollection.java +++ b/src/java.base/share/classes/java/util/SequencedCollection.java @@ -25,6 +25,7 @@ package java.util; +import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; /** @@ -145,6 +146,7 @@ default void addLast(E e) { * @return the retrieved element * @throws NoSuchElementException if this collection is empty */ + @Pure default E getFirst() { return this.iterator().next(); } @@ -161,6 +163,7 @@ default E getFirst() { * @return the retrieved element * @throws NoSuchElementException if this collection is empty */ + @Pure default E getLast() { return this.reversed().iterator().next(); } diff --git a/src/java.base/share/classes/java/util/SequencedMap.java b/src/java.base/share/classes/java/util/SequencedMap.java index 3933603e15c6f..5241bcad1d722 100644 --- a/src/java.base/share/classes/java/util/SequencedMap.java +++ b/src/java.base/share/classes/java/util/SequencedMap.java @@ -25,6 +25,7 @@ package java.util; +import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import jdk.internal.util.NullableKeyValueHolder; @@ -294,9 +295,11 @@ Collection view() { public SequencedSet reversed() { return SequencedMap.this.reversed().sequencedKeySet(); } + @Pure public boolean equals(Object other) { return view().equals(other); } + @Pure public int hashCode() { return view().hashCode(); } @@ -358,9 +361,11 @@ Collection> view() { public SequencedSet> reversed() { return SequencedMap.this.reversed().sequencedEntrySet(); } + @Pure public boolean equals(Object other) { return view().equals(other); } + @Pure public int hashCode() { return view().hashCode(); } diff --git a/src/java.base/share/classes/java/util/Set.java b/src/java.base/share/classes/java/util/Set.java index 4e0953c500b27..a29820d648326 100644 --- a/src/java.base/share/classes/java/util/Set.java +++ b/src/java.base/share/classes/java/util/Set.java @@ -36,11 +36,11 @@ import org.checkerframework.checker.nullness.qual.PolyNull; import org.checkerframework.checker.signedness.qual.PolySigned; import org.checkerframework.checker.signedness.qual.UnknownSignedness; -import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; +import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; /** * A collection that contains no duplicate elements. More formally, sets diff --git a/src/java.base/share/classes/java/util/Vector.java b/src/java.base/share/classes/java/util/Vector.java index adf96dabf9d58..a60aa2d93cfc9 100644 --- a/src/java.base/share/classes/java/util/Vector.java +++ b/src/java.base/share/classes/java/util/Vector.java @@ -356,8 +356,8 @@ public synchronized boolean isEmpty(@GuardSatisfied Vector this) { return new Enumeration() { int count = 0; - @EnsuresNonEmptyIf(result = true, expression = "this") @Pure + @EnsuresNonEmptyIf(result = true, expression = "this") public boolean hasMoreElements() { return count < elementCount; } @@ -781,6 +781,7 @@ E elementData(int index) { } @SuppressWarnings("unchecked") + @Pure static E elementAt(Object[] es, int index) { return (E) es[index]; } diff --git a/src/java.base/share/classes/java/util/WeakHashMap.java b/src/java.base/share/classes/java/util/WeakHashMap.java index 4cb4c820bf1d0..3cf4274beae18 100644 --- a/src/java.base/share/classes/java/util/WeakHashMap.java +++ b/src/java.base/share/classes/java/util/WeakHashMap.java @@ -449,8 +449,8 @@ public boolean isEmpty(@GuardSatisfied WeakHashMap this) { * @return {@code true} if there is a mapping for {@code key}; * {@code false} otherwise */ - @EnsuresKeyForIf(expression={"#1"}, result=true, map={"this"}) @Pure + @EnsuresKeyForIf(expression={"#1"}, result=true, map={"this"}) public boolean containsKey(@GuardSatisfied WeakHashMap this, @GuardSatisfied @Nullable @UnknownSignedness Object key) { return getEntry(key) != null; } diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java index bd1b8fef0cc90..96d8e59b50475 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java @@ -849,7 +849,6 @@ static final void setTabAt(Node[] tab, int i, Node v) { /* ---------------- Public operations -------------- */ /** - @Pure * Creates a new, empty map with the default initial table size (16). */ public ConcurrentHashMap() { @@ -991,8 +990,8 @@ else if (eh < 0) * {@code equals} method; {@code false} otherwise * @throws NullPointerException if the specified key is null */ - @EnsuresKeyForIf(expression={"#1"}, result=true, map={"this"}) @Pure + @EnsuresKeyForIf(expression={"#1"}, result=true, map={"this"}) public boolean containsKey(@GuardSatisfied @UnknownSignedness Object key) { return get(key) != null; } diff --git a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java index 2c814b2222dce..84cbe8c7ee89d 100644 --- a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java +++ b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java @@ -413,6 +413,7 @@ public Object clone() { // Positional Access Operations @SuppressWarnings("unchecked") + @Pure static E elementAt(Object[] a, int index) { return (E) a[index]; } diff --git a/src/java.base/share/classes/java/util/stream/SpinedBuffer.java b/src/java.base/share/classes/java/util/stream/SpinedBuffer.java index 98bbc040a7b49..99be057fce6a4 100644 --- a/src/java.base/share/classes/java/util/stream/SpinedBuffer.java +++ b/src/java.base/share/classes/java/util/stream/SpinedBuffer.java @@ -37,6 +37,7 @@ import java.util.function.IntConsumer; import java.util.function.IntFunction; import java.util.function.LongConsumer; +import org.checkerframework.dataflow.qual.Pure; /** * An ordered collection of elements. Elements can be added, but not removed. @@ -157,6 +158,7 @@ protected void increaseCapacity() { /** * Retrieve the element at the specified index. */ + @Pure public E get(long index) { // @@@ can further optimize by caching last seen spineIndex, // which is going to be right most of the time @@ -770,6 +772,7 @@ public void accept(int i) { curChunk[elementIndex++] = i; } + @Pure public int get(long index) { // Casts to int are safe since the spine array index is the index minus // the prior element count from the current spine @@ -885,6 +888,7 @@ public void accept(long i) { curChunk[elementIndex++] = i; } + @Pure public long get(long index) { // Casts to int are safe since the spine array index is the index minus // the prior element count from the current spine @@ -1002,6 +1006,7 @@ public void accept(double i) { curChunk[elementIndex++] = i; } + @Pure public double get(long index) { // Casts to int are safe since the spine array index is the index minus // the prior element count from the current spine diff --git a/src/java.base/share/classes/java/util/zip/ZipFile.java b/src/java.base/share/classes/java/util/zip/ZipFile.java index 222c6d4a0c605..715c037467e4e 100644 --- a/src/java.base/share/classes/java/util/zip/ZipFile.java +++ b/src/java.base/share/classes/java/util/zip/ZipFile.java @@ -510,8 +510,8 @@ public ZipEntryIterator(int entryCount) { } @Override - @EnsuresNonEmptyIf(result = true, expression = "this") @Pure + @EnsuresNonEmptyIf(result = true, expression = "this") public boolean hasMoreElements() { return hasNext(); } From d41273387b9eba1315017d52e949a27f8d728f1b Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 19 May 2026 18:03:30 -0700 Subject: [PATCH 12/15] `@SideEffectFree` annotations --- .../share/classes/java/util/AbstractList.java | 3 +++ .../share/classes/java/util/AbstractMap.java | 7 +++++++ .../share/classes/java/util/ArrayDeque.java | 1 + .../share/classes/java/util/ArrayList.java | 3 +++ .../share/classes/java/util/Collection.java | 1 - .../share/classes/java/util/Collections.java | 10 +-------- .../share/classes/java/util/EnumMap.java | 5 +++++ .../share/classes/java/util/EnumSet.java | 8 +++++++ .../share/classes/java/util/HashMap.java | 3 +++ .../share/classes/java/util/HashSet.java | 2 ++ .../share/classes/java/util/Hashtable.java | 4 ++++ .../classes/java/util/IdentityHashMap.java | 4 +--- .../share/classes/java/util/JumboEnumSet.java | 2 ++ .../classes/java/util/LinkedHashMap.java | 6 ++++++ .../classes/java/util/LinkedHashSet.java | 3 +++ .../share/classes/java/util/LinkedList.java | 6 +++++- .../share/classes/java/util/List.java | 1 - .../share/classes/java/util/Map.java | 8 +++++++ .../classes/java/util/PriorityQueue.java | 2 +- .../share/classes/java/util/Properties.java | 11 +++++++++- .../classes/java/util/RegularEnumSet.java | 1 + .../java/util/ReverseOrderDequeView.java | 5 +++++ .../java/util/ReverseOrderListView.java | 6 ++++++ .../java/util/ReverseOrderSortedMapView.java | 19 +++++++++++++++++ .../java/util/ReverseOrderSortedSetView.java | 14 +++++++++++++ .../share/classes/java/util/Set.java | 15 ++++++++++++- .../share/classes/java/util/SortedSet.java | 1 + .../share/classes/java/util/TreeMap.java | 14 +++++++++++++ .../share/classes/java/util/TreeSet.java | 1 + .../share/classes/java/util/Vector.java | 1 + .../share/classes/java/util/WeakHashMap.java | 2 +- .../util/concurrent/ArrayBlockingQueue.java | 4 ++++ .../util/concurrent/ConcurrentHashMap.java | 5 +++++ .../concurrent/ConcurrentLinkedDeque.java | 4 +++- .../concurrent/ConcurrentLinkedQueue.java | 2 +- .../concurrent/ConcurrentNavigableMap.java | 1 + .../concurrent/ConcurrentSkipListMap.java | 21 +++++++++++++++++++ .../concurrent/ConcurrentSkipListSet.java | 7 +++++++ .../util/concurrent/CopyOnWriteArrayList.java | 16 ++++++++++++++ .../util/concurrent/CopyOnWriteArraySet.java | 3 +++ .../java/util/concurrent/DelayQueue.java | 1 - .../util/concurrent/LinkedBlockingDeque.java | 4 ++++ .../util/concurrent/LinkedBlockingQueue.java | 4 ++++ .../util/concurrent/LinkedTransferQueue.java | 4 ++++ .../concurrent/PriorityBlockingQueue.java | 4 ++++ .../util/concurrent/SynchronousQueue.java | 2 +- .../classes/java/util/jar/Attributes.java | 5 +++++ .../java/util/stream/SpinedBuffer.java | 14 ++++++++++++- .../classes/java/util/stream/Stream.java | 1 - 49 files changed, 246 insertions(+), 25 deletions(-) diff --git a/src/java.base/share/classes/java/util/AbstractList.java b/src/java.base/share/classes/java/util/AbstractList.java index 423db23761629..7997e85e864b4 100644 --- a/src/java.base/share/classes/java/util/AbstractList.java +++ b/src/java.base/share/classes/java/util/AbstractList.java @@ -899,6 +899,7 @@ public boolean addAll(int index, Collection c) { return true; } + @SideEffectFree public Iterator iterator() { return listIterator(); } @@ -971,6 +972,7 @@ public void add(E e) { }; } + @SideEffectFree public List subList(int fromIndex, int toIndex) { subListRangeCheck(fromIndex, toIndex, size); return new SubList<>(this, fromIndex, toIndex); @@ -1020,6 +1022,7 @@ private static class RandomAccessSubList super(parent, fromIndex, toIndex); } + @SideEffectFree public List subList(int fromIndex, int toIndex) { subListRangeCheck(fromIndex, toIndex, size); return new RandomAccessSubList<>(this, fromIndex, toIndex); diff --git a/src/java.base/share/classes/java/util/AbstractMap.java b/src/java.base/share/classes/java/util/AbstractMap.java index b8462e5fe9f10..79f7049ca7047 100644 --- a/src/java.base/share/classes/java/util/AbstractMap.java +++ b/src/java.base/share/classes/java/util/AbstractMap.java @@ -389,6 +389,7 @@ public void clear(@GuardSatisfied AbstractMap this) { Set ks = keySet; if (ks == null) { ks = new AbstractSet() { + @SideEffectFree public Iterator iterator() { return new Iterator() { private Iterator> i = entrySet().iterator(); @@ -462,6 +463,7 @@ public Collection values(@GuardSatisfied AbstractMap this) { Collection vals = values; if (vals == null) { vals = new AbstractCollection() { + @SideEffectFree public Iterator iterator() { return new Iterator() { private Iterator> i = entrySet().iterator(); @@ -636,6 +638,7 @@ public String toString(@GuardSatisfied AbstractMap this) { * * @return a shallow copy of this map */ + @SideEffectFree protected Object clone() throws CloneNotSupportedException { AbstractMap result = (AbstractMap)super.clone(); result.keySet = null; @@ -1000,6 +1003,7 @@ public String toString(AbstractMap.@GuardSatisfied SimpleImmutableEntry th public void forEach(Consumer c) { view().forEach(c); } @Pure public boolean isEmpty() { return view().isEmpty(); } + @SideEffectFree public Iterator iterator() { return view().iterator(); } public Stream parallelStream() { return view().parallelStream(); } // @SideEffectsOnly("this") @@ -1016,11 +1020,14 @@ public String toString(AbstractMap.@GuardSatisfied SimpleImmutableEntry th public boolean retainAll(Collection c) { return view().retainAll(c); } @Pure public int size() { return view().size(); } + @SideEffectFree public Spliterator spliterator() { return view().spliterator(); } public Stream stream() { return view().stream(); } + @SideEffectFree public Object[] toArray() { return view().toArray(); } public T[] toArray(IntFunction generator) { return view().toArray(generator); } public T[] toArray(T[] a) { return view().toArray(a); } + @SideEffectFree public String toString() { return view().toString(); } } } diff --git a/src/java.base/share/classes/java/util/ArrayDeque.java b/src/java.base/share/classes/java/util/ArrayDeque.java index ab4ab1881f697..56490f9810600 100644 --- a/src/java.base/share/classes/java/util/ArrayDeque.java +++ b/src/java.base/share/classes/java/util/ArrayDeque.java @@ -868,6 +868,7 @@ public final void forEachRemaining(Consumer action) { * @return a {@code Spliterator} over the elements in this deque * @since 1.8 */ + @SideEffectFree public Spliterator spliterator() { return new DeqSpliterator(); } diff --git a/src/java.base/share/classes/java/util/ArrayList.java b/src/java.base/share/classes/java/util/ArrayList.java index dd0ea7e78e5ff..1ec69c77e7020 100644 --- a/src/java.base/share/classes/java/util/ArrayList.java +++ b/src/java.base/share/classes/java/util/ArrayList.java @@ -1284,6 +1284,7 @@ public void add(E e) { */ // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") + @SideEffectFree public @PolyGrowShrink List subList(@GuardSatisfied @PolyGrowShrink ArrayList this, @NonNegative int fromIndex, @NonNegative int toIndex) { subListRangeCheck(fromIndex, toIndex, size); return new SubList<>(this, fromIndex, toIndex); @@ -1424,6 +1425,7 @@ public boolean removeIf(Predicate filter) { return modified; } + @SideEffectFree public @PolyNull @PolySigned Object[] toArray(SubList<@PolyNull @PolySigned E> this) { checkForComodification(); return Arrays.copyOfRange(root.elementData, offset, offset + size); @@ -1610,6 +1612,7 @@ final void checkForComodification() { }; } + @SideEffectFree public List subList(int fromIndex, int toIndex) { subListRangeCheck(fromIndex, toIndex, size); return new SubList<>(this, fromIndex, toIndex); diff --git a/src/java.base/share/classes/java/util/Collection.java b/src/java.base/share/classes/java/util/Collection.java index 3a8a2a522ab13..79c8e8a7bc811 100644 --- a/src/java.base/share/classes/java/util/Collection.java +++ b/src/java.base/share/classes/java/util/Collection.java @@ -411,7 +411,6 @@ public interface Collection extends Iterable { * runtime component type} of the specified array * @throws NullPointerException if the specified array is null */ - @SideEffectFree @Nullable T [] toArray(@PolyNull T[] a); /** diff --git a/src/java.base/share/classes/java/util/Collections.java b/src/java.base/share/classes/java/util/Collections.java index 8bfa36ea789bf..8f2111262b066 100644 --- a/src/java.base/share/classes/java/util/Collections.java +++ b/src/java.base/share/classes/java/util/Collections.java @@ -291,8 +291,7 @@ else if (cmp > 0) * Gets the ith element from the given list by repositioning the specified * list listIterator. */ - @Pure - @SideEffectsOnly("#1") + // @SideEffectsOnly("#1") private static T get(ListIterator i, int index) { T obj; int pos = i.nextIndex(); @@ -1112,7 +1111,6 @@ static class UnmodifiableCollection implements Collection, Serializable { public boolean contains(@UnknownSignedness Object o) {return c.contains(o);} @SideEffectFree public @PolyNull @PolySigned Object[] toArray(Collections.UnmodifiableCollection<@PolyNull @PolySigned E> this) {return c.toArray();} - @SideEffectFree public @Nullable T[] toArray(@PolyNull T[] a) {return c.toArray(a);} public T[] toArray(IntFunction f) {return c.toArray(f);} public String toString() {return c.toString();} @@ -2536,7 +2534,6 @@ public boolean contains(@UnknownSignedness Object o) { public @PolyNull @PolySigned Object[] toArray(Collections.SynchronizedCollection<@PolyNull @PolySigned E> this) { synchronized (mutex) {return c.toArray();} } - @SideEffectFree public @Nullable T[] toArray(@PolyNull T[] a) { synchronized (mutex) {return c.toArray(a);} } @@ -3696,7 +3693,6 @@ private String badElementMsg(Object o) { public boolean contains(@UnknownSignedness Object o) { return c.contains(o); } @SideEffectFree public @PolyNull @PolySigned Object[] toArray(Collections.CheckedCollection<@PolyNull @PolySigned E> this) { return c.toArray(); } - @SideEffectFree public @Nullable T[] toArray(@PolyNull T[] a) { return c.toArray(a); } public T[] toArray(IntFunction f) { return c.toArray(f); } public String toString() { return c.toString(); } @@ -5168,7 +5164,6 @@ public void clear() {} @SideEffectFree public @PolyNull @PolySigned Object[] toArray(Collections.EmptySet<@PolyNull @PolySigned E> this) { return new Object[0]; } - @SideEffectFree public @Nullable T[] toArray(@PolyNull T[] a) { if (a.length > 0) a[0] = null; @@ -5313,7 +5308,6 @@ public void clear() {} @SideEffectFree public @PolyNull @PolySigned Object[] toArray(Collections.EmptyList<@PolyNull @PolySigned E> this) { return new Object[0]; } - @SideEffectFree public @Nullable T[] toArray(@PolyNull T[] a) { if (a.length > 0) a[0] = null; @@ -6551,7 +6545,6 @@ private static class SetFromMap extends AbstractSet public Iterator iterator() { return s.iterator(); } @SideEffectFree public @PolyNull @PolySigned Object[] toArray(Collections.SetFromMap<@PolyNull @PolySigned E> this) { return s.toArray(); } - @SideEffectFree public @Nullable T[] toArray(@PolyNull T[] a) { return s.toArray(a); } public String toString() { return s.toString(); } @Pure @@ -6741,7 +6734,6 @@ static class AsLIFOQueue extends AbstractQueue public Iterator iterator() { return q.iterator(); } @SideEffectFree public @PolyNull @PolySigned Object[] toArray(Collections.AsLIFOQueue<@PolyNull @PolySigned E> this) { return q.toArray(); } - @SideEffectFree public @Nullable T[] toArray(@PolyNull T[] a) { return q.toArray(a); } public T[] toArray(IntFunction f) { return q.toArray(f); } public String toString() { return q.toString(); } diff --git a/src/java.base/share/classes/java/util/EnumMap.java b/src/java.base/share/classes/java/util/EnumMap.java index bfdda342b7e6a..3ea7ee73194ab 100644 --- a/src/java.base/share/classes/java/util/EnumMap.java +++ b/src/java.base/share/classes/java/util/EnumMap.java @@ -133,6 +133,7 @@ public int hashCode() { return 0; } + @SideEffectFree public String toString() { return "java.util.EnumMap.NULL"; } @@ -416,6 +417,7 @@ public void clear() { * * @return a set view of the keys contained in this enum map */ + @SideEffectFree public Set keySet() { Set ks = keySet; if (ks == null) { @@ -463,6 +465,7 @@ public void clear() { * * @return a collection view of the values contained in this map */ + @SideEffectFree public Collection values() { Collection vs = values; if (vs == null) { @@ -721,6 +724,7 @@ public int hashCode() { return entryHashCode(index); } + @SideEffectFree public String toString() { if (index < 0) return super.toString(); @@ -825,6 +829,7 @@ private int entryHashCode(int index) { * @return a shallow copy of this enum map */ @SuppressWarnings("unchecked") + @SideEffectFree public EnumMap clone() { EnumMap result = null; try { diff --git a/src/java.base/share/classes/java/util/EnumSet.java b/src/java.base/share/classes/java/util/EnumSet.java index 02b36184d757a..2f092fce95c60 100644 --- a/src/java.base/share/classes/java/util/EnumSet.java +++ b/src/java.base/share/classes/java/util/EnumSet.java @@ -158,6 +158,7 @@ public static > EnumSet allOf(Class elementType) { * @return A copy of the specified enum set. * @throws NullPointerException if {@code s} is null */ + @SideEffectFree public static > EnumSet copyOf(EnumSet s) { return s.clone(); } @@ -176,6 +177,7 @@ public static > EnumSet copyOf(EnumSet s) { * {@code EnumSet} instance and contains no elements * @throws NullPointerException if {@code c} is null */ + @SideEffectFree public static > EnumSet copyOf(Collection c) { if (c instanceof EnumSet) { return ((EnumSet)c).clone(); @@ -221,6 +223,7 @@ public static > EnumSet complementOf(EnumSet s) { * @throws NullPointerException if {@code e} is null * @return an enum set initially containing the specified element */ + @SideEffectFree public static > EnumSet of(E e) { EnumSet result = noneOf(e.getDeclaringClass()); result.add(e); @@ -242,6 +245,7 @@ public static > EnumSet of(E e) { * @throws NullPointerException if any parameters are null * @return an enum set initially containing the specified elements */ + @SideEffectFree public static > EnumSet of(E e1, E e2) { EnumSet result = noneOf(e1.getDeclaringClass()); result.add(e1); @@ -265,6 +269,7 @@ public static > EnumSet of(E e1, E e2) { * @throws NullPointerException if any parameters are null * @return an enum set initially containing the specified elements */ + @SideEffectFree public static > EnumSet of(E e1, E e2, E e3) { EnumSet result = noneOf(e1.getDeclaringClass()); result.add(e1); @@ -290,6 +295,7 @@ public static > EnumSet of(E e1, E e2, E e3) { * @throws NullPointerException if any parameters are null * @return an enum set initially containing the specified elements */ + @SideEffectFree public static > EnumSet of(E e1, E e2, E e3, E e4) { EnumSet result = noneOf(e1.getDeclaringClass()); result.add(e1); @@ -344,6 +350,7 @@ public static > EnumSet of(E e1, E e2, E e3, E e4, * @return an enum set initially containing the specified elements */ @SafeVarargs + @SideEffectFree public static > EnumSet of(E first, E... rest) { EnumSet result = noneOf(first.getDeclaringClass()); result.add(first); @@ -390,6 +397,7 @@ public static > EnumSet range(E from, E to) { @SuppressWarnings("unchecked") // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") + @SideEffectFree public EnumSet clone() { try { return (EnumSet) super.clone(); diff --git a/src/java.base/share/classes/java/util/HashMap.java b/src/java.base/share/classes/java/util/HashMap.java index b60cbfca9cfdb..5ea19f8739351 100644 --- a/src/java.base/share/classes/java/util/HashMap.java +++ b/src/java.base/share/classes/java/util/HashMap.java @@ -315,6 +315,7 @@ static class Node implements Map.Entry { public final K getKey() { return key; } @Pure public final V getValue() { return value; } + @SideEffectFree public final String toString() { return key + "=" + value; } @Pure @@ -1050,6 +1051,7 @@ public final Spliterator spliterator() { return new KeySpliterator<>(HashMap.this, 0, -1, 0, 0); } + @SideEffectFree public Object[] toArray() { return keysToArray(new Object[size]); } @@ -1116,6 +1118,7 @@ public final Spliterator spliterator() { return new ValueSpliterator<>(HashMap.this, 0, -1, 0, 0); } + @SideEffectFree public Object[] toArray() { return valuesToArray(new Object[size]); } diff --git a/src/java.base/share/classes/java/util/HashSet.java b/src/java.base/share/classes/java/util/HashSet.java index 98dc6de2f27ce..cdf44f001e5ee 100644 --- a/src/java.base/share/classes/java/util/HashSet.java +++ b/src/java.base/share/classes/java/util/HashSet.java @@ -401,11 +401,13 @@ private void readObject(java.io.ObjectInputStream s) */ // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") + @SideEffectFree public Spliterator spliterator() { return new HashMap.KeySpliterator<>(map, 0, -1, 0, 0); } @Override + @SideEffectFree public Object[] toArray() { return map.keysToArray(new Object[map.size()]); } diff --git a/src/java.base/share/classes/java/util/Hashtable.java b/src/java.base/share/classes/java/util/Hashtable.java index 1ead43be81d6e..402eece52ad7d 100644 --- a/src/java.base/share/classes/java/util/Hashtable.java +++ b/src/java.base/share/classes/java/util/Hashtable.java @@ -294,6 +294,7 @@ public synchronized boolean isEmpty(@GuardSatisfied Hashtable this) { * @see #keySet() * @see Map */ + @SideEffectFree public synchronized Enumeration<@KeyFor({"this"}) K> keys() { return this.getEnumeration(KEYS); } @@ -310,6 +311,7 @@ public synchronized boolean isEmpty(@GuardSatisfied Hashtable this) { * @see #values() * @see Map */ + @SideEffectFree public synchronized Enumeration elements() { return this.getEnumeration(VALUES); } @@ -632,6 +634,7 @@ final Hashtable cloneHashtable() { * * @return a string representation of this hashtable */ + @SideEffectFree public synchronized String toString(@GuardSatisfied Hashtable this) { int max = size() - 1; if (max == -1) @@ -1507,6 +1510,7 @@ public int hashCode() { return hash ^ Objects.hashCode(value); } + @SideEffectFree public String toString() { return key.toString()+"="+value.toString(); } diff --git a/src/java.base/share/classes/java/util/IdentityHashMap.java b/src/java.base/share/classes/java/util/IdentityHashMap.java index 45670034dee2e..94be828c3902f 100644 --- a/src/java.base/share/classes/java/util/IdentityHashMap.java +++ b/src/java.base/share/classes/java/util/IdentityHashMap.java @@ -978,6 +978,7 @@ public int hashCode() { System.identityHashCode(traversalTable[index+1])); } + @SideEffectFree public String toString() { if (index < 0) return super.toString(); @@ -1106,7 +1107,6 @@ public Object[] toArray() { return toArray(new Object[0]); } @SuppressWarnings("unchecked") - @SideEffectFree public @Nullable T[] toArray(@PolyNull T[] a) { int expectedModCount = modCount; int size = size(); @@ -1206,7 +1206,6 @@ public Object[] toArray() { return toArray(new Object[0]); } @SuppressWarnings("unchecked") - @SideEffectFree public @Nullable T[] toArray(@PolyNull T[] a) { int expectedModCount = modCount; int size = size(); @@ -1340,7 +1339,6 @@ public Object[] toArray() { } @SuppressWarnings("unchecked") - @SideEffectFree public @Nullable T[] toArray(@PolyNull T[] a) { int expectedModCount = modCount; int size = size(); diff --git a/src/java.base/share/classes/java/util/JumboEnumSet.java b/src/java.base/share/classes/java/util/JumboEnumSet.java index d66a78539931b..1f41985d3beb7 100644 --- a/src/java.base/share/classes/java/util/JumboEnumSet.java +++ b/src/java.base/share/classes/java/util/JumboEnumSet.java @@ -117,6 +117,7 @@ void complement() { * * @return an iterator over the elements contained in this set */ + @SideEffectFree public @PolyGrowShrink @PolyNonEmpty Iterator iterator(@PolyGrowShrink @PolyNonEmpty JumboEnumSet this) { return new EnumSetIterator<>(); } @@ -420,6 +421,7 @@ private boolean recalculateSize() { return size != oldSize; } + @SideEffectFree public EnumSet clone() { JumboEnumSet result = (JumboEnumSet) super.clone(); result.elements = result.elements.clone(); diff --git a/src/java.base/share/classes/java/util/LinkedHashMap.java b/src/java.base/share/classes/java/util/LinkedHashMap.java index 6714c0aa3fdc7..aaed1b544154c 100644 --- a/src/java.base/share/classes/java/util/LinkedHashMap.java +++ b/src/java.base/share/classes/java/util/LinkedHashMap.java @@ -744,6 +744,7 @@ public final Spliterator spliterator() { Spliterator.DISTINCT); } + @SideEffectFree public Object[] toArray() { return keysToArray(new Object[size], reversed); } @@ -815,6 +816,7 @@ public SequencedSet reversed() { * * @return a view of the values contained in this map */ + @SideEffectFree public Collection values() { return sequencedValues(); } @@ -862,6 +864,7 @@ public final Spliterator spliterator() { Spliterator.ORDERED); } + @SideEffectFree public Object[] toArray() { return valuesToArray(new Object[size], reversed); } @@ -1253,14 +1256,17 @@ public void clear() { base.clear(); } + @SideEffectFree public Set keySet() { return base.sequencedKeySet().reversed(); } + @SideEffectFree public Collection values() { return base.sequencedValues().reversed(); } + @SideEffectFree public Set> entrySet() { return base.sequencedEntrySet().reversed(); } diff --git a/src/java.base/share/classes/java/util/LinkedHashSet.java b/src/java.base/share/classes/java/util/LinkedHashSet.java index 9a1fd11ec516b..f1b81b447f5c6 100644 --- a/src/java.base/share/classes/java/util/LinkedHashSet.java +++ b/src/java.base/share/classes/java/util/LinkedHashSet.java @@ -212,6 +212,7 @@ public LinkedHashSet(Collection c) { @Override // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") + @SideEffectFree public Spliterator spliterator() { return Spliterators.spliterator(this, Spliterator.DISTINCT | Spliterator.ORDERED); } @@ -330,6 +331,7 @@ public SequencedSet reversed() { class ReverseLinkedHashSetView extends AbstractSet implements SequencedSet { @Pure public int size() { return LinkedHashSet.this.size(); } + @SideEffectFree public Iterator iterator() { return map().sequencedKeySet().reversed().iterator(); } public boolean add(E e) { return LinkedHashSet.this.add(e); } public void addFirst(E e) { LinkedHashSet.this.addLast(e); } @@ -342,6 +344,7 @@ class ReverseLinkedHashSetView extends AbstractSet implements SequencedSet public E removeLast() { return LinkedHashSet.this.removeFirst(); } public SequencedSet reversed() { return LinkedHashSet.this; } @Pure + @SideEffectFree public Object[] toArray() { return map().keysToArray(new Object[map.size()], true); } public T[] toArray(T[] a) { return map().keysToArray(map.prepareArray(a), true); } } diff --git a/src/java.base/share/classes/java/util/LinkedList.java b/src/java.base/share/classes/java/util/LinkedList.java index 925b958e28411..6740c068eb551 100644 --- a/src/java.base/share/classes/java/util/LinkedList.java +++ b/src/java.base/share/classes/java/util/LinkedList.java @@ -1100,7 +1100,6 @@ private static class Node { * Adapter to provide descending iterators via ListItr.previous */ private class DescendingIterator implements Iterator { - @Pure private final ListItr itr = new ListItr(size()); @Pure @EnsuresNonEmptyIf(result = true, expression = "this") @@ -1410,6 +1409,7 @@ static class ReverseOrderLinkedListView extends LinkedList implements java this.rdeque = rdeque; } + @SideEffectFree public String toString() { return rlist.toString(); } @@ -1458,6 +1458,7 @@ public void forEach(Consumer action) { rlist.forEach(action); } + @SideEffectFree public Iterator iterator() { return rlist.iterator(); } @@ -1472,6 +1473,7 @@ public boolean equals(Object o) { return rlist.equals(o); } + @SideEffectFree public List subList(int fromIndex, int toIndex) { return rlist.subList(fromIndex, toIndex); } @@ -1495,6 +1497,7 @@ public LinkedList reversed() { return list; } + @SideEffectFree public Spliterator spliterator() { return rlist.spliterator(); } @@ -1503,6 +1506,7 @@ public T[] toArray(T[] a) { return rlist.toArray(a); } + @SideEffectFree public Object[] toArray() { return rlist.toArray(); } diff --git a/src/java.base/share/classes/java/util/List.java b/src/java.base/share/classes/java/util/List.java index f7d60fab9f4c3..d67a63db81e1c 100644 --- a/src/java.base/share/classes/java/util/List.java +++ b/src/java.base/share/classes/java/util/List.java @@ -270,7 +270,6 @@ public interface List extends SequencedCollection { * this list * @throws NullPointerException if the specified array is null */ - @SideEffectFree @Nullable T[] toArray(@PolyNull T[] a); diff --git a/src/java.base/share/classes/java/util/Map.java b/src/java.base/share/classes/java/util/Map.java index e3c9cc7635068..a4894dfa10a19 100644 --- a/src/java.base/share/classes/java/util/Map.java +++ b/src/java.base/share/classes/java/util/Map.java @@ -683,6 +683,7 @@ public static Comparator> comparingByValue(Comparator Map.Entry copyOf(Map.Entry e) { Objects.requireNonNull(e); if (e instanceof KeyValueHolder) { @@ -1423,6 +1424,7 @@ default boolean replace(K key, V oldValue, V newValue) { * @since 9 */ @SuppressWarnings("unchecked") + @SideEffectFree static Map of() { return (Map) ImmutableCollections.EMPTY_MAP; } @@ -1440,6 +1442,7 @@ static Map of() { * * @since 9 */ + @SideEffectFree static @NonEmpty Map of(K k1, V v1) { return new ImmutableCollections.Map1<>(k1, v1); } @@ -1460,6 +1463,7 @@ static Map of() { * * @since 9 */ + @SideEffectFree static @NonEmpty Map of(K k1, V v1, K k2, V v2) { return new ImmutableCollections.MapN<>(k1, v1, k2, v2); } @@ -1482,6 +1486,7 @@ static Map of() { * * @since 9 */ + @SideEffectFree static @NonEmpty Map of(K k1, V v1, K k2, V v2, K k3, V v3) { return new ImmutableCollections.MapN<>(k1, v1, k2, v2, k3, v3); } @@ -1506,6 +1511,7 @@ static Map of() { * * @since 9 */ + @SideEffectFree static @NonEmpty Map of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) { return new ImmutableCollections.MapN<>(k1, v1, k2, v2, k3, v3, k4, v4); } @@ -1532,6 +1538,7 @@ static Map of() { * * @since 9 */ + @SideEffectFree static @NonEmpty Map of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) { return new ImmutableCollections.MapN<>(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5); } @@ -1818,6 +1825,7 @@ static Map of() { * @since 10 */ @SuppressWarnings({"rawtypes","unchecked"}) + @SideEffectFree static @PolyNonEmpty Map copyOf(@PolyNonEmpty Map map) { if (map instanceof ImmutableCollections.AbstractImmutableMap) { return (Map)map; diff --git a/src/java.base/share/classes/java/util/PriorityQueue.java b/src/java.base/share/classes/java/util/PriorityQueue.java index 4d1225c89d839..b972e27762c84 100644 --- a/src/java.base/share/classes/java/util/PriorityQueue.java +++ b/src/java.base/share/classes/java/util/PriorityQueue.java @@ -482,7 +482,6 @@ public boolean contains(@GuardSatisfied PriorityQueue this, @GuardSatisfied @ * this queue * @throws NullPointerException if the specified array is null */ - @SideEffectFree public @Nullable T[] toArray(@PolyNull T[] a) { final int size = this.size; if (a.length < size) @@ -864,6 +863,7 @@ private void readObject(java.io.ObjectInputStream s) * @return a {@code Spliterator} over the elements in this queue * @since 1.8 */ + @SideEffectFree public final Spliterator spliterator() { return new PriorityQueueSpliterator(0, -1, 0); } diff --git a/src/java.base/share/classes/java/util/Properties.java b/src/java.base/share/classes/java/util/Properties.java index f4ae2ee1973f4..c6bd98b91b8b2 100644 --- a/src/java.base/share/classes/java/util/Properties.java +++ b/src/java.base/share/classes/java/util/Properties.java @@ -1330,12 +1330,14 @@ public boolean isEmpty() { } @Override + @SideEffectFree public Enumeration keys() { // CHM.keys() returns Iterator w/ remove() - instead wrap keySet() return Collections.enumeration(map.keySet()); } @Override + @SideEffectFree public Enumeration elements() { // CHM.elements() returns Iterator w/ remove() - instead wrap values() return Collections.enumeration(map.values()); @@ -1395,16 +1397,19 @@ public synchronized void clear() { } @Override + @SideEffectFree public synchronized String toString() { return map.toString(); } @Override + @SideEffectFree public Set<@KeyFor("this") Object> keySet() { return Collections.synchronizedSet(map.keySet(), this); } @Override + @SideEffectFree public Collection values() { return Collections.synchronizedCollection(map.values(), this); } @@ -1428,13 +1433,14 @@ private EntrySet(Set> entrySet) { } @Pure - @Pure @Override public int size() { return entrySet.size(); } + @Override public int size() { return entrySet.size(); } @Pure @EnsuresNonEmptyIf(result = false, expression = "this") @Override public boolean isEmpty() { return entrySet.isEmpty(); } @Pure @EnsuresNonEmptyIf(result = true, expression = "this") @Override public boolean contains(@UnknownSignedness Object o) { return entrySet.contains(o); } + @SideEffectFree @Override public Object[] toArray() { return entrySet.toArray(); } @Override public @Nullable T[] toArray(@PolyNull T[] a) { return entrySet.toArray(a); } // @SideEffectsOnly("this") @@ -1473,6 +1479,7 @@ public int hashCode() { } @Override + @SideEffectFree public String toString() { return entrySet.toString(); } @@ -1492,6 +1499,7 @@ public boolean retainAll(Collection c) { } @Override + @SideEffectFree public Iterator> iterator() { return entrySet.iterator(); } @@ -1590,6 +1598,7 @@ public synchronized Object replace(Object key, Object value) { protected void rehash() { /* no-op */ } @Override + @SideEffectFree public synchronized Object clone() { Properties clone = (Properties) cloneHashtable(); clone.map = new ConcurrentHashMap<>(map); diff --git a/src/java.base/share/classes/java/util/RegularEnumSet.java b/src/java.base/share/classes/java/util/RegularEnumSet.java index caa15d17f8579..353c772665b18 100644 --- a/src/java.base/share/classes/java/util/RegularEnumSet.java +++ b/src/java.base/share/classes/java/util/RegularEnumSet.java @@ -97,6 +97,7 @@ void complement() { * @return an iterator over the elements contained in this set */ @DoesNotUnrefineReceiver("modifiability") + @SideEffectFree public @PolyGrowShrink @PolyNonEmpty Iterator iterator(@PolyGrowShrink @PolyNonEmpty RegularEnumSet this) { return new EnumSetIterator<>(); } diff --git a/src/java.base/share/classes/java/util/ReverseOrderDequeView.java b/src/java.base/share/classes/java/util/ReverseOrderDequeView.java index 654420802de26..86a075afedda1 100644 --- a/src/java.base/share/classes/java/util/ReverseOrderDequeView.java +++ b/src/java.base/share/classes/java/util/ReverseOrderDequeView.java @@ -42,6 +42,7 @@ private ReverseOrderDequeView(Deque deque) { base = deque; } + @SideEffectFree public static Deque of(Deque deque) { if (deque instanceof ReverseOrderDequeView rodv) { return rodv.base; @@ -57,10 +58,12 @@ public void forEach(Consumer action) { action.accept(e); } + @SideEffectFree public Iterator iterator() { return base.descendingIterator(); } + @SideEffectFree public Spliterator spliterator() { return Spliterators.spliteratorUnknownSize(base.descendingIterator(), 0); } @@ -162,6 +165,7 @@ public Stream stream() { return StreamSupport.stream(spliterator(), false); } + @SideEffectFree public Object[] toArray() { return ArraysSupport.reverse(base.toArray()); } @@ -175,6 +179,7 @@ public T[] toArray(IntFunction generator) { return ArraysSupport.reverse(base.toArray(generator)); } + @SideEffectFree // copied from AbstractCollection public String toString() { Iterator it = iterator(); diff --git a/src/java.base/share/classes/java/util/ReverseOrderListView.java b/src/java.base/share/classes/java/util/ReverseOrderListView.java index a6b0b9e184c73..c59934e3a7a3c 100644 --- a/src/java.base/share/classes/java/util/ReverseOrderListView.java +++ b/src/java.base/share/classes/java/util/ReverseOrderListView.java @@ -44,6 +44,7 @@ class ReverseOrderListView implements List { final List base; final boolean modifiable; + @SideEffectFree public static List of(List list, boolean modifiable) { if (list instanceof ReverseOrderListView rolv) { return rolv.base; @@ -153,10 +154,12 @@ public void forEach(Consumer action) { action.accept(e); } + @SideEffectFree public Iterator iterator() { return new DescendingIterator(); } + @SideEffectFree public Spliterator spliterator() { // TODO can probably improve this return Spliterators.spliteratorUnknownSize(new DescendingIterator(), 0); @@ -296,6 +299,7 @@ public Stream stream() { return StreamSupport.stream(spliterator(), false); } + @SideEffectFree public Object[] toArray() { return ArraysSupport.reverse(base.toArray()); } @@ -310,6 +314,7 @@ public T[] toArray(IntFunction generator) { } // copied from AbstractCollection + @SideEffectFree public String toString() { Iterator it = iterator(); if (! it.hasNext()) @@ -408,6 +413,7 @@ public E set(int index, E element) { return base.set(size - index - 1, element); } + @SideEffectFree public List subList(int fromIndex, int toIndex) { int size = base.size(); Objects.checkFromToIndex(fromIndex, toIndex, size); diff --git a/src/java.base/share/classes/java/util/ReverseOrderSortedMapView.java b/src/java.base/share/classes/java/util/ReverseOrderSortedMapView.java index 1a15d09236e63..13036771c0061 100644 --- a/src/java.base/share/classes/java/util/ReverseOrderSortedMapView.java +++ b/src/java.base/share/classes/java/util/ReverseOrderSortedMapView.java @@ -41,6 +41,7 @@ private ReverseOrderSortedMapView(SortedMap map) { cmp = Collections.reverseOrder(map.comparator()); } + @SideEffectFree public static SortedMap of(SortedMap map) { if (map instanceof ReverseOrderSortedMapView rosmv) { return rosmv.base; @@ -55,6 +56,7 @@ public static SortedMap of(SortedMap map) { // hashCode: inherited from AbstractMap + @SideEffectFree public String toString() { return toString(this, descendingEntryIterator(base)); } @@ -102,9 +104,11 @@ public int size() { return base.size(); } + @SideEffectFree public Set keySet() { return new AbstractSet<>() { // inherit add(), which throws UOE + @SideEffectFree public Iterator iterator() { return descendingKeyIterator(base); } @Pure public int size() { return base.size(); } @@ -115,9 +119,11 @@ public Set keySet() { }; } + @SideEffectFree public Collection values() { return new AbstractCollection<>() { // inherit add(), which throws UOE + @SideEffectFree public Iterator iterator() { return descendingValueIterator(base); } @Pure public int size() { return base.size(); } @@ -128,9 +134,11 @@ public Collection values() { }; } + @SideEffectFree public Set> entrySet() { return new AbstractSet<>() { // inherit add(), which throws UOE + @SideEffectFree public Iterator> iterator() { return descendingEntryIterator(base); } @Pure public int size() { return base.size(); } @@ -186,6 +194,7 @@ public Comparator comparator() { return cmp; } + @SideEffectFree public SortedMap subMap(K fromKey, K toKey) { if (cmp.compare(fromKey, toKey) <= 0) { return new Submap(fromKey, toKey); @@ -194,10 +203,12 @@ public SortedMap subMap(K fromKey, K toKey) { } } + @SideEffectFree public SortedMap headMap(K toKey) { return new Submap(null, toKey); } + @SideEffectFree public SortedMap tailMap(K fromKey) { return new Submap(fromKey, null); } @@ -302,12 +313,14 @@ public int hashCode() { return Objects.hashCode(key) ^ Objects.hashCode(value); } + @SideEffectFree public String toString() { return key + "=" + value; } } // copied and modified from AbstractMap + @SideEffectFree static String toString(Map thisMap, Iterator> i) { if (! i.hasNext()) return "{}"; @@ -409,12 +422,15 @@ public void remove() { // hashCode: inherited from AbstractMap + @SideEffectFree public String toString() { return ReverseOrderSortedMapView.toString(this, entryIterator()); } + @SideEffectFree public Set> entrySet() { return new AbstractSet<>() { + @SideEffectFree public Iterator> iterator() { return entryIterator(); } @@ -471,6 +487,7 @@ public K lastKey() { return last.getKey(); } + @SideEffectFree public SortedMap subMap(K from, K to) { if (aboveHead(from) && belowTail(from) && aboveHead(to) && belowTail(to) && @@ -481,6 +498,7 @@ public SortedMap subMap(K from, K to) { } } + @SideEffectFree public SortedMap headMap(K to) { if (aboveHead(to) && belowTail(to)) return new Submap(head, to); @@ -488,6 +506,7 @@ public SortedMap headMap(K to) { throw new IllegalArgumentException(); } + @SideEffectFree public SortedMap tailMap(K from) { if (aboveHead(from) && belowTail(from)) return new Submap(from, tail); diff --git a/src/java.base/share/classes/java/util/ReverseOrderSortedSetView.java b/src/java.base/share/classes/java/util/ReverseOrderSortedSetView.java index bd3f00c97f7c1..63caa9d68f3aa 100644 --- a/src/java.base/share/classes/java/util/ReverseOrderSortedSetView.java +++ b/src/java.base/share/classes/java/util/ReverseOrderSortedSetView.java @@ -44,6 +44,7 @@ private ReverseOrderSortedSetView(SortedSet set) { comp = Collections.reverseOrder(set.comparator()); } + @SideEffectFree public static SortedSet of(SortedSet set) { if (set instanceof ReverseOrderSortedSetView rossv) { return rossv.base; @@ -86,6 +87,7 @@ public int hashCode() { } // copied from AbstractCollection + @SideEffectFree public String toString() { Iterator it = iterator(); if (! it.hasNext()) @@ -109,10 +111,12 @@ public void forEach(Consumer action) { action.accept(e); } + @SideEffectFree public Iterator iterator() { return descendingIterator(base); } + @SideEffectFree public Spliterator spliterator() { return Spliterators.spliteratorUnknownSize(descendingIterator(base), 0); } @@ -173,6 +177,7 @@ public Stream stream() { return StreamSupport.stream(spliterator(), false); } + @SideEffectFree public Object[] toArray() { return ArraysSupport.reverse(base.toArray()); } @@ -197,14 +202,17 @@ public Comparator comparator() { public E last() { return base.first(); } + @SideEffectFree public SortedSet headSet(E to) { return new Subset(null, to); } + @SideEffectFree public SortedSet subSet(E from, E to) { return new Subset(from, to); } + @SideEffectFree public SortedSet tailSet(E from) { return new Subset(from, null); } @@ -270,6 +278,7 @@ boolean belowTail(E e) { return tail == null || cmp.compare(e, tail) < 0; } + @SideEffectFree public Iterator iterator() { return new Iterator<>() { E cache = null; @@ -343,10 +352,12 @@ public Comparator comparator() { return ReverseOrderSortedSetView.this.comparator(); } + @SideEffectFree public E first() { return this.iterator().next(); } + @SideEffectFree public E last() { var it = this.iterator(); if (! it.hasNext()) @@ -357,6 +368,7 @@ public E last() { return last; } + @SideEffectFree public SortedSet subSet(E from, E to) { if (aboveHead(from) && belowTail(from) && aboveHead(to) && belowTail(to) && @@ -367,6 +379,7 @@ public SortedSet subSet(E from, E to) { } } + @SideEffectFree public SortedSet headSet(E to) { if (aboveHead(to) && belowTail(to)) return ReverseOrderSortedSetView.this.new Subset(head, to); @@ -374,6 +387,7 @@ public SortedSet headSet(E to) { throw new IllegalArgumentException(); } + @SideEffectFree public SortedSet tailSet(E from) { if (aboveHead(from) && belowTail(from)) return ReverseOrderSortedSetView.this.new Subset(null, tail); diff --git a/src/java.base/share/classes/java/util/Set.java b/src/java.base/share/classes/java/util/Set.java index a29820d648326..54ac68a1f87d1 100644 --- a/src/java.base/share/classes/java/util/Set.java +++ b/src/java.base/share/classes/java/util/Set.java @@ -243,7 +243,6 @@ public interface Set extends Collection { * set * @throws NullPointerException if the specified array is null */ - @SideEffectFree @Nullable T [] toArray(@PolyNull T[] a); @@ -469,6 +468,7 @@ public interface Set extends Collection { * @since 1.8 */ @Override + @SideEffectFree default Spliterator spliterator() { return Spliterators.spliterator(this, Spliterator.DISTINCT); } @@ -483,6 +483,7 @@ default Spliterator spliterator() { * @since 9 */ @SuppressWarnings("unchecked") + @SideEffectFree static Set of() { return (Set) ImmutableCollections.EMPTY_SET; } @@ -498,6 +499,7 @@ static Set of() { * * @since 9 */ + @SideEffectFree static @NonEmpty Set of(E e1) { return new ImmutableCollections.Set12<>(e1); } @@ -515,6 +517,7 @@ static Set of() { * * @since 9 */ + @SideEffectFree static @NonEmpty Set of(E e1, E e2) { return new ImmutableCollections.Set12<>(e1, e2); } @@ -533,6 +536,7 @@ static Set of() { * * @since 9 */ + @SideEffectFree static @NonEmpty Set of(E e1, E e2, E e3) { return new ImmutableCollections.SetN<>(e1, e2, e3); } @@ -552,6 +556,7 @@ static Set of() { * * @since 9 */ + @SideEffectFree static @NonEmpty Set of(E e1, E e2, E e3, E e4) { return new ImmutableCollections.SetN<>(e1, e2, e3, e4); } @@ -572,6 +577,7 @@ static Set of() { * * @since 9 */ + @SideEffectFree static @NonEmpty Set of(E e1, E e2, E e3, E e4, E e5) { return new ImmutableCollections.SetN<>(e1, e2, e3, e4, e5); } @@ -593,6 +599,7 @@ static Set of() { * * @since 9 */ + @SideEffectFree static @NonEmpty Set of(E e1, E e2, E e3, E e4, E e5, E e6) { return new ImmutableCollections.SetN<>(e1, e2, e3, e4, e5, e6); @@ -616,6 +623,7 @@ static Set of() { * * @since 9 */ + @SideEffectFree static @NonEmpty Set of(E e1, E e2, E e3, E e4, E e5, E e6, E e7) { return new ImmutableCollections.SetN<>(e1, e2, e3, e4, e5, e6, e7); @@ -640,6 +648,7 @@ static Set of() { * * @since 9 */ + @SideEffectFree static @NonEmpty Set of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8) { return new ImmutableCollections.SetN<>(e1, e2, e3, e4, e5, e6, e7, e8); @@ -665,6 +674,7 @@ static Set of() { * * @since 9 */ + @SideEffectFree static @NonEmpty Set of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9) { return new ImmutableCollections.SetN<>(e1, e2, e3, e4, e5, e6, e7, e8, e9); @@ -691,6 +701,7 @@ static Set of() { * * @since 9 */ + @SideEffectFree static @NonEmpty Set of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10) { return new ImmutableCollections.SetN<>(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10); @@ -724,6 +735,7 @@ static Set of() { */ @SafeVarargs @SuppressWarnings("varargs") + @SideEffectFree static Set of(E... elements) { switch (elements.length) { // implicit null check of elements case 0: @@ -757,6 +769,7 @@ static Set of(E... elements) { * @since 10 */ @SuppressWarnings("unchecked") + @SideEffectFree static @PolyNonEmpty Set copyOf(@PolyNonEmpty Collection coll) { if (coll instanceof ImmutableCollections.AbstractImmutableSet) { return (Set)coll; diff --git a/src/java.base/share/classes/java/util/SortedSet.java b/src/java.base/share/classes/java/util/SortedSet.java index 7b71cd5f774c1..60691f4c2c634 100644 --- a/src/java.base/share/classes/java/util/SortedSet.java +++ b/src/java.base/share/classes/java/util/SortedSet.java @@ -271,6 +271,7 @@ public interface SortedSet extends Set, SequencedSet { @Override // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") + @SideEffectFree default Spliterator spliterator() { return new Spliterators.IteratorSpliterator( this, Spliterator.DISTINCT | Spliterator.SORTED | Spliterator.ORDERED) { diff --git a/src/java.base/share/classes/java/util/TreeMap.java b/src/java.base/share/classes/java/util/TreeMap.java index 46ce4bf140a00..e11638f940254 100644 --- a/src/java.base/share/classes/java/util/TreeMap.java +++ b/src/java.base/share/classes/java/util/TreeMap.java @@ -987,6 +987,7 @@ public void clear(@GuardSatisfied TreeMap this) { */ // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") + @SideEffectFree public Object clone(@GuardSatisfied TreeMap this) { TreeMap clone; try { @@ -1180,6 +1181,7 @@ public Object clone(@GuardSatisfied TreeMap this) { */ // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") + @SideEffectFree public Set<@KeyFor({"this"}) K> keySet(@GuardSatisfied TreeMap this) { return navigableKeySet(); } @@ -1222,6 +1224,7 @@ public Object clone(@GuardSatisfied TreeMap this) { * {@code retainAll} and {@code clear} operations. It does not * support the {@code add} or {@code addAll} operations. */ + @SideEffectFree public Collection values(@GuardSatisfied TreeMap this) { Collection vs = values; if (vs == null) { @@ -1546,7 +1549,9 @@ public Iterator descendingIterator() { public E floor(E e) { return m.floorKey(e); } public E ceiling(E e) { return m.ceilingKey(e); } public E higher(E e) { return m.higherKey(e); } + @SideEffectFree public E first() { return m.firstKey(); } + @SideEffectFree public E last() { return m.lastKey(); } @Pure public Comparator comparator() { return m.comparator(); } @@ -1570,18 +1575,23 @@ public NavigableSet subSet(E fromElement, boolean fromInclusive, return new KeySet<>(m.subMap(fromElement, fromInclusive, toElement, toInclusive)); } + @SideEffectFree public NavigableSet headSet(E toElement, boolean inclusive) { return new KeySet<>(m.headMap(toElement, inclusive)); } + @SideEffectFree public NavigableSet tailSet(E fromElement, boolean inclusive) { return new KeySet<>(m.tailMap(fromElement, inclusive)); } + @SideEffectFree public SortedSet subSet(E fromElement, E toElement) { return subSet(fromElement, true, toElement, false); } + @SideEffectFree public SortedSet headSet(E toElement) { return headSet(toElement, false); } + @SideEffectFree public SortedSet tailSet(E fromElement) { return tailSet(fromElement, true); } @@ -2084,6 +2094,7 @@ public final NavigableSet navigableKeySet() { (navigableKeySetView = new TreeMap.KeySet<>(this)); } + @SideEffectFree public final Set keySet() { return navigableKeySet(); } @@ -2427,6 +2438,7 @@ Iterator descendingKeyIterator() { } final class AscendingEntrySetView extends EntrySetView { + @SideEffectFree public Iterator> iterator() { return new SubMapEntryIterator(absLowest(), absHighFence()); } @@ -2520,6 +2532,7 @@ Iterator descendingKeyIterator() { } final class DescendingEntrySetView extends EntrySetView { + @SideEffectFree public Iterator> iterator() { return new DescendingSubMapEntryIterator(absHighest(), absLowFence()); } @@ -2653,6 +2666,7 @@ public int hashCode() { return keyHash ^ valueHash; } + @SideEffectFree public String toString() { return key + "=" + value; } diff --git a/src/java.base/share/classes/java/util/TreeSet.java b/src/java.base/share/classes/java/util/TreeSet.java index 0e90aeef805b6..a0450cf215b12 100644 --- a/src/java.base/share/classes/java/util/TreeSet.java +++ b/src/java.base/share/classes/java/util/TreeSet.java @@ -637,6 +637,7 @@ private void readObject(java.io.ObjectInputStream s) */ // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") + @SideEffectFree public Spliterator spliterator() { return TreeMap.keySpliteratorFor(m); } diff --git a/src/java.base/share/classes/java/util/Vector.java b/src/java.base/share/classes/java/util/Vector.java index a60aa2d93cfc9..83d13368bd24f 100644 --- a/src/java.base/share/classes/java/util/Vector.java +++ b/src/java.base/share/classes/java/util/Vector.java @@ -352,6 +352,7 @@ public synchronized boolean isEmpty(@GuardSatisfied Vector this) { * @return an enumeration of the components of this vector * @see Iterator */ + @SideEffectFree public @PolyGrowShrink @PolyNonEmpty Enumeration elements(@PolyGrowShrink @PolyNonEmpty Vector this) { return new Enumeration() { int count = 0; diff --git a/src/java.base/share/classes/java/util/WeakHashMap.java b/src/java.base/share/classes/java/util/WeakHashMap.java index 3cf4274beae18..85f6a9be05868 100644 --- a/src/java.base/share/classes/java/util/WeakHashMap.java +++ b/src/java.base/share/classes/java/util/WeakHashMap.java @@ -803,6 +803,7 @@ public int hashCode() { return Objects.hashCode(k) ^ Objects.hashCode(v); } + @SideEffectFree public String toString() { return getKey() + "=" + getValue(); } @@ -1090,7 +1091,6 @@ public Object[] toArray() { return deepCopy().toArray(); } - @SideEffectFree public @Nullable T[] toArray(@PolyNull T[] a) { return deepCopy().toArray(a); } diff --git a/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java index 684b4b094df89..ea16b957c8771 100644 --- a/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java @@ -613,6 +613,7 @@ public boolean contains(@GuardSatisfied @Nullable @UnknownSignedness Object o) * * @return an array containing all of the elements in this queue */ + @SideEffectFree public @PolyNull @PolySigned Object[] toArray(ArrayBlockingQueue<@PolyNull @PolySigned E> this) { final ReentrantLock lock = this.lock; lock.lock(); @@ -687,6 +688,7 @@ public boolean contains(@GuardSatisfied @Nullable @UnknownSignedness Object o) } } + @SideEffectFree public String toString() { return Helpers.collectionToString(this); } @@ -802,6 +804,7 @@ else if (i > take) * * @return an iterator over the elements in this queue in proper sequence */ + @SideEffectFree public @PolyGrowShrink @PolyNonEmpty Iterator iterator(@PolyGrowShrink @PolyNonEmpty ArrayBlockingQueue this) { return new Itr(); } @@ -1486,6 +1489,7 @@ boolean takeIndexWrapped() { * @return a {@code Spliterator} over the elements in this queue * @since 1.8 */ + @SideEffectFree public Spliterator spliterator() { return Spliterators.spliterator (this, (Spliterator.ORDERED | diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java index 96d8e59b50475..f9f090d33a2ba 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java @@ -665,6 +665,7 @@ static class Node implements Map.Entry { public final V getValue() { return val; } @Pure public final int hashCode() { return key.hashCode() ^ val.hashCode(); } + @SideEffectFree public final String toString() { return Helpers.mapEntryToString(key, val); } @@ -1361,6 +1362,7 @@ public int hashCode() { * * @return a string representation of this map */ + @SideEffectFree public String toString() { Node[] t; int f = (t = table) == null ? 0 : t.length; @@ -2285,6 +2287,7 @@ public static KeySetView newKeySet(int initialCapacity) { * @return the set view * @throws NullPointerException if the mappedValue is null */ + @SideEffectFree public KeySetView keySet(V mappedValue) { if (mappedValue == null) throw new NullPointerException(); @@ -3606,6 +3609,7 @@ static final class MapEntry implements Map.Entry { public V getValue() { return val; } @Pure public int hashCode() { return key.hashCode() ^ val.hashCode(); } + @SideEffectFree public String toString() { return Helpers.mapEntryToString(key, val); } @@ -4616,6 +4620,7 @@ abstract static sealed class CollectionView * * @return a string representation of this collection */ + @SideEffectFree public final String toString() { StringBuilder sb = new StringBuilder(); sb.append('['); diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java index 571a27f9446ed..ce2d2a01ebd73 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java @@ -1284,6 +1284,7 @@ public void clear(@GuardSatisfied @CanShrink ConcurrentLinkedDeque this) { ; } + @SideEffectFree public String toString() { String[] a = null; restart: for (;;) { @@ -1395,7 +1396,6 @@ else if (a != null && size <= a.length) { * this deque * @throws NullPointerException if the specified array is null */ - @SideEffectFree @SuppressWarnings("unchecked") public @Nullable T[] toArray(@PolyNull T[] a) { if (a == null) throw new NullPointerException(); @@ -1510,6 +1510,7 @@ public void remove() { /** Forward iterator */ private class Itr extends AbstractItr { Itr() {} // prevent access constructor creation + @SideEffectFree Node startNode() { return first(); } Node nextNode(Node p) { return succ(p); } } @@ -1517,6 +1518,7 @@ private class Itr extends AbstractItr { /** Descending iterator */ private class DescendingItr extends AbstractItr { DescendingItr() {} // prevent access constructor creation + @SideEffectFree Node startNode() { return last(); } Node nextNode(Node p) { return pred(p); } } diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java index 25962bc5d6b74..20956d9251c4d 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java @@ -638,6 +638,7 @@ else if (p == q) } } + @SideEffectFree public String toString() { String[] a = null; restartFromHead: for (;;) { @@ -747,7 +748,6 @@ else if (a != null && size <= a.length) { * this queue * @throws NullPointerException if the specified array is null */ - @SideEffectFree @SuppressWarnings("unchecked") public @Nullable T[] toArray(@PolyNull T[] a) { Objects.requireNonNull(a); diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentNavigableMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentNavigableMap.java index f201d63bcb851..1ff2b80f20889 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentNavigableMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentNavigableMap.java @@ -157,6 +157,7 @@ ConcurrentNavigableMap subMap(K fromKey, boolean fromInclusive, * * @return a navigable set view of the keys in this map */ + @SideEffectFree NavigableSet keySet(); /** diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java index 9deac7e18d5ce..5da0d61133791 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java @@ -1135,6 +1135,7 @@ public ConcurrentSkipListMap(SortedMap m) { * * @return a shallow copy of this map */ + @SideEffectFree public ConcurrentSkipListMap clone() { try { @SuppressWarnings("unchecked") @@ -1641,6 +1642,7 @@ else if (doRemove(key, v) != null) * * @return a navigable set view of the keys in this map */ + @SideEffectFree public NavigableSet keySet() { KeySet ks; if ((ks = keySet) != null) return ks; @@ -1673,6 +1675,7 @@ public NavigableSet navigableKeySet() { *

The view's iterators and spliterators are * weakly consistent. */ + @SideEffectFree public Collection values() { Values vs; if ((vs = values) != null) return vs; @@ -2284,7 +2287,9 @@ static final class KeySet public K higher(K e) { return m.higherKey(e); } @Pure public Comparator comparator() { return m.comparator(); } + @SideEffectFree public K first() { return m.firstKey(); } + @SideEffectFree public K last() { return m.lastKey(); } // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") @@ -2298,6 +2303,7 @@ public K pollLast() { Map.Entry e = m.pollLastEntry(); return (e == null) ? null : e.getKey(); } + @SideEffectFree public Iterator iterator() { return (m instanceof ConcurrentSkipListMap) ? ((ConcurrentSkipListMap)m).new KeyIterator() @@ -2316,6 +2322,7 @@ public boolean equals(Object o) { return false; } } + @SideEffectFree public @PolyNull @PolySigned Object[] toArray(KeySet<@PolyNull @PolySigned K,V> this) { return toList(this).toArray(); } public @Nullable T[] toArray(@PolyNull T[] a) { return toList(this).toArray(a); } public Iterator descendingIterator() { @@ -2328,18 +2335,23 @@ public NavigableSet subSet(K fromElement, return new KeySet<>(m.subMap(fromElement, fromInclusive, toElement, toInclusive)); } + @SideEffectFree public NavigableSet headSet(K toElement, boolean inclusive) { return new KeySet<>(m.headMap(toElement, inclusive)); } + @SideEffectFree public NavigableSet tailSet(K fromElement, boolean inclusive) { return new KeySet<>(m.tailMap(fromElement, inclusive)); } + @SideEffectFree public NavigableSet subSet(K fromElement, K toElement) { return subSet(fromElement, true, toElement, false); } + @SideEffectFree public NavigableSet headSet(K toElement) { return headSet(toElement, false); } + @SideEffectFree public NavigableSet tailSet(K fromElement) { return tailSet(fromElement, true); } @@ -2347,6 +2359,7 @@ public NavigableSet descendingSet() { return new KeySet<>(m.descendingMap()); } + @SideEffectFree public Spliterator spliterator() { return (m instanceof ConcurrentSkipListMap) ? ((ConcurrentSkipListMap)m).keySpliterator() @@ -2359,6 +2372,7 @@ static final class Values extends AbstractCollection { Values(ConcurrentNavigableMap map) { m = map; } + @SideEffectFree public Iterator iterator() { return (m instanceof ConcurrentSkipListMap) ? ((ConcurrentSkipListMap)m).new ValueIterator() @@ -2375,9 +2389,11 @@ public Iterator iterator() { // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") public void clear() { m.clear(); } + @SideEffectFree public Object[] toArray() { return toList(this).toArray(); } public @Nullable T[] toArray(@PolyNull T[] a) { return toList(this).toArray(a); } + @SideEffectFree public Spliterator spliterator() { return (m instanceof ConcurrentSkipListMap) ? ((ConcurrentSkipListMap)m).valueSpliterator() @@ -2409,6 +2425,7 @@ static final class EntrySet extends AbstractSet> { EntrySet(ConcurrentNavigableMap map) { m = map; } + @SideEffectFree public Iterator> iterator() { return (m instanceof ConcurrentSkipListMap) ? ((ConcurrentSkipListMap)m).new EntryIterator() @@ -2460,9 +2477,11 @@ public boolean equals(Object o) { return false; } } + @SideEffectFree public Object[] toArray() { return toList(this).toArray(); } public @Nullable T[] toArray(@PolyNull T[] a) { return toList(this).toArray(a); } + @SideEffectFree public Spliterator> spliterator() { return (m instanceof ConcurrentSkipListMap) ? ((ConcurrentSkipListMap)m).entrySpliterator() @@ -3005,6 +3024,7 @@ public Map.Entry pollLastEntry() { /* ---------------- Submap Views -------------- */ + @SideEffectFree public NavigableSet keySet() { KeySet ks; if ((ks = keySetView) != null) return ks; @@ -3018,6 +3038,7 @@ public NavigableSet navigableKeySet() { return keySetView = new KeySet<>(this); } + @SideEffectFree public Collection values() { Values vs; if ((vs = valuesView) != null) return vs; diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java index a5682c38b6b90..b9bd22662ded4 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java @@ -431,6 +431,7 @@ public E higher(E e) { /** * @throws java.util.NoSuchElementException {@inheritDoc} */ + @SideEffectFree public E first(@NonEmpty ConcurrentSkipListSet this) { return m.firstKey(); } @@ -438,6 +439,7 @@ public E first(@NonEmpty ConcurrentSkipListSet this) { /** * @throws java.util.NoSuchElementException {@inheritDoc} */ + @SideEffectFree public E last(@NonEmpty ConcurrentSkipListSet this) { return m.lastKey(); } @@ -486,6 +488,7 @@ public void addLast(E e) { * @throws NullPointerException if {@code toElement} is null * @throws IllegalArgumentException {@inheritDoc} */ + @SideEffectFree public @PolyGrowShrink @PolyNonEmpty NavigableSet headSet(@PolyGrowShrink @PolyNonEmpty ConcurrentSkipListSet this, E toElement, boolean inclusive) { return new ConcurrentSkipListSet(m.headMap(toElement, inclusive)); } @@ -495,6 +498,7 @@ public void addLast(E e) { * @throws NullPointerException if {@code fromElement} is null * @throws IllegalArgumentException {@inheritDoc} */ + @SideEffectFree public @PolyGrowShrink @PolyNonEmpty NavigableSet tailSet(@PolyGrowShrink @PolyNonEmpty ConcurrentSkipListSet this, E fromElement, boolean inclusive) { return new ConcurrentSkipListSet(m.tailMap(fromElement, inclusive)); } @@ -505,6 +509,7 @@ public void addLast(E e) { * {@code toElement} is null * @throws IllegalArgumentException {@inheritDoc} */ + @SideEffectFree public @PolyGrowShrink @PolyNonEmpty NavigableSet subSet(@PolyGrowShrink @PolyNonEmpty ConcurrentSkipListSet this, E fromElement, E toElement) { return subSet(fromElement, true, toElement, false); } @@ -514,6 +519,7 @@ public void addLast(E e) { * @throws NullPointerException if {@code toElement} is null * @throws IllegalArgumentException {@inheritDoc} */ + @SideEffectFree public @PolyGrowShrink @PolyNonEmpty NavigableSet headSet(@PolyGrowShrink @PolyNonEmpty ConcurrentSkipListSet this, E toElement) { return headSet(toElement, false); } @@ -523,6 +529,7 @@ public void addLast(E e) { * @throws NullPointerException if {@code fromElement} is null * @throws IllegalArgumentException {@inheritDoc} */ + @SideEffectFree public @PolyGrowShrink @PolyNonEmpty NavigableSet tailSet(@PolyGrowShrink @PolyNonEmpty ConcurrentSkipListSet this, E fromElement) { return tailSet(fromElement, true); } diff --git a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java index 84cbe8c7ee89d..00dc6b4eecd45 100644 --- a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java +++ b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java @@ -325,6 +325,7 @@ public int lastIndexOf(E e, int index) { * * @return a clone of this list */ + @SideEffectFree public Object clone() { try { @SuppressWarnings("unchecked") @@ -354,6 +355,7 @@ public Object clone() { * * @return an array containing all the elements in this list */ + @SideEffectFree public @PolyNull @PolySigned Object[] toArray(CopyOnWriteArrayList<@PolyNull @PolySigned E> this) { return getArray().clone(); } @@ -1110,6 +1112,7 @@ private void readObject(java.io.ObjectInputStream s) * * @return a string representation of this list */ + @SideEffectFree public String toString() { return Arrays.toString(getArray()); } @@ -1177,6 +1180,7 @@ public int hashCode() { * * @return an iterator over the elements in this list in proper sequence */ + @SideEffectFree public @PolyGrowShrink @PolyNonEmpty Iterator iterator(@PolyGrowShrink @PolyNonEmpty CopyOnWriteArrayList this) { return new COWIterator(getArray(), 0); } @@ -1226,6 +1230,7 @@ public int hashCode() { * @return a {@code Spliterator} over the elements in this list * @since 1.8 */ + @SideEffectFree public Spliterator spliterator() { return Spliterators.spliterator (getArray(), Spliterator.IMMUTABLE | Spliterator.ORDERED); @@ -1339,6 +1344,7 @@ public void forEachRemaining(Consumer action) { * @return a view of the specified range within this list * @throws IndexOutOfBoundsException {@inheritDoc} */ + @SideEffectFree public @PolyGrowShrink List subList(@PolyGrowShrink CopyOnWriteArrayList this, int fromIndex, int toIndex) { synchronized (lock) { Object[] es = getArray(); @@ -1391,6 +1397,7 @@ private void rangeCheckForAdd(int index) { throw new IndexOutOfBoundsException(outOfBounds(index, size)); } + @SideEffectFree public Object[] toArray() { final Object[] es; final int offset; @@ -1480,6 +1487,7 @@ public boolean isEmpty() { return size() == 0; } + @SideEffectFree public String toString() { return Arrays.toString(toArray()); } @@ -1692,6 +1700,7 @@ public boolean remove(@Nullable @UnknownSignedness Object o) { } } + @SideEffectFree public Iterator iterator() { return listIterator(0); } @@ -1709,6 +1718,7 @@ public ListIterator listIterator(int index) { } } + @SideEffectFree public List subList(int fromIndex, int toIndex) { synchronized (lock) { checkForComodification(); @@ -1780,6 +1790,7 @@ private boolean bulkRemove(Predicate filter) { } } + @SideEffectFree public Spliterator spliterator() { synchronized (lock) { return Spliterators.spliterator( @@ -1975,10 +1986,12 @@ public void forEach(Consumer action) { action.accept(e); } + @SideEffectFree public Iterator iterator() { return new DescendingIterator(); } + @SideEffectFree public Spliterator spliterator() { // TODO can probably improve this return Spliterators.spliteratorUnknownSize(new DescendingIterator(), 0); @@ -2093,6 +2106,7 @@ public Stream stream() { return StreamSupport.stream(spliterator(), false); } + @SideEffectFree public Object[] toArray() { return ArraysSupport.reverse(base.toArray()); } @@ -2108,6 +2122,7 @@ public T[] toArray(IntFunction generator) { } // copied from AbstractCollection + @SideEffectFree public String toString() { Iterator it = iterator(); if (! it.hasNext()) @@ -2270,6 +2285,7 @@ public E set(int index, E element) { } } + @SideEffectFree public List subList(int fromIndex, int toIndex) { synchronized (lock) { int size = base.size(); diff --git a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java index 3e1358d2f5b70..487944eed2ea7 100644 --- a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java +++ b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArraySet.java @@ -194,6 +194,7 @@ public boolean contains(@GuardSatisfied @Nullable @UnknownSignedness Object o) { * * @return an array containing all the elements in this set */ + @SideEffectFree public @PolyNull @PolySigned Object[] toArray(CopyOnWriteArraySet<@PolyNull @PolySigned E> this) { return al.toArray(); } @@ -420,6 +421,7 @@ public boolean retainAll(Collection iterator(@PolyGrowShrink @PolyNonEmpty CopyOnWriteArraySet this) { return al.iterator(); } @@ -479,6 +481,7 @@ public void forEach(Consumer action) { * @return a {@code Spliterator} over the elements in this set * @since 1.8 */ + @SideEffectFree public Spliterator spliterator() { return Spliterators.spliterator (al.getArray(), Spliterator.IMMUTABLE | Spliterator.DISTINCT); diff --git a/src/java.base/share/classes/java/util/concurrent/DelayQueue.java b/src/java.base/share/classes/java/util/concurrent/DelayQueue.java index 3549287b5b416..4463a14ba3b2d 100644 --- a/src/java.base/share/classes/java/util/concurrent/DelayQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/DelayQueue.java @@ -528,7 +528,6 @@ public int remainingCapacity() { * this queue * @throws NullPointerException if the specified array is null */ - @SideEffectFree public @Nullable T[] toArray(@PolyNull T[] a) { final ReentrantLock lock = this.lock; lock.lock(); diff --git a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java index d8457b2fa0a9d..3faeeeb3003d7 100644 --- a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java +++ b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java @@ -992,6 +992,7 @@ public boolean addAll(Collection c) { * @return an array containing all of the elements in this deque */ @SuppressWarnings("unchecked") + @SideEffectFree public @PolyNull @PolySigned Object[] toArray(LinkedBlockingDeque<@PolyNull @PolySigned E> this) { final ReentrantLock lock = this.lock; lock.lock(); @@ -1061,6 +1062,7 @@ public boolean addAll(Collection c) { } } + @SideEffectFree public String toString() { return Helpers.collectionToString(this); } @@ -1111,6 +1113,7 @@ Node succ(Node p) { * * @return an iterator over the elements in this deque in proper sequence */ + @SideEffectFree public @PolyGrowShrink @PolyNonEmpty Iterator iterator(@PolyGrowShrink @PolyNonEmpty LinkedBlockingDeque this) { return new Itr(); } @@ -1381,6 +1384,7 @@ public int characteristics() { * @return a {@code Spliterator} over the elements in this deque * @since 1.8 */ + @SideEffectFree public Spliterator spliterator() { return new LBDSpliterator(); } diff --git a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java index 2fb3859c80b9c..92194a3171d7e 100644 --- a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java @@ -621,6 +621,7 @@ public boolean contains(@GuardSatisfied @Nullable @UnknownSignedness Object o) { * * @return an array containing all of the elements in this queue */ + @SideEffectFree public @PolyNull @PolySigned Object[] toArray(LinkedBlockingQueue<@PolyNull @PolySigned E> this) { fullyLock(); try { @@ -690,6 +691,7 @@ public boolean contains(@GuardSatisfied @Nullable @UnknownSignedness Object o) { } } + @SideEffectFree public String toString() { return Helpers.collectionToString(this); } @@ -796,6 +798,7 @@ Node succ(Node p) { * * @return an iterator over the elements in this queue in proper sequence */ + @SideEffectFree public @PolyGrowShrink @PolyNonEmpty Iterator iterator(@PolyGrowShrink @PolyNonEmpty LinkedBlockingQueue this) { return new Itr(); } @@ -1016,6 +1019,7 @@ public int characteristics() { * @return a {@code Spliterator} over the elements in this queue * @since 1.8 */ + @SideEffectFree public Spliterator spliterator() { return new LBQSpliterator(); } diff --git a/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java b/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java index f885f950bc28f..0dfa57a8ae2ef 100644 --- a/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java @@ -752,6 +752,7 @@ private int countOfMode(boolean data) { } } + @SideEffectFree public String toString() { String[] a = null; restartFromHead: for (;;) { @@ -827,6 +828,7 @@ else if (a != null && size <= a.length) { * * @return an array containing all of the elements in this queue */ + @SideEffectFree public @PolyNull @PolySigned Object[] toArray(LinkedTransferQueue<@PolyNull @PolySigned E> this) { return toArrayInternal(null); } @@ -1100,6 +1102,7 @@ public int characteristics() { * @return a {@code Spliterator} over the elements in this queue * @since 1.8 */ + @SideEffectFree public Spliterator spliterator() { return new LTQSpliterator(); } @@ -1385,6 +1388,7 @@ public int drainTo(@GuardSatisfied @CanShrink LinkedTransferQueue this, Colle * * @return an iterator over the elements in this queue in proper sequence */ + @SideEffectFree public @PolyGrowShrink @PolyNonEmpty Iterator iterator(@PolyGrowShrink @PolyNonEmpty LinkedTransferQueue this) { return new Itr(); } diff --git a/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java index 2deb1a5df2090..446fade1c1920 100644 --- a/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java @@ -736,6 +736,7 @@ public boolean contains(@GuardSatisfied @Nullable @UnknownSignedness Object o) { } } + @SideEffectFree public String toString() { return Helpers.collectionToString(this); } @@ -812,6 +813,7 @@ public void clear(@GuardSatisfied @CanShrink PriorityBlockingQueue this) { * * @return an array containing all of the elements in this queue */ + @SideEffectFree public @PolyNull @PolySigned Object[] toArray(PriorityBlockingQueue<@PolyNull @PolySigned E> this) { final ReentrantLock lock = this.lock; lock.lock(); @@ -884,6 +886,7 @@ public void clear(@GuardSatisfied @CanShrink PriorityBlockingQueue this) { * * @return an iterator over the elements in this queue */ + @SideEffectFree public @PolyGrowShrink @PolyNonEmpty Iterator iterator(@PolyGrowShrink @PolyNonEmpty PriorityBlockingQueue this) { return new Itr(toArray()); } @@ -1053,6 +1056,7 @@ public int characteristics() { * @return a {@code Spliterator} over the elements in this queue * @since 1.8 */ + @SideEffectFree public Spliterator spliterator() { return new PBQSpliterator(); } diff --git a/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java b/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java index 5c402e9431221..45ee3254e1d17 100644 --- a/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/SynchronousQueue.java @@ -1103,7 +1103,6 @@ public Spliterator spliterator() { * @return the specified array * @throws NullPointerException if the specified array is null */ - @SideEffectFree public @Nullable T[] toArray(@PolyNull T[] a) { if (a.length > 0) a[0] = null; @@ -1114,6 +1113,7 @@ public Spliterator spliterator() { * Always returns {@code "[]"}. * @return {@code "[]"} */ + @SideEffectFree public String toString() { return "[]"; } diff --git a/src/java.base/share/classes/java/util/jar/Attributes.java b/src/java.base/share/classes/java/util/jar/Attributes.java index 58dba2a49cf49..6821c0c013f26 100644 --- a/src/java.base/share/classes/java/util/jar/Attributes.java +++ b/src/java.base/share/classes/java/util/jar/Attributes.java @@ -287,6 +287,7 @@ public boolean isEmpty() { /** * Returns a Set view of the attribute names (keys) contained in this Map. */ + @SideEffectFree public Set keySet() { return map.keySet(); } @@ -294,6 +295,7 @@ public Set keySet() { /** * Returns a Collection view of the attribute values contained in this Map. */ + @SideEffectFree public Collection values() { return map.values(); } @@ -339,6 +341,7 @@ public int hashCode() { * the Attributes returned can be safely modified without affecting * the original. */ + @SideEffectFree public Object clone() { return new Attributes(this); } @@ -501,6 +504,7 @@ public static class Name { */ private static @Stable Map KNOWN_NAMES; + @SideEffectFree static final Name of(String name) { Name n = KNOWN_NAMES.get(name); if (n != null) { @@ -573,6 +577,7 @@ public int hashCode() { /** * Returns the attribute name as a String. */ + @SideEffectFree public String toString() { return name; } diff --git a/src/java.base/share/classes/java/util/stream/SpinedBuffer.java b/src/java.base/share/classes/java/util/stream/SpinedBuffer.java index 99be057fce6a4..56854abf6aad7 100644 --- a/src/java.base/share/classes/java/util/stream/SpinedBuffer.java +++ b/src/java.base/share/classes/java/util/stream/SpinedBuffer.java @@ -236,6 +236,7 @@ public void clear() { } @Override + @SideEffectFree public Iterator iterator() { return Spliterators.iterator(spliterator()); } @@ -266,6 +267,7 @@ public void accept(E e) { } @Override + @SideEffectFree public String toString() { List list = new ArrayList<>(); forEach(list::add); @@ -278,6 +280,7 @@ public String toString() { /** * Return a {@link Spliterator} describing the contents of the buffer. */ + @SideEffectFree public Spliterator spliterator() { class Splitr implements Spliterator { // The current spine index @@ -464,6 +467,7 @@ abstract static class OfPrimitive } @Override + @SideEffectFree public abstract Iterator iterator(); @Override @@ -784,10 +788,12 @@ public int get(long index) { } @Override + @SideEffectFree public PrimitiveIterator.OfInt iterator() { return Spliterators.iterator(spliterator()); } + @SideEffectFree public Spliterator.OfInt spliterator() { @SuppressWarnings("overloads") class Splitr extends BaseSpliterator @@ -819,6 +825,7 @@ Spliterator.OfInt arraySpliterator(int[] array, int offset, int len) { } @Override + @SideEffectFree public String toString() { int[] array = asPrimitiveArray(); if (array.length < 200) { @@ -900,11 +907,12 @@ public long get(long index) { } @Override + @SideEffectFree public PrimitiveIterator.OfLong iterator() { return Spliterators.iterator(spliterator()); } - + @SideEffectFree public Spliterator.OfLong spliterator() { @SuppressWarnings("overloads") class Splitr extends BaseSpliterator @@ -936,6 +944,7 @@ Spliterator.OfLong arraySpliterator(long[] array, int offset, int len) { } @Override + @SideEffectFree public String toString() { long[] array = asPrimitiveArray(); if (array.length < 200) { @@ -1018,10 +1027,12 @@ public double get(long index) { } @Override + @SideEffectFree public PrimitiveIterator.OfDouble iterator() { return Spliterators.iterator(spliterator()); } + @SideEffectFree public Spliterator.OfDouble spliterator() { @SuppressWarnings("overloads") class Splitr extends BaseSpliterator @@ -1053,6 +1064,7 @@ Spliterator.OfDouble arraySpliterator(double[] array, int offset, int len) { } @Override + @SideEffectFree public String toString() { double[] array = asPrimitiveArray(); if (array.length < 200) { diff --git a/src/java.base/share/classes/java/util/stream/Stream.java b/src/java.base/share/classes/java/util/stream/Stream.java index 7193a7d7e86e5..4e592f283465f 100644 --- a/src/java.base/share/classes/java/util/stream/Stream.java +++ b/src/java.base/share/classes/java/util/stream/Stream.java @@ -922,7 +922,6 @@ default Stream dropWhile(Predicate predicate) { * stream is not assignable to the {@linkplain Class#getComponentType * runtime component type} of the generated array */ - @SideEffectFree A[] toArray(IntFunction generator); /** From 27f4b4ab037e617a035d30e74ca249589c74a818 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 19 May 2026 18:54:16 -0700 Subject: [PATCH 13/15] Add imports --- src/java.base/share/classes/java/util/EnumSet.java | 1 + src/java.base/share/classes/java/util/LinkedHashSet.java | 1 + .../share/classes/java/util/ReverseOrderDequeView.java | 2 ++ .../share/classes/java/util/ReverseOrderListView.java | 6 ++++-- .../share/classes/java/util/ReverseOrderSortedMapView.java | 1 + .../share/classes/java/util/ReverseOrderSortedSetView.java | 2 ++ .../classes/java/util/concurrent/ArrayBlockingQueue.java | 1 + .../classes/java/util/concurrent/LinkedBlockingDeque.java | 1 + .../classes/java/util/concurrent/LinkedBlockingQueue.java | 1 + .../classes/java/util/concurrent/LinkedTransferQueue.java | 1 + .../classes/java/util/concurrent/PriorityBlockingQueue.java | 1 + .../share/classes/java/util/stream/SpinedBuffer.java | 2 ++ 12 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/java.base/share/classes/java/util/EnumSet.java b/src/java.base/share/classes/java/util/EnumSet.java index 2f092fce95c60..c85dc5fe67087 100644 --- a/src/java.base/share/classes/java/util/EnumSet.java +++ b/src/java.base/share/classes/java/util/EnumSet.java @@ -26,6 +26,7 @@ package java.util; import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; diff --git a/src/java.base/share/classes/java/util/LinkedHashSet.java b/src/java.base/share/classes/java/util/LinkedHashSet.java index f1b81b447f5c6..feb93687f0212 100644 --- a/src/java.base/share/classes/java/util/LinkedHashSet.java +++ b/src/java.base/share/classes/java/util/LinkedHashSet.java @@ -27,6 +27,7 @@ import org.checkerframework.dataflow.qual.Deterministic; import org.checkerframework.dataflow.qual.Pure; +import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; diff --git a/src/java.base/share/classes/java/util/ReverseOrderDequeView.java b/src/java.base/share/classes/java/util/ReverseOrderDequeView.java index 86a075afedda1..19702f274b3db 100644 --- a/src/java.base/share/classes/java/util/ReverseOrderDequeView.java +++ b/src/java.base/share/classes/java/util/ReverseOrderDequeView.java @@ -25,6 +25,8 @@ package java.util; +import org.checkerframework.dataflow.qual.SideEffectFree; + import java.util.function.Consumer; import java.util.function.IntFunction; import java.util.stream.Stream; diff --git a/src/java.base/share/classes/java/util/ReverseOrderListView.java b/src/java.base/share/classes/java/util/ReverseOrderListView.java index c59934e3a7a3c..f6e834f9c79ea 100644 --- a/src/java.base/share/classes/java/util/ReverseOrderListView.java +++ b/src/java.base/share/classes/java/util/ReverseOrderListView.java @@ -25,8 +25,11 @@ package java.util; -import java.util.Objects; +import org.checkerframework.dataflow.qual.Pure; +import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; + +import java.util.Objects; import java.util.function.Consumer; import java.util.function.IntFunction; import java.util.function.Predicate; @@ -34,7 +37,6 @@ import java.util.stream.Stream; import java.util.stream.StreamSupport; import jdk.internal.util.ArraysSupport; -import org.checkerframework.dataflow.qual.Pure; /** * Provides a reverse-ordered view of a List. Not serializable. diff --git a/src/java.base/share/classes/java/util/ReverseOrderSortedMapView.java b/src/java.base/share/classes/java/util/ReverseOrderSortedMapView.java index 13036771c0061..ffef3f2a837f9 100644 --- a/src/java.base/share/classes/java/util/ReverseOrderSortedMapView.java +++ b/src/java.base/share/classes/java/util/ReverseOrderSortedMapView.java @@ -26,6 +26,7 @@ package java.util; import org.checkerframework.dataflow.qual.Pure; +import org.checkerframework.dataflow.qual.SideEffectFree; /** * Provides a reversed-ordered view of a SortedMap. Not serializable. diff --git a/src/java.base/share/classes/java/util/ReverseOrderSortedSetView.java b/src/java.base/share/classes/java/util/ReverseOrderSortedSetView.java index 63caa9d68f3aa..be4109cac72e8 100644 --- a/src/java.base/share/classes/java/util/ReverseOrderSortedSetView.java +++ b/src/java.base/share/classes/java/util/ReverseOrderSortedSetView.java @@ -25,6 +25,8 @@ package java.util; +import org.checkerframework.dataflow.qual.SideEffectFree; + import java.util.function.Consumer; import java.util.function.IntFunction; import java.util.stream.Stream; diff --git a/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java index ea16b957c8771..3fe027bafbeac 100644 --- a/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/ArrayBlockingQueue.java @@ -48,6 +48,7 @@ import org.checkerframework.checker.signedness.qual.PolySigned; 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.DoesNotUnrefineReceiver; diff --git a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java index 3faeeeb3003d7..f928042e2d12e 100644 --- a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java +++ b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java @@ -48,6 +48,7 @@ import org.checkerframework.checker.signedness.qual.PolySigned; 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.DoesNotUnrefineReceiver; diff --git a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java index 92194a3171d7e..5faa7a4ad1e82 100644 --- a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java @@ -47,6 +47,7 @@ import org.checkerframework.checker.signedness.qual.PolySigned; 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.DoesNotUnrefineReceiver; diff --git a/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java b/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java index 0dfa57a8ae2ef..ce7772bf79352 100644 --- a/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java @@ -48,6 +48,7 @@ import org.checkerframework.checker.signedness.qual.PolySigned; 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.DoesNotUnrefineReceiver; diff --git a/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java index 446fade1c1920..fe1a1cef9473f 100644 --- a/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java @@ -48,6 +48,7 @@ import org.checkerframework.checker.signedness.qual.PolySigned; 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.DoesNotUnrefineReceiver; diff --git a/src/java.base/share/classes/java/util/stream/SpinedBuffer.java b/src/java.base/share/classes/java/util/stream/SpinedBuffer.java index 56854abf6aad7..5ea5f3a3246cf 100644 --- a/src/java.base/share/classes/java/util/stream/SpinedBuffer.java +++ b/src/java.base/share/classes/java/util/stream/SpinedBuffer.java @@ -24,6 +24,8 @@ */ package java.util.stream; +import org.checkerframework.dataflow.qual.SideEffectFree; + import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; From 243e3f66776bb02bb64be85527b9b2a429fdb64d Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Wed, 20 May 2026 07:04:00 -0700 Subject: [PATCH 14/15] Run `build_jdk21u` only for the `jdk` repository, not `jdk21u` --- .github/workflows/ci.yml | 1 + .github/workflows/ci.yml.m4 | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 05a82df71c1d5..57d44cb35f572 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,6 +51,7 @@ jobs: run: make jdk build_jdk21u: + if: endsWith(github.repository, '/jdk') needs: - check_generated_ci runs-on: ubuntu-latest diff --git a/.github/workflows/ci.yml.m4 b/.github/workflows/ci.yml.m4 index 4b09b9583f000..50210af2491f2 100644 --- a/.github/workflows/ci.yml.m4 +++ b/.github/workflows/ci.yml.m4 @@ -55,6 +55,7 @@ jobs: run: make jdk build_jdk21u: + if: endsWith(github.repository, '/jdk') needs: - check_generated_ci runs-on: ubuntu-latest From 72f293849d452d68df942c4cde7a06b67ec1cce9 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Wed, 20 May 2026 08:43:43 -0700 Subject: [PATCH 15/15] Address CodeRabbit feedback --- src/java.base/share/classes/java/util/Collections.java | 3 +-- src/java.base/share/classes/java/util/HashSet.java | 2 -- src/java.base/share/classes/java/util/IdentityHashMap.java | 1 - .../share/classes/java/util/ImmutableCollections.java | 1 - src/java.base/share/classes/java/util/LinkedHashMap.java | 6 +++++- src/java.base/share/classes/java/util/LinkedHashSet.java | 2 -- src/java.base/share/classes/java/util/RegularEnumSet.java | 1 - .../share/classes/java/util/ReverseOrderListView.java | 4 ++++ src/java.base/share/classes/java/util/SortedSet.java | 2 -- src/java.base/share/classes/java/util/TreeSet.java | 5 +---- .../classes/java/util/concurrent/ConcurrentHashMap.java | 4 ---- 11 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/java.base/share/classes/java/util/Collections.java b/src/java.base/share/classes/java/util/Collections.java index 8f2111262b066..18a66f0ef8e61 100644 --- a/src/java.base/share/classes/java/util/Collections.java +++ b/src/java.base/share/classes/java/util/Collections.java @@ -1541,8 +1541,7 @@ public EmptyNavigableSet() { @DoesNotUnrefineReceiver("modifiability") public NavigableSet descendingSet() { return new UnmodifiableNavigableSet<>(ns.descendingSet()); } - // @SideEffectsOnly("this") - @DoesNotUnrefineReceiver("modifiability") + @SideEffectFree public Iterator descendingIterator() { return descendingSet().iterator(); } diff --git a/src/java.base/share/classes/java/util/HashSet.java b/src/java.base/share/classes/java/util/HashSet.java index cdf44f001e5ee..756747e1afd26 100644 --- a/src/java.base/share/classes/java/util/HashSet.java +++ b/src/java.base/share/classes/java/util/HashSet.java @@ -399,8 +399,6 @@ private void readObject(java.io.ObjectInputStream s) * @return a {@code Spliterator} over the elements in this set * @since 1.8 */ - // @SideEffectsOnly("this") - @DoesNotUnrefineReceiver("modifiability") @SideEffectFree public Spliterator spliterator() { return new HashMap.KeySpliterator<>(map, 0, -1, 0, 0); diff --git a/src/java.base/share/classes/java/util/IdentityHashMap.java b/src/java.base/share/classes/java/util/IdentityHashMap.java index 94be828c3902f..12b276b27f0d7 100644 --- a/src/java.base/share/classes/java/util/IdentityHashMap.java +++ b/src/java.base/share/classes/java/util/IdentityHashMap.java @@ -792,7 +792,6 @@ public boolean hasNext() { } // @SideEffectsOnly("this") - @Pure protected int nextIndex(@NonEmpty IdentityHashMapIterator this) { if (modCount != expectedModCount) throw new ConcurrentModificationException(); diff --git a/src/java.base/share/classes/java/util/ImmutableCollections.java b/src/java.base/share/classes/java/util/ImmutableCollections.java index f4310924b44e0..102db2642c3d0 100644 --- a/src/java.base/share/classes/java/util/ImmutableCollections.java +++ b/src/java.base/share/classes/java/util/ImmutableCollections.java @@ -1358,7 +1358,6 @@ public boolean hasNext() { // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") - @Pure private int nextIndex() { int idx = this.idx; if (REVERSE) { diff --git a/src/java.base/share/classes/java/util/LinkedHashMap.java b/src/java.base/share/classes/java/util/LinkedHashMap.java index aaed1b544154c..c7630ed325355 100644 --- a/src/java.base/share/classes/java/util/LinkedHashMap.java +++ b/src/java.base/share/classes/java/util/LinkedHashMap.java @@ -38,6 +38,7 @@ import org.checkerframework.dataflow.qual.SideEffectFree; // import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.framework.qual.CFComment; import org.checkerframework.framework.qual.DoesNotUnrefineReceiver; import java.util.function.Consumer; @@ -552,6 +553,7 @@ public boolean containsValue(@GuardSatisfied LinkedHashMap this, @GuardSat * The {@link #containsKey containsKey} operation may be used to * distinguish these two cases. */ + @CFComment("`get()` is not strictly pure: if `accessOrder==true`, it changes the access order") @Pure public @Nullable V get(@GuardSatisfied LinkedHashMap this, @UnknownSignedness @GuardSatisfied @Nullable Object key) { Node e; @@ -565,6 +567,7 @@ public boolean containsValue(@GuardSatisfied LinkedHashMap this, @GuardSat /** * {@inheritDoc} */ + @CFComment("`getOrDefault()` is not strictly pure: if `accessOrder==true`, it changes the access order") @Pure public V getOrDefault(@Nullable Object key, V defaultValue) { Node e; @@ -1128,7 +1131,6 @@ final class LinkedKeyIterator extends LinkedHashIterator LinkedKeyIterator(boolean reversed) { super(reversed); } // @SideEffectsOnly("this") @DoesNotUnrefineReceiver("modifiability") - @Pure public final K next(@NonEmpty LinkedKeyIterator this) { return nextNode().getKey(); } } @@ -1227,6 +1229,7 @@ public boolean containsValue(Object value) { return base.containsValue(value); } + @CFComment("`get()` is not strictly pure: if `accessOrder==true`, it changes the access order") @Pure public V get(Object key) { return base.get(key); @@ -1271,6 +1274,7 @@ public Set> entrySet() { return base.sequencedEntrySet().reversed(); } + @CFComment("`getOrDefault()` is not strictly pure: if `accessOrder==true`, it changes the access order") @Pure public V getOrDefault(Object key, V defaultValue) { return base.getOrDefault(key, defaultValue); diff --git a/src/java.base/share/classes/java/util/LinkedHashSet.java b/src/java.base/share/classes/java/util/LinkedHashSet.java index feb93687f0212..755512641f681 100644 --- a/src/java.base/share/classes/java/util/LinkedHashSet.java +++ b/src/java.base/share/classes/java/util/LinkedHashSet.java @@ -211,8 +211,6 @@ public LinkedHashSet(Collection c) { * @since 1.8 */ @Override - // @SideEffectsOnly("this") - @DoesNotUnrefineReceiver("modifiability") @SideEffectFree public Spliterator spliterator() { return Spliterators.spliterator(this, Spliterator.DISTINCT | Spliterator.ORDERED); diff --git a/src/java.base/share/classes/java/util/RegularEnumSet.java b/src/java.base/share/classes/java/util/RegularEnumSet.java index 353c772665b18..af48606a713c8 100644 --- a/src/java.base/share/classes/java/util/RegularEnumSet.java +++ b/src/java.base/share/classes/java/util/RegularEnumSet.java @@ -96,7 +96,6 @@ void complement() { * * @return an iterator over the elements contained in this set */ - @DoesNotUnrefineReceiver("modifiability") @SideEffectFree public @PolyGrowShrink @PolyNonEmpty Iterator iterator(@PolyGrowShrink @PolyNonEmpty RegularEnumSet this) { return new EnumSetIterator<>(); diff --git a/src/java.base/share/classes/java/util/ReverseOrderListView.java b/src/java.base/share/classes/java/util/ReverseOrderListView.java index f6e834f9c79ea..1ec525c8d1a2f 100644 --- a/src/java.base/share/classes/java/util/ReverseOrderListView.java +++ b/src/java.base/share/classes/java/util/ReverseOrderListView.java @@ -87,7 +87,11 @@ class DescendingIterator implements Iterator { final ListIterator it = base.listIterator(base.size()); @Pure public boolean hasNext() { return it.hasPrevious(); } + // @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public E next() { return it.previous(); } + // @SideEffectsOnly("this") + @DoesNotUnrefineReceiver("modifiability") public void remove() { checkModifiable(); it.remove(); diff --git a/src/java.base/share/classes/java/util/SortedSet.java b/src/java.base/share/classes/java/util/SortedSet.java index 60691f4c2c634..e10b5935e9573 100644 --- a/src/java.base/share/classes/java/util/SortedSet.java +++ b/src/java.base/share/classes/java/util/SortedSet.java @@ -269,8 +269,6 @@ public interface SortedSet extends Set, SequencedSet { * @since 1.8 */ @Override - // @SideEffectsOnly("this") - @DoesNotUnrefineReceiver("modifiability") @SideEffectFree default Spliterator spliterator() { return new Spliterators.IteratorSpliterator( diff --git a/src/java.base/share/classes/java/util/TreeSet.java b/src/java.base/share/classes/java/util/TreeSet.java index a0450cf215b12..9f6529637419a 100644 --- a/src/java.base/share/classes/java/util/TreeSet.java +++ b/src/java.base/share/classes/java/util/TreeSet.java @@ -210,8 +210,7 @@ public TreeSet(@Nullable Comparator comparator) { * @return an iterator over the elements in this set in descending order * @since 1.6 */ - // @SideEffectsOnly("this") - @DoesNotUnrefineReceiver("modifiability") + @SideEffectFree public @PolyGrowShrink @PolyNonEmpty Iterator descendingIterator(@PolyGrowShrink @PolyNonEmpty TreeSet this) { return m.descendingKeySet().iterator(); } @@ -635,8 +634,6 @@ private void readObject(java.io.ObjectInputStream s) * @return a {@code Spliterator} over the elements in this set * @since 1.8 */ - // @SideEffectsOnly("this") - @DoesNotUnrefineReceiver("modifiability") @SideEffectFree public Spliterator spliterator() { return TreeMap.keySpliteratorFor(m); diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java index f9f090d33a2ba..7035b52234837 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java @@ -5383,7 +5383,6 @@ static final class SearchKeysTask super(p, b, i, f, t); this.searchFunction = searchFunction; this.result = result; } - @Pure public final U getRawResult() { return result.get(); } public final void compute() { final Function searchFunction; @@ -5428,7 +5427,6 @@ static final class SearchValuesTask super(p, b, i, f, t); this.searchFunction = searchFunction; this.result = result; } - @Pure public final U getRawResult() { return result.get(); } public final void compute() { final Function searchFunction; @@ -5473,7 +5471,6 @@ static final class SearchEntriesTask super(p, b, i, f, t); this.searchFunction = searchFunction; this.result = result; } - @Pure public final U getRawResult() { return result.get(); } public final void compute() { final Function, ? extends U> searchFunction; @@ -5518,7 +5515,6 @@ static final class SearchMappingsTask super(p, b, i, f, t); this.searchFunction = searchFunction; this.result = result; } - @Pure public final U getRawResult() { return result.get(); } public final void compute() { final BiFunction searchFunction;