RFR: 8321164: javac with annotation processor throws AssertionError: Filling jrt:/... during JarFileObject[/...]

Jan Lahoda jlahoda at openjdk.org
Thu Dec 7 06:46:48 UTC 2023


This is a latent bug revealed by the recent JDK-8225377/https://git.openjdk.org/jdk/commit/de6667cf11aa59d1bab78ae5fb235ea0b901d5c4.

The problem (to my understanding) is as follows:
 - `ClassReader` cannot be used recursively, i.e. while completing one class from a classfile, we cannot complete another one. `ClassReader` carefully avoids situations like this.
 - when reading an anonymous class, the `EnclosingMethod` attribute is read, and the enclosing method must be found. `ClassReader` uses a special `ClassReader. isSameBinaryType` method, that is supposed to avoid completion:
https://github.com/openjdk/jdk/blob/3edc24a71d29632e0a2166a64fc25ce83f631b47/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java#L1401
 - the `isSameBinaryType` method uses erasure, and if the given type has type annotations, the erasure will try to remove the annotations:
https://github.com/openjdk/jdk/blob/3edc24a71d29632e0a2166a64fc25ce83f631b47/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java#L2423

The problem is that this method uses `Type.getKind()` which completes.

The proposal in this patch is to avoid the completion by not using `getKind`, but rather `getTag`. While I am not completely sure why the code avoids doing `dropMetadata` for some types, I tried to replicate the existing behavior. One caveat is that certain types may have `getTag() == CLASS`, but `getKind() == ERROR` (e.g. if the class is not found). The new code is not replicating this aspect, as we cannot reliably determine whether a `ClassType` is erroneous or not without completing it. But, it is not clear to me why dropping annotations from an erroneous `ClassType` should be problematic.

-------------

Commit messages:
 - Restoring behavior w.r.t. null, removing trailing whitespace.
 - 8321164: javac with annotation processor throws AssertionError: Filling jrt:/... during JarFileObject[/...]

Changes: https://git.openjdk.org/jdk/pull/17001/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=17001&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8321164
  Stats: 134 lines in 2 files changed: 124 ins; 0 del; 10 mod
  Patch: https://git.openjdk.org/jdk/pull/17001.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/17001/head:pull/17001

PR: https://git.openjdk.org/jdk/pull/17001


More information about the compiler-dev mailing list