IDEA-385863 [java-inspections] False-positive «redundant nullability annotation» inspection warning on @lombok.NonNull

GitOrigin-RevId: ae53fba211152012ca2542ce32f23accd2d68d2f
This commit is contained in:
Tagir Valeev
2026-02-13 14:31:54 +00:00
committed by intellij-monorepo-bot
parent 0fbb5fb8e6
commit f697eeaf1d
7 changed files with 58 additions and 0 deletions
@@ -449,6 +449,9 @@ public class NullableStuffInspectionBase extends AbstractBaseJavaLocalInspection
if (REPORT_REDUNDANT_NULLABILITY_ANNOTATION_IN_THE_SCOPE_OF_ANNOTATED_CONTAINER) {
NullabilityAnnotationInfo containerInfo = wrapper.findContainerInfoForRedundantAnnotation();
if (containerInfo != null) {
if (containerInfo.getNullability() == Nullability.NOT_NULL && manager.isNonNullUsedForInstrumentation(wrapper.annotation())) {
return;
}
reportRedundantInContainerScope(wrapper.annotation(), containerInfo);
}
}
@@ -555,6 +555,14 @@ public class NullableNotNullManagerImpl extends NullableNotNullManager implement
});
}
@Override
public boolean isNonNullUsedForInstrumentation(@NotNull PsiAnnotation annotation) {
String qualifiedName = annotation.getQualifiedName();
if (qualifiedName == null) return false;
AnnotationPackageSupport support = AnnotationPackageSupport.EP_NAME.findFirstSafe(e -> e.getNullabilityAnnotations(Nullability.NOT_NULL).contains(qualifiedName));
return support != null && support.isNonNullUsedForInstrumentation();
}
@Override
public void dispose() {
@@ -66,4 +66,12 @@ public interface AnnotationPackageSupport {
default boolean canAnnotateLocals() {
return true;
}
/**
* @return true if the non-null annotation reported by this support is used for the instrumentation or code generation.
* In this case, it won't be reported as redundant if it appears in the scope of container non-null annotation.
*/
default boolean isNonNullUsedForInstrumentation() {
return false;
}
}
@@ -495,6 +495,14 @@ public abstract class NullableNotNullManager {
.getNullability(annotation.getQualifiedName()) != null;
}
/**
* @param annotation annotation to check
* @return true if the annotation is a non-null annotation, which is used for instrumentation or code generation.
*/
public boolean isNonNullUsedForInstrumentation(@NotNull PsiAnnotation annotation) {
return false;
}
protected interface NullabilityAnnotationDataHolder {
/**
* @return qualified names of all recognized annotations
@@ -16,4 +16,9 @@ final class LombokAnnotationSupport implements AnnotationPackageSupport {
}
return Collections.emptyList();
}
@Override
public boolean isNonNullUsedForInstrumentation() {
return true;
}
}
@@ -0,0 +1,22 @@
package de.plushnikov.intellij.plugin.inspection;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.nullable.NullableStuffInspectionBase;
public class LombokNullableStuffInspectionTest extends LombokInspectionTest {
@Override
protected String getBasePath() {
return super.getBasePath() + "/" + TEST_DATA_INSPECTION_DIRECTORY + "/diverse";
}
@Override
protected InspectionProfileEntry getInspection() {
return new NullableStuffInspectionBase();
}
public void testNoRedundantUnderNullMarked() {
doTest();
}
}
@@ -0,0 +1,4 @@
@org.jetbrains.annotations.NotNullByDefault
class X {
@lombok.NonNull String myField;
}