Description
NullAway currently warns for unsafe dereference of Map.get(...), since Map.get(...) may return null when no mapping exists.
However, java.util.Map.remove(Object key) has a very similar return contract: it returns the previous value associated with the key, or null if there was no mapping.
Currently, NullAway appears not to warn when dereferencing the result of Map.remove(...), which can lead to a false negative.
Minimal repro
package com.example;
import java.util.Map;
class Test {
void removeShouldBeNullable(Map<String, Object> map) {
map.remove("x").toString(); // Expected NullAway warning, but no warning currently
}
void getIsAlreadyNullable(Map<String, Object> map) {
map.get("x").toString(); // NullAway warns
}
}
Description
NullAway currently warns for unsafe dereference of
Map.get(...), sinceMap.get(...)may returnnullwhen no mapping exists.However,
java.util.Map.remove(Object key)has a very similar return contract: it returns the previous value associated with the key, ornullif there was no mapping.Currently, NullAway appears not to warn when dereferencing the result of
Map.remove(...), which can lead to a false negative.Minimal repro