Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/util/HashMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -1217,8 +1217,8 @@ public boolean replace(K key, V oldValue, V newValue) {
* mapping function modified this map
*/
@Override
public V computeIfAbsent(K key,
Function<? super K, ? extends V> mappingFunction) {
public @Nullable V computeIfAbsent(K key,
Function<? super K, ? extends @Nullable V> mappingFunction) {
if (mappingFunction == null)
throw new NullPointerException();
int hash = hash(key);
Expand Down
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/util/Hashtable.java
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ public synchronized boolean replace(K key, V oldValue, V newValue) {
* mapping function modified this map
*/
@Override
public synchronized V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) {
public synchronized @Nullable V computeIfAbsent(K key, Function<? super K, ? extends @Nullable V> mappingFunction) {
Objects.requireNonNull(mappingFunction);

Entry<?,?> tab[] = table;
Expand Down
5 changes: 3 additions & 2 deletions src/java.base/share/classes/java/util/Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -1081,8 +1081,9 @@ default boolean replace(K key, V oldValue, V newValue) {
* ({@linkplain Collection##optional-restrictions optional})
* @since 1.8
*/
default V computeIfAbsent(K key,
Function<? super K, ? extends V> mappingFunction) {
// We would use an annotation like @PolyNull here if JSpecify offered one.
default @Nullable V computeIfAbsent(K key,
Function<? super K, ? extends @Nullable V> mappingFunction) {
Objects.requireNonNull(mappingFunction);
V v;
if ((v = get(key)) == null) {
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/util/Properties.java
Original file line number Diff line number Diff line change
Expand Up @@ -1502,8 +1502,8 @@ public synchronized boolean replace(Object key, Object oldValue, Object newValue
}

@Override
public synchronized Object computeIfAbsent(Object key,
Function<? super Object, ? extends Object> mappingFunction) {
public synchronized @Nullable Object computeIfAbsent(Object key,
Function<? super Object, ? extends @Nullable Object> mappingFunction) {
return map.computeIfAbsent(key, mappingFunction);
}

Expand Down
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/util/TreeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ final Entry<K,V> getLowerEntry(K key) {
* mapping function modified this map
*/
@Override
public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) {
public @Nullable V computeIfAbsent(K key, Function<? super K, ? extends @Nullable V> mappingFunction) {
Objects.requireNonNull(mappingFunction);
V newValue;
Entry<K,V> t = root;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1725,7 +1725,7 @@ boolean removeValueIf(Predicate<? super V> function) {
* @throws RuntimeException or Error if the mappingFunction does so,
* in which case the mapping is left unestablished
*/
public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) {
public @Nullable V computeIfAbsent(K key, Function<? super K, ? extends @Nullable V> mappingFunction) {
if (key == null || mappingFunction == null)
throw new NullPointerException();
int h = spread(key.hashCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ default void replaceAll(BiFunction<? super K, ? super V, ? extends V> function)
* @since 1.8
*/
@Override
default V computeIfAbsent(K key,
Function<? super K, ? extends V> mappingFunction) {
default @Nullable V computeIfAbsent(K key,
Function<? super K, ? extends @Nullable V> mappingFunction) {
Objects.requireNonNull(mappingFunction);
V oldValue, newValue;
return ((oldValue = get(key)) == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1463,8 +1463,8 @@ else if ((d = h.down) != null) // remove levels
* or the mappingFunction is null
* @since 1.8
*/
public V computeIfAbsent(K key,
Function<? super K, ? extends V> mappingFunction) {
public @Nullable V computeIfAbsent(K key,
Function<? super K, ? extends @Nullable V> mappingFunction) {
if (key == null || mappingFunction == null)
throw new NullPointerException();
V v, p, r;
Expand Down
Loading