Skip to content

Require the javac flag -XDaddTypeAnnotationsToSymbol=true for Error Prone invocations #5426

@cushon

Description

@cushon

This bug tracks making the javac flag -XDaddTypeAnnotationsToSymbol=true required for javac invocations that enable Error Prone, on JDK 21.

This would be similar to how the following javac flags are already required here

-XDcompilePolicy=simple
--should-stop=ifError=FLOW

On JDK 21, -XDaddTypeAnnotationsToSymbol=true enables a fix for the javac bug [JDK-8225377: type annotations are not visible to javac plugins across compilation boundaries], which Error Prone currently maintains workarounds for (including here). After this change is made, those workarounds can be removed.

-XDaddTypeAnnotationsToSymbol=true is not required on JDK 22 and newer, the fix for JDK-8225377 is enabled by default in newer versions. (And Error Prone no longer supports JDK versions before 21.)

There are some caveats:

  • The flag is available in OpenJDK 21.0.8 and newer, so older update releases of JDK 21 could see issues with type annotations if workarounds for JDK-8225377 are removed.
  • Enabling the fix can in some cases cause the compiler to load additional symbols, and can cause it to report new errors if the compilation classpath is incomplete, see also JDK-8370800: Downgrade cant.attach.type.annotations diagnostics to warnings. These errors are rare, and would be reported for compilations that update past JDK 21.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions