Skip to content

Commit

Permalink
Annotate new overrides in collection implementations. (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpovirk authored Oct 7, 2024
1 parent 3491a93 commit 148c6ab
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/util/HashSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,12 @@ public Spliterator<E> spliterator() {
}

@Override
public Object[] toArray() {
public @Nullable Object[] toArray() {
return map.keysToArray(new Object[map.size()]);
}

@Override
public <T> T[] toArray(T[] a) {
public <T extends @Nullable Object> T[] toArray(T[] a) {
return map.keysToArray(map.prepareArray(a));
}

Expand Down
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/util/IdentityHashMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,7 @@ public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
* {@code false}.
*/
@Override
public boolean remove(Object key, Object value) {
public boolean remove(@Nullable Object key, @Nullable Object value) {
return removeMapping(key, value);
}

Expand Down
9 changes: 5 additions & 4 deletions src/java.base/share/classes/java/util/TreeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

package java.util;

import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

Expand Down Expand Up @@ -581,7 +582,7 @@ final Entry<K,V> getLowerEntry(K key) {
}

@Override
public V putIfAbsent(K key, V value) {
public @Nullable V putIfAbsent(K key, V value) {
return put(key, value, false);
}

Expand Down Expand Up @@ -666,7 +667,7 @@ else if (cmp > 0)
* remapping function modified this map
*/
@Override
public V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
public @Nullable V computeIfPresent(K key, BiFunction<? super K, ? super @NonNull V, ? extends @Nullable V> remappingFunction) {
Objects.requireNonNull(remappingFunction);
Entry<K,V> oldEntry = getEntry(key);
if (oldEntry != null && oldEntry.value != null) {
Expand All @@ -687,7 +688,7 @@ public V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> r
* remapping function modified this map
*/
@Override
public V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
public @Nullable V compute(K key, BiFunction<? super K, ? super @Nullable V, ? extends @Nullable V> remappingFunction) {
Objects.requireNonNull(remappingFunction);
V newValue;
Entry<K,V> t = root;
Expand Down Expand Up @@ -749,7 +750,7 @@ else if (cmp > 0)
* remapping function modified this map
*/
@Override
public V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
public @Nullable V merge(K key, @NonNull V value, BiFunction<? super @NonNull V, ? super @NonNull V, ? extends @Nullable V> remappingFunction) {
Objects.requireNonNull(remappingFunction);
Objects.requireNonNull(value);
Entry<K,V> t = root;
Expand Down

0 comments on commit 148c6ab

Please sign in to comment.