Files
openide/java/java-tests/testData/inspection/dataFlow/fixture/MapGetWithValueNullability.java
Tagir Valeev 8fbbd7a3de Report nullable Map.get if map values are nullable
Part of IDEA-236740

GitOrigin-RevId: d507993271d302a7a5fb2e3d1aacb3274cea79b1
2020-04-27 10:33:18 +00:00

35 lines
1.1 KiB
Java

import foo.*;
import java.util.*;
class Test {
public void main(Map<@NotNull String, @NotNull Integer> map, HashMap<@NotNull String, @NotNull Integer> hashMap) {
Integer value = map.get("y");
if (value == null) {
System.out.println("it's not contained");
}
map.get("z").intValue();
value = hashMap.get("y");
if (value == null) {
System.out.println("it's not contained");
}
}
public void main1(Map<@NotNull String, @Nullable Integer> map, HashMap<@NotNull String, @Nullable Integer> hashMap) {
map.get("y").<warning descr="Method invocation 'intValue' may produce 'NullPointerException'">intValue</warning>();
hashMap.get("y").<warning descr="Method invocation 'intValue' may produce 'NullPointerException'">intValue</warning>();
}
public void main2(Map<@NotNull String, @NotNull Integer> map, HashMap<@NotNull String, @NotNull Integer> hashMap) {
Integer value = map.remove("y");
if (value == null) {
System.out.println("it's not contained");
}
value = hashMap.remove("y");
if (value == null) {
System.out.println("it's not contained");
}
}
}