disableWarningsInGeneratedCode does not suppress warnings in files annotated with jakarta.annotation.Generated
Description
-XepDisableWarningsInGeneratedCode / disableWarningsInGeneratedCode does not suppress errors or warnings in Java source files annotated with jakarta.annotation.Generated, even though it does work for javax.annotation.processing.Generated.
Steps to reproduce
- Use Hibernate ORM 6.x (or any annotation processor that emits
@Generated using jakarta.annotation.Generated)
- Enable
disableWarningsInGeneratedCode via the error-prone Gradle plugin or -XepDisableWarningsInGeneratedCode
- Build — error-prone reports violations (e.g.
UnnecessarilyFullyQualified) on the generated metamodel classes (Analysis_.java, etc.)
Hibernate's metamodel processor generates files like:
import jakarta.annotation.Generated;
@StaticMetamodel(Analysis.class)
@Generated("org.hibernate.processor.HibernateProcessor")
public abstract class Analysis_ { ... }
Despite the @Generated annotation being present, error-prone does not treat the file as generated code.
Root cause
ASTHelpers.getGeneratedBy(Symbol) uses symbol.getRawAttributes() to find @Generated annotations. jakarta.annotation.Generated has @Retention(SOURCE), so during compilation the annotation is present in the source AST but appears not to be surfaced by getRawAttributes() in the way that error-prone expects. The result is that SuppressionInfo.isGenerated() returns false for these classes.
The name matching itself (getSimpleName().contentEquals("Generated")) is already package-agnostic and correct — the issue is purely about retention/attribute visibility.
This is the same class of problem as #1863 (Lombok's @Retention(CLASS) annotation being invisible), applied to @Retention(SOURCE).
Context
javax.annotation.processing.Generated (Java 9+, @Retention(SOURCE)) — works correctly
jakarta.annotation.Generated (Jakarta EE, @Retention(SOURCE)) — not recognized
Both annotations have identical simple names and identical retention policies, so the discrepancy is unexpected. It may be that getRawAttributes() populates differently for these two annotations in the javac symbol table, or that there is a special case somewhere that handles javax.annotation.* but not jakarta.annotation.*.
Workaround
Exclude annotationProcessor output via excludedPaths:
options.errorprone {
disableWarningsInGeneratedCode.set(true)
excludedPaths.set(".*/build/generated/sources/annotationProcessor/.*")
}
Environment
- error-prone version: 2.36.0
- Gradle error-prone plugin: net.ltgt.errorprone 4.1.0
- Hibernate ORM: 7.0.0.Final (metamodel processor uses
jakarta.annotation.Generated)
- Java: 26
disableWarningsInGeneratedCodedoes not suppress warnings in files annotated withjakarta.annotation.GeneratedDescription
-XepDisableWarningsInGeneratedCode/disableWarningsInGeneratedCodedoes not suppress errors or warnings in Java source files annotated withjakarta.annotation.Generated, even though it does work forjavax.annotation.processing.Generated.Steps to reproduce
@Generatedusingjakarta.annotation.Generated)disableWarningsInGeneratedCodevia the error-prone Gradle plugin or-XepDisableWarningsInGeneratedCodeUnnecessarilyFullyQualified) on the generated metamodel classes (Analysis_.java, etc.)Hibernate's metamodel processor generates files like:
Despite the
@Generatedannotation being present, error-prone does not treat the file as generated code.Root cause
ASTHelpers.getGeneratedBy(Symbol)usessymbol.getRawAttributes()to find@Generatedannotations.jakarta.annotation.Generatedhas@Retention(SOURCE), so during compilation the annotation is present in the source AST but appears not to be surfaced bygetRawAttributes()in the way that error-prone expects. The result is thatSuppressionInfo.isGenerated()returnsfalsefor these classes.The name matching itself (
getSimpleName().contentEquals("Generated")) is already package-agnostic and correct — the issue is purely about retention/attribute visibility.This is the same class of problem as #1863 (Lombok's
@Retention(CLASS)annotation being invisible), applied to@Retention(SOURCE).Context
javax.annotation.processing.Generated(Java 9+,@Retention(SOURCE)) — works correctlyjakarta.annotation.Generated(Jakarta EE,@Retention(SOURCE)) — not recognizedBoth annotations have identical simple names and identical retention policies, so the discrepancy is unexpected. It may be that
getRawAttributes()populates differently for these two annotations in the javac symbol table, or that there is a special case somewhere that handlesjavax.annotation.*but notjakarta.annotation.*.Workaround
Exclude annotationProcessor output via
excludedPaths:options.errorprone { disableWarningsInGeneratedCode.set(true) excludedPaths.set(".*/build/generated/sources/annotationProcessor/.*") }Environment
jakarta.annotation.Generated)