mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Report nullable Map.get if map values are nullable
Part of IDEA-236740 GitOrigin-RevId: d507993271d302a7a5fb2e3d1aacb3274cea79b1
This commit is contained in:
committed by
intellij-monorepo-bot
parent
95e0050d31
commit
8fbbd7a3de
@@ -104,7 +104,7 @@ public class DfaPsiUtil {
|
||||
}
|
||||
|
||||
if (owner instanceof PsiMethod && isMapMethodWithUnknownNullity((PsiMethod)owner)) {
|
||||
return Nullability.UNKNOWN;
|
||||
return getTypeNullability(resultType) == Nullability.NULLABLE ? Nullability.NULLABLE : Nullability.UNKNOWN;
|
||||
}
|
||||
|
||||
Nullability fromType = getTypeNullability(resultType);
|
||||
|
||||
+6
@@ -8,6 +8,7 @@ class Test {
|
||||
if (value == null) {
|
||||
System.out.println("it's not contained");
|
||||
}
|
||||
map.get("z").intValue();
|
||||
|
||||
value = hashMap.get("y");
|
||||
if (value == null) {
|
||||
@@ -15,6 +16,11 @@ class Test {
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
+1
-1
@@ -197,7 +197,7 @@ public class DataFlowInspection8Test extends DataFlowInspectionTestCase {
|
||||
public void testStreamCustomSumMethod() { doTest(); }
|
||||
public void testStreamReduceLogicalAnd() { doTest(); }
|
||||
|
||||
public void testMapGetWithNotNullKeys() { doTestWithCustomAnnotations(); }
|
||||
public void testMapGetWithValueNullability() { doTestWithCustomAnnotations(); }
|
||||
public void testInferNestedForeachNullability() { doTestWithCustomAnnotations(); }
|
||||
|
||||
public void testMethodVsExpressionTypeAnnotationConflict() {
|
||||
|
||||
Reference in New Issue
Block a user