/javac-bug-static-import-apt

Bug in javac that obstructs annotation processing

Primary LanguageJava

Synopsis

Unresolved static imports are unrecoverable and obstruct annotation processing

Description

Compiling a Java source file that contains an unresolved static import leads to the compilation terminating with an error without performing annotation processing. In constrast, when an unresolved regular import is encountered, annotation processing comenses, thereby granting annotation processors a chance to generate the missing type.

Consequently, a Java source file with a static import refering to a type that is yet to be generated by an annotation processor cannot be compiled - it effectively gets stuck. The only remedy is to temporarily modify the file by commenting out the unresolved import until the respective type is generated.

Version, system info

Arch Linux, kernel 6.6.1-arch1-1
openjdk version "22-ea" 2024-03-19
OpenJDK Runtime Environment (build 22-ea+25-1998)
OpenJDK 64-Bit Server VM (build 22-ea+25-1998, mixed mode, sharing)

The problem is also reproducible with versions 21, 17 and 11.

Steps to reproduce

  1. Compile the annotation processor
make processor
  1. Compile the source file with an unresolved regular import and see that annotation processing is performed
make import
  1. Compile the source file with an unresolved static import and see that annotation processing is not performed.
make static-import