disableWarningsInGeneratedCode does not suppress warnings for jakarta.annotation.Generated
- Dominant language
- Java
- Stars
- 7.2k
- Forks
- 820
- Avg merge
- 5h 9m
- Merged PRs (30d)
- 50
Description
`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:
```java
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`:
```kotlin
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
Contributor guide
Assessment
This issue has not been assessed yet.