Skip to content

disableWarningsInGeneratedCode does not suppress warnings for jakarta.annotation.Generated #5812

@iulspop

Description

@iulspop

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

  1. Use Hibernate ORM 6.x (or any annotation processor that emits @Generated using jakarta.annotation.Generated)
  2. Enable disableWarningsInGeneratedCode via the error-prone Gradle plugin or -XepDisableWarningsInGeneratedCode
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions