Integrated: 8321164: javac with annotation processor throws AssertionError: Filling jrt:/... during JarFileObject[/...]
Jan Lahoda
jlahoda at openjdk.org
Thu Dec 7 09:12:51 UTC 2023
On Wed, 6 Dec 2023 18:52:48 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> 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.
This pull request has now been integrated.
Changeset: 03c45951
Author: Jan Lahoda <jlahoda at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/03c4595173d564df97aa4f2b3156adcd4be379fa
Stats: 134 lines in 2 files changed: 124 ins; 0 del; 10 mod
8321164: javac with annotation processor throws AssertionError: Filling jrt:/... during JarFileObject[/...]
Reviewed-by: vromero, mcimadamore
-------------
PR: https://git.openjdk.org/jdk/pull/17001
More information about the compiler-dev
mailing list