hardcode Map.remove as having unknown nullity (IDEA-CR-28277, IDEA-183875)

This commit is contained in:
peter
2018-01-08 18:52:37 +01:00
parent 0d510a529b
commit 9cffe95fa7
3 changed files with 17 additions and 5 deletions
@@ -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
@@ -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");
}
}
}
@@ -1646,7 +1646,6 @@
<val name="source" val="&quot;this.values&quot;"/>
<val name="sourceIsContainer" val="true" />
</annotation>
<annotation name='org.jetbrains.annotations.Nullable'/>
</item>
<item name='java.util.Map V replace(K, V)'>
<annotation name='org.jetbrains.annotations.Contract'>