Skip to content

Commit ba84219

Browse files
authored
Sound treatment of collection Object parameters
1 parent 773905e commit ba84219

32 files changed

+132
-128
lines changed

src/java.base/share/classes/java/lang/reflect/Field.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ public String toGenericString(@GuardSatisfied Field this) {
430430
@SideEffectFree
431431
@CallerSensitive
432432
@ForceInline // to ensure Reflection.getCallerClass optimization
433-
public @Nullable Object get(@GuardSatisfied Field this, @UnknownInitialization @GuardSatisfied @Nullable Object obj)
433+
public @Nullable Object get(@GuardSatisfied Field this, @UnknownInitialization @GuardSatisfied Object obj)
434434
throws IllegalArgumentException, IllegalAccessException
435435
{
436436
if (!override) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public boolean isEmpty(@GuardSatisfied AbstractCollection<E> this) {
116116
*/
117117
@Override
118118
@Pure
119-
public boolean contains(@GuardSatisfied AbstractCollection<E> this, @GuardSatisfied @Nullable Object o) {
119+
public boolean contains(@GuardSatisfied AbstractCollection<E> this, @GuardSatisfied Object o) {
120120
Iterator<E> it = iterator();
121121
if (o==null) {
122122
while (it.hasNext())
@@ -309,7 +309,7 @@ public boolean add(@GuardSatisfied AbstractCollection<E> this, E e) {
309309
* @throws NullPointerException {@inheritDoc}
310310
*/
311311
@Override
312-
public boolean remove(@GuardSatisfied AbstractCollection<E> this, @Nullable Object o) {
312+
public boolean remove(@GuardSatisfied AbstractCollection<E> this, Object o) {
313313
Iterator<E> it = iterator();
314314
if (o==null) {
315315
while (it.hasNext()) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public E remove(@GuardSatisfied AbstractList<E> this, @IndexFor({"this"}) int in
195195
* @throws NullPointerException {@inheritDoc}
196196
*/
197197
@Pure
198-
public @GTENegativeOne int indexOf(@GuardSatisfied AbstractList<E> this, @GuardSatisfied @Nullable Object o) {
198+
public @GTENegativeOne int indexOf(@GuardSatisfied AbstractList<E> this, @GuardSatisfied Object o) {
199199
ListIterator<E> it = listIterator();
200200
if (o==null) {
201201
while (it.hasNext())
@@ -222,7 +222,7 @@ public E remove(@GuardSatisfied AbstractList<E> this, @IndexFor({"this"}) int in
222222
* @throws NullPointerException {@inheritDoc}
223223
*/
224224
@Pure
225-
public @GTENegativeOne int lastIndexOf(@GuardSatisfied AbstractList<E> this, @GuardSatisfied @Nullable Object o) {
225+
public @GTENegativeOne int lastIndexOf(@GuardSatisfied AbstractList<E> this, @GuardSatisfied Object o) {
226226
ListIterator<E> it = listIterator(size());
227227
if (o==null) {
228228
while (it.hasPrevious())

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public boolean isEmpty(@GuardSatisfied AbstractMap<K, V> this) {
126126
* @throws NullPointerException {@inheritDoc}
127127
*/
128128
@Pure
129-
public boolean containsValue(@GuardSatisfied AbstractMap<K, V> this, @GuardSatisfied @Nullable Object value) {
129+
public boolean containsValue(@GuardSatisfied AbstractMap<K, V> this, @GuardSatisfied Object value) {
130130
Iterator<Entry<K,V>> i = entrySet().iterator();
131131
if (value==null) {
132132
while (i.hasNext()) {
@@ -160,7 +160,7 @@ public boolean containsValue(@GuardSatisfied AbstractMap<K, V> this, @GuardSatis
160160
*/
161161
@EnsuresKeyForIf(expression={"#1"}, result=true, map={"this"})
162162
@Pure
163-
public boolean containsKey(@GuardSatisfied AbstractMap<K, V> this, @GuardSatisfied @Nullable Object key) {
163+
public boolean containsKey(@GuardSatisfied AbstractMap<K, V> this, @GuardSatisfied Object key) {
164164
Iterator<Map.Entry<K,V>> i = entrySet().iterator();
165165
if (key==null) {
166166
while (i.hasNext()) {
@@ -193,7 +193,7 @@ public boolean containsKey(@GuardSatisfied AbstractMap<K, V> this, @GuardSatisfi
193193
* @throws NullPointerException {@inheritDoc}
194194
*/
195195
@Pure
196-
public @Nullable V get(@GuardSatisfied AbstractMap<K, V> this, @GuardSatisfied @Nullable Object key) {
196+
public @Nullable V get(@GuardSatisfied AbstractMap<K, V> this, @GuardSatisfied Object key) {
197197
Iterator<Entry<K,V>> i = entrySet().iterator();
198198
if (key==null) {
199199
while (i.hasNext()) {
@@ -254,7 +254,7 @@ public boolean containsKey(@GuardSatisfied AbstractMap<K, V> this, @GuardSatisfi
254254
* @throws ClassCastException {@inheritDoc}
255255
* @throws NullPointerException {@inheritDoc}
256256
*/
257-
public @Nullable V remove(@GuardSatisfied AbstractMap<K, V> this, @Nullable Object key) {
257+
public @Nullable V remove(@GuardSatisfied AbstractMap<K, V> this, Object key) {
258258
Iterator<Entry<K,V>> i = entrySet().iterator();
259259
Entry<K,V> correctEntry = null;
260260
if (key==null) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ public E getLast(@GuardSatisfied ArrayDeque<E> this) {
447447
* @param o element to be removed from this deque, if present
448448
* @return {@code true} if the deque contained the specified element
449449
*/
450-
public boolean removeFirstOccurrence(@GuardSatisfied ArrayDeque<E> this, Object o) {
450+
public boolean removeFirstOccurrence(@GuardSatisfied ArrayDeque<E> this, @Nullable Object o) {
451451
if (o != null) {
452452
final Object[] es = elements;
453453
for (int i = head, end = tail, to = (i <= end) ? end : es.length;
@@ -475,7 +475,7 @@ public boolean removeFirstOccurrence(@GuardSatisfied ArrayDeque<E> this, Object
475475
* @param o element to be removed from this deque, if present
476476
* @return {@code true} if the deque contained the specified element
477477
*/
478-
public boolean removeLastOccurrence(@GuardSatisfied ArrayDeque<E> this, Object o) {
478+
public boolean removeLastOccurrence(@GuardSatisfied ArrayDeque<E> this, @Nullable Object o) {
479479
if (o != null) {
480480
final Object[] es = elements;
481481
for (int i = tail, end = head, to = (i >= end) ? end : 0;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ public boolean contains(@GuardSatisfied ArrayList<E> this, @GuardSatisfied @Null
335335
return indexOfRange(o, 0, size);
336336
}
337337

338-
int indexOfRange(Object o, int start, int end) {
338+
int indexOfRange(@Nullable Object o, int start, int end) {
339339
Object[] es = elementData;
340340
if (o == null) {
341341
for (int i = start; i < end; i++) {
@@ -365,7 +365,7 @@ int indexOfRange(Object o, int start, int end) {
365365
return lastIndexOfRange(o, 0, size);
366366
}
367367

368-
int lastIndexOfRange(Object o, int start, int end) {
368+
int lastIndexOfRange(@Nullable Object o, int start, int end) {
369369
Object[] es = elementData;
370370
if (o == null) {
371371
for (int i = end - 1; i >= start; i--) {
@@ -1297,7 +1297,7 @@ public <T> T[] toArray(T[] a) {
12971297
return a;
12981298
}
12991299

1300-
public boolean equals(Object o) {
1300+
public boolean equals(@Nullable Object o) {
13011301
if (o == this) {
13021302
return true;
13031303
}
@@ -1317,19 +1317,19 @@ public int hashCode() {
13171317
return hash;
13181318
}
13191319

1320-
public int indexOf(Object o) {
1320+
public int indexOf(@Nullable Object o) {
13211321
int index = root.indexOfRange(o, offset, offset + size);
13221322
checkForComodification();
13231323
return index >= 0 ? index - offset : -1;
13241324
}
13251325

1326-
public int lastIndexOf(Object o) {
1326+
public int lastIndexOf(@Nullable Object o) {
13271327
int index = root.lastIndexOfRange(o, offset, offset + size);
13281328
checkForComodification();
13291329
return index >= 0 ? index - offset : -1;
13301330
}
13311331

1332-
public boolean contains(Object o) {
1332+
public boolean contains(@Nullable Object o) {
13331333
return indexOf(o) >= 0;
13341334
}
13351335

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public interface Collection<E> extends Iterable<E> {
268268
*/
269269
@CFComment({"lock: not true, because map could contain nulls: AssertParametersNonNull(\"get(#1)\")"})
270270
@Pure
271-
boolean contains(@GuardSatisfied Collection<E> this, @GuardSatisfied @Nullable Object o);
271+
boolean contains(@GuardSatisfied Collection<E> this, @GuardSatisfied Object o);
272272

273273
/**
274274
* Returns an iterator over the elements in this collection. There are no
@@ -460,7 +460,7 @@ default <T> T[] toArray(IntFunction<T[]> generator) {
460460
* @throws UnsupportedOperationException if the {@code remove} operation
461461
* is not supported by this collection
462462
*/
463-
boolean remove(@GuardSatisfied Collection<E> this, @Nullable Object o);
463+
boolean remove(@GuardSatisfied Collection<E> this, Object o);
464464

465465

466466
// Bulk Operations

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ public interface Deque<E> extends Queue<E> {
580580
* deque does not permit null elements
581581
* (<a href="{@docRoot}/java.base/java/util/Collection.html#optional-restrictions">optional</a>)
582582
*/
583-
boolean remove(@GuardSatisfied Deque<E> this, @Nullable Object o);
583+
boolean remove(@GuardSatisfied Deque<E> this, Object o);
584584

585585
/**
586586
* Returns {@code true} if this deque contains the specified element.
@@ -597,7 +597,7 @@ public interface Deque<E> extends Queue<E> {
597597
* (<a href="{@docRoot}/java.base/java/util/Collection.html#optional-restrictions">optional</a>)
598598
*/
599599
@Pure
600-
boolean contains(@GuardSatisfied Deque<E> this, @Nullable Object o);
600+
boolean contains(@GuardSatisfied Deque<E> this, Object o);
601601

602602
/**
603603
* Returns the number of elements in this deque.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public Dictionary() {
122122
* @see java.util.Dictionary#put(java.lang.Object, java.lang.Object)
123123
*/
124124
@Pure
125-
public abstract @Nullable V get(@GuardSatisfied Dictionary<K, V> this, @Nullable Object key);
125+
public abstract @Nullable V get(@GuardSatisfied Dictionary<K, V> this, Object key);
126126

127127
/**
128128
* Maps the specified {@code key} to the specified

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public EnumMap(Map<K, ? extends V> m) {
212212
* @return {@code true} if this map maps one or more keys to this value
213213
*/
214214
@Pure
215-
public boolean containsValue(@Nullable Object value) {
215+
public boolean containsValue(Object value) {
216216
value = maskNull(value);
217217

218218
for (Object val : vals)
@@ -232,7 +232,7 @@ public boolean containsValue(@Nullable Object value) {
232232
*/
233233
@EnsuresKeyForIf(expression={"#1"}, result=true, map={"this"})
234234
@Pure
235-
public boolean containsKey(@Nullable Object key) {
235+
public boolean containsKey(Object key) {
236236
return isValidKey(key) && vals[((Enum<?>)key).ordinal()] != null;
237237
}
238238

@@ -256,7 +256,7 @@ private boolean containsMapping(@Nullable Object key, @Nullable Object value) {
256256
* The {@link #containsKey containsKey} operation may be used to
257257
* distinguish these two cases.
258258
*/
259-
public @Nullable V get(@Nullable Object key) {
259+
public @Nullable V get(Object key) {
260260
return (isValidKey(key) ?
261261
unmaskNull(vals[((Enum<?>)key).ordinal()]) : null);
262262
}

0 commit comments

Comments
 (0)