Skip to content

Commit 148c6ab

Browse files
authored
Annotate new overrides in collection implementations. (#75)
1 parent 3491a93 commit 148c6ab

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -382,12 +382,12 @@ public Spliterator<E> spliterator() {
382382
}
383383

384384
@Override
385-
public Object[] toArray() {
385+
public @Nullable Object[] toArray() {
386386
return map.keysToArray(new Object[map.size()]);
387387
}
388388

389389
@Override
390-
public <T> T[] toArray(T[] a) {
390+
public <T extends @Nullable Object> T[] toArray(T[] a) {
391391
return map.keysToArray(map.prepareArray(a));
392392
}
393393

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,7 @@ public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
14441444
* {@code false}.
14451445
*/
14461446
@Override
1447-
public boolean remove(Object key, Object value) {
1447+
public boolean remove(@Nullable Object key, @Nullable Object value) {
14481448
return removeMapping(key, value);
14491449
}
14501450

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
package java.util;
2727

28+
import org.jspecify.annotations.NonNull;
2829
import org.jspecify.annotations.NullMarked;
2930
import org.jspecify.annotations.Nullable;
3031

@@ -581,7 +582,7 @@ final Entry<K,V> getLowerEntry(K key) {
581582
}
582583

583584
@Override
584-
public V putIfAbsent(K key, V value) {
585+
public @Nullable V putIfAbsent(K key, V value) {
585586
return put(key, value, false);
586587
}
587588

@@ -666,7 +667,7 @@ else if (cmp > 0)
666667
* remapping function modified this map
667668
*/
668669
@Override
669-
public V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
670+
public @Nullable V computeIfPresent(K key, BiFunction<? super K, ? super @NonNull V, ? extends @Nullable V> remappingFunction) {
670671
Objects.requireNonNull(remappingFunction);
671672
Entry<K,V> oldEntry = getEntry(key);
672673
if (oldEntry != null && oldEntry.value != null) {
@@ -687,7 +688,7 @@ public V computeIfPresent(K key, BiFunction<? super K, ? super V, ? extends V> r
687688
* remapping function modified this map
688689
*/
689690
@Override
690-
public V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
691+
public @Nullable V compute(K key, BiFunction<? super K, ? super @Nullable V, ? extends @Nullable V> remappingFunction) {
691692
Objects.requireNonNull(remappingFunction);
692693
V newValue;
693694
Entry<K,V> t = root;
@@ -749,7 +750,7 @@ else if (cmp > 0)
749750
* remapping function modified this map
750751
*/
751752
@Override
752-
public V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
753+
public @Nullable V merge(K key, @NonNull V value, BiFunction<? super @NonNull V, ? super @NonNull V, ? extends @Nullable V> remappingFunction) {
753754
Objects.requireNonNull(remappingFunction);
754755
Objects.requireNonNull(value);
755756
Entry<K,V> t = root;

0 commit comments

Comments
 (0)