[java-inspections] Do not report 'Not annotated method is used as an override...' when method ref target is a library method

Initially, it was implemented to simplify annotation propagation. But we don't do this for libraries (as this would require adding external annotation which is not always desired)

Fixes IDEA-292765 Lambda can be method reference inspection doesn't consider nullability of the functional interface

GitOrigin-RevId: d99b253173c607234dea50eebb0da513d52ca5a7
This commit is contained in:
Tagir Valeev
2022-04-25 22:42:12 +00:00
committed by intellij-monorepo-bot
parent a3eced1e77
commit a535ce5071
3 changed files with 18 additions and 1 deletions
@@ -482,7 +482,8 @@ public class NullableStuffInspectionBase extends AbstractBaseJavaLocalInspection
reportProblem(holder, refName, "inspection.nullable.problems.Nullable.method.overrides.NotNull",
getPresentableAnnoName(targetMethod), getPresentableAnnoName(superMethod));
}
else if (isNonAnnotatedOverridingNotNull(targetMethod, superMethod)) {
else if (!(targetMethod instanceof PsiCompiledElement) &&
isNonAnnotatedOverridingNotNull(targetMethod, superMethod)) {
reportProblem(holder, refName, createFixForNonAnnotatedOverridesNotNull(targetMethod, superMethod),
"not.annotated.method.is.used.as.an.override.for.a.method.annotated.with.0", getPresentableAnnoName(superMethod));
}
@@ -0,0 +1,15 @@
import org.jetbrains.annotations.NotNull;
import java.util.List;
class A {
interface FI<T> {
@NotNull List<T> getX(@NotNull T value);
}
void foo() {
FI<String> f = value -> List.of(value);
FI<String> f2 = List::of;
}
}
@@ -124,6 +124,7 @@ public class NullableStuffInspectionTest extends LightJavaCodeInsightFixtureTest
}
public void testOverriddenViaMethodReference() { doTest(); }
public void testMethodReferenceListOf() { doTest(); }
public void testOverridingExternalNotNull() { doTest(); }
public void testIgnoreExternalNotNull() {