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 74148f53cf88..5c275191c25d 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 @@ -118,15 +118,15 @@ public final class DfaPsiUtil { if (DumbService.isDumb(owner.getProject())) return Nullability.UNKNOWN; NullabilityAnnotationInfo fromAnnotation = getNullabilityFromAnnotation(owner, ignoreParameterNullabilityInference); if (fromAnnotation != null) { - if (fromAnnotation.getNullability() != Nullability.NOT_NULL) { + if (resultType != null && fromAnnotation.getNullability() != Nullability.NOT_NULL) { PsiType type = PsiUtil.getTypeByPsiElement(owner); if (type != null) { PsiAnnotationOwner annotationOwner = fromAnnotation.getAnnotation().getOwner(); - if (PsiUtil.resolveClassInClassTypeOnly(type) instanceof PsiTypeParameter && - annotationOwner instanceof PsiType && annotationOwner != type) { + if (PsiUtil.resolveClassInClassTypeOnly(type) instanceof PsiTypeParameter tp && + annotationOwner instanceof PsiType && annotationOwner != type && + !tp.equals(PsiUtil.resolveClassInClassTypeOnly(resultType))) { // Nullable/Unknown from type hierarchy: should check the instantiation, as it could be more concrete - Nullability fromType = getNullabilityFromType(resultType, owner); - if (fromType != null) return fromType; + return resultType.getNullability().nullability(); } } } diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/GuavaIterablesProblems.java b/java/java-tests/testData/inspection/dataFlow/fixture/GuavaIterablesProblems.java index 34dc909fd6df..3c62464a878f 100644 --- a/java/java-tests/testData/inspection/dataFlow/fixture/GuavaIterablesProblems.java +++ b/java/java-tests/testData/inspection/dataFlow/fixture/GuavaIterablesProblems.java @@ -41,6 +41,10 @@ class MyTest { } + void get2(List l1) { + System.out.println(Iterables.get(l1, 0).length()); + } + void foo(List l1, List l2) { for (String s : Iterables.concat(l1, l2)) { System.out.println(s.length());