mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-176701 Missing warning when collection with null elements is returned by method that does not allow null elements
This commit is contained in:
+2
-1
@@ -278,7 +278,8 @@ public class NullableStuffInspectionBase extends BaseJavaBatchLocalInspectionToo
|
||||
for (int i = 0; i <= 1; i++) {
|
||||
PsiType expectedArg = PsiUtil.substituteTypeParameter(expectedType, CommonClassNames.JAVA_UTIL_MAP, i, false);
|
||||
PsiType assignedArg = PsiUtil.substituteTypeParameter(assignedType, CommonClassNames.JAVA_UTIL_MAP, i, false);
|
||||
if (isNullityConflict(expectedArg, assignedArg)) {
|
||||
if (isNullityConflict(expectedArg, assignedArg) ||
|
||||
expectedArg != null && assignedArg != null && isNullableNotNullCollectionConflict(place, expectedArg, assignedArg)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import typeUse.*;
|
||||
import java.util.*;
|
||||
|
||||
class Test {
|
||||
|
||||
public @NotNull Map<@NotNull String, @NotNull ArrayList<@NotNull String>> getDataBroken() {
|
||||
ArrayList<@Nullable String> arrayList = new ArrayList<>();
|
||||
arrayList.add(null);
|
||||
|
||||
@NotNull Map<@NotNull String, @NotNull ArrayList<@Nullable String>> map = new HashMap<>();
|
||||
map.put("x", arrayList);
|
||||
return <warning descr="Assigning a collection of nullable elements into a collection of non-null elements">map</warning>;
|
||||
}
|
||||
}
|
||||
+5
@@ -207,6 +207,11 @@ public class NullableStuffInspectionTest extends LightCodeInsightFixtureTestCase
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testPassingNullableMapValueWhereNotNullIsExpected() {
|
||||
DataFlowInspection8Test.setupTypeUseAnnotations("typeUse", myFixture);
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNotNullCollectionItemWithNullableSuperType() {
|
||||
DataFlowInspection8Test.setupTypeUseAnnotations("typeUse", myFixture);
|
||||
doTest();
|
||||
|
||||
Reference in New Issue
Block a user