[java-inspections] IDEA-376188 follow-up: report top-level annotations as well

GitOrigin-RevId: dbd7c1fd3b59880032f44c9d6ca5838d2763eae0
This commit is contained in:
Tagir Valeev
2025-10-01 15:50:23 +00:00
committed by intellij-monorepo-bot
parent 216eddbbf8
commit 766e2f9727
2 changed files with 13 additions and 12 deletions
@@ -265,16 +265,15 @@ public class NullableStuffInspectionBase extends AbstractBaseJavaLocalInspection
if (context != null) {
checkRedundantInContainerScope(annotation, manager.findDefaultTypeUseNullability(context), nullability);
}
if (nullability == Nullability.NOT_NULL && PsiUtil.resolveClassInClassTypeOnly(type) instanceof PsiTypeParameter) {
PsiType notAnnotated = type.annotate(TypeAnnotationProvider.EMPTY);
TypeNullability notAnnotatedNullability = notAnnotated.getNullability();
if (notAnnotatedNullability.nullability() == Nullability.NOT_NULL &&
notAnnotatedNullability.source() instanceof NullabilitySource.ExtendsBound) {
reportProblem(holder, annotation,
new RemoveAnnotationQuickFix(annotation, null),
"inspection.nullable.problems.redundant.annotation.inherited.notnull");
}
}
if (type != null && nullability == Nullability.NOT_NULL && PsiUtil.resolveClassInClassTypeOnly(type) instanceof PsiTypeParameter) {
PsiType notAnnotated = type.annotate(TypeAnnotationProvider.EMPTY);
TypeNullability notAnnotatedNullability = notAnnotated.getNullability();
if (notAnnotatedNullability.nullability() == Nullability.NOT_NULL &&
notAnnotatedNullability.source() instanceof NullabilitySource.ExtendsBound) {
reportProblem(holder, annotation,
new RemoveAnnotationQuickFix(annotation, null),
"inspection.nullable.problems.redundant.annotation.inherited.notnull");
}
}
if (type instanceof PsiPrimitiveType) {
@@ -5,8 +5,10 @@ import org.jetbrains.annotations.Nullable;
import java.util.List;
@NotNullByDefault
class Container<T> {
class Container<T extends CharSequence> {
<warning descr="Redundant nullability annotation: type parameter upper bound is already non-null">@NotNull</warning> T getT() {
return null;
}
<L extends @Nullable Object> List<@NotNull L> get() {
return null;