diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/nullable/NullableStuffInspectionBase.java b/java/java-analysis-impl/src/com/intellij/codeInspection/nullable/NullableStuffInspectionBase.java index 31db87c104ca..67e2056e331e 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/nullable/NullableStuffInspectionBase.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/nullable/NullableStuffInspectionBase.java @@ -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; } } diff --git a/java/java-tests/testData/inspection/nullableProblems/PassingNullableMapValueWhereNotNullIsExpected.java b/java/java-tests/testData/inspection/nullableProblems/PassingNullableMapValueWhereNotNullIsExpected.java new file mode 100644 index 000000000000..6e3e07e6c9b2 --- /dev/null +++ b/java/java-tests/testData/inspection/nullableProblems/PassingNullableMapValueWhereNotNullIsExpected.java @@ -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 map; + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInspection/NullableStuffInspectionTest.java b/java/java-tests/testSrc/com/intellij/java/codeInspection/NullableStuffInspectionTest.java index 5c9ce08e5639..646a91679ecc 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInspection/NullableStuffInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInspection/NullableStuffInspectionTest.java @@ -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();