[java-analysis] Eclipse annotations: TYPE_BOUND/TYPE_ARGUMENT targets should not apply to mixed places like FIELD+TYPE_USE

Fixes IDEA-272286 org.eclipse.jdt.annotation.NonNullByDefault should not add @NonNull to Local variables

GitOrigin-RevId: a9c8f21ea5e50ef4696d2c98e5a0b01e40dd1797
This commit is contained in:
Tagir Valeev
2021-06-25 11:42:13 +00:00
committed by intellij-monorepo-bot
parent 105488ed63
commit 61bf6f49a8
3 changed files with 7 additions and 2 deletions
@@ -45,7 +45,8 @@ class EclipseAnnotationSupport implements AnnotationPackageSupport {
else if (value instanceof PsiLiteralExpression && Boolean.FALSE.equals(((PsiLiteralExpression)value).getValue())) {
targets = ArrayUtil.EMPTY_STRING_ARRAY;
}
boolean targetApplies = StreamEx.of(targets).map(TARGET_MAP::get).nonNull().anyMatch(loc -> ArrayUtil.contains(loc, types));
boolean targetApplies = StreamEx.of(targets).map(TARGET_MAP::get).nonNull()
.anyMatch(loc -> loc == PsiAnnotation.TargetType.TYPE_USE ? types.length == 1 && types[0] == loc : ArrayUtil.contains(loc, types));
return new NullabilityAnnotationInfo(anno, targetApplies ? Nullability.NOT_NULL : Nullability.UNKNOWN, true);
}
return null;
@@ -16,6 +16,10 @@ public class EclipseDefaultTypeUse {
// List::add is not annotated but ArrayList<String> is defined in context of TYPE_USE NonNullByDefault annotation
a.add(<warning descr="Passing 'null' argument to parameter annotated as @NotNull">null</warning>);
}
void local() {
String s = null;
}
}
@NonNullByDefault
@FunctionalInterface
@@ -9,7 +9,7 @@ import java.lang.annotation.*;
@NonNullByDefault
class X {
void test() {
String x = Y.getFoo();
@NonNull String x = Y.getFoo();
}
}