diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaPsiUtil.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaPsiUtil.java
index cc2d25715b7f..015e36bf41cd 100644
--- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaPsiUtil.java
+++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaPsiUtil.java
@@ -106,7 +106,7 @@ public class DfaPsiUtil {
return Nullness.NOT_NULL;
}
- if (owner instanceof PsiMethod && isMapGet((PsiMethod)owner)) {
+ if (owner instanceof PsiMethod && isMapMethodWithUnknownNullity((PsiMethod)owner)) {
return Nullness.UNKNOWN;
}
@@ -127,10 +127,11 @@ public class DfaPsiUtil {
return Nullness.UNKNOWN;
}
- private static boolean isMapGet(@NotNull PsiMethod method) {
- if (!"get".equals(method.getName())) return false;
+ private static boolean isMapMethodWithUnknownNullity(@NotNull PsiMethod method) {
+ String name = method.getName();
+ if (!"get".equals(name) && !"remove".equals(name)) return false;
PsiMethod superMethod = DeepestSuperMethodsSearch.search(method).findFirst();
- return "java.util.Map.get".equals(PsiUtil.getMemberQualifiedName(superMethod != null ? superMethod : method));
+ return ("java.util.Map." + name).equals(PsiUtil.getMemberQualifiedName(superMethod != null ? superMethod : method));
}
@NotNull
diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/MapGetWithNotNullKeys.java b/java/java-tests/testData/inspection/dataFlow/fixture/MapGetWithNotNullKeys.java
index c9d61344c22b..44ed68952ae2 100644
--- a/java/java-tests/testData/inspection/dataFlow/fixture/MapGetWithNotNullKeys.java
+++ b/java/java-tests/testData/inspection/dataFlow/fixture/MapGetWithNotNullKeys.java
@@ -14,4 +14,16 @@ class Test {
System.out.println("it's not contained");
}
}
+
+ 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");
+ }
+ }
}
\ No newline at end of file
diff --git a/java/jdkAnnotations/java/util/annotations.xml b/java/jdkAnnotations/java/util/annotations.xml
index dd8d2ec39dae..c02583de70dc 100644
--- a/java/jdkAnnotations/java/util/annotations.xml
+++ b/java/jdkAnnotations/java/util/annotations.xml
@@ -1646,7 +1646,6 @@
-
-