[java-dfa] IDEA-368172 Nullable return is not reported for lambda parameterized with unbounded type parameter under NullMarked

(cherry picked from commit 61623e582c856479d4a2222ef33a73178831e074)

IJ-CR-156030

GitOrigin-RevId: 450b280f93a17b3c8500b6cfeaf9be7464e4edd3
This commit is contained in:
Tagir Valeev
2025-02-25 09:15:32 +01:00
committed by intellij-monorepo-bot
parent a9f5abf661
commit 914432b67a
2 changed files with 12 additions and 3 deletions

View File

@@ -273,7 +273,16 @@ public final class DfaPsiUtil {
if (eachType instanceof PsiClassType classType && !local) {
PsiElement context = classType.getPsiContext();
if (context != null) {
return NullableNotNullManager.getInstance(context.getProject()).findDefaultTypeUseNullability(context);
NullableNotNullManager manager = NullableNotNullManager.getInstance(context.getProject());
NullabilityAnnotationInfo typeUseNullability = manager.findDefaultTypeUseNullability(context);
if (typeUseNullability != null) {
return typeUseNullability;
}
PsiClass declaration = PsiUtil.resolveClassInClassTypeOnly(classType);
if (declaration instanceof PsiTypeParameter typeParameter && typeParameter.getExtendsList().getReferenceElements().length == 0) {
// If there's no bound, we assume an implicit `extends Object` bound, which is subject to default annotation if any.
return manager.findDefaultTypeUseNullability(declaration);
}
}
}
return null;

View File

@@ -23,13 +23,13 @@ class ReturnFromParameterizedNullMarked {
return <warning descr="'null' is returned by the method declared as @NullMarked">null</warning>;
}
};
Callable<R> callable2 = () -> null;
Callable<R> callable2 = () -> <warning descr="'null' is returned by the method declared as @NullMarked">null</warning>;
R r = new Callable<R>() {
@Override
public R call() throws Exception {
return <warning descr="'null' is returned by the method declared as @NullMarked">null</warning>;
}
}.call();
R r2 = ((Callable<R>) () -> null).call();
R r2 = ((Callable<R>) () -> <warning descr="Function may return null, but it's not allowed here">null</warning>).call();
}
}