RFR: 8309499: javac fails to report compiler.err.no.java.lang with annotation processing enabled

Liam Miller-Cushon cushon at openjdk.org
Mon Jun 12 18:02:49 UTC 2023


On Wed, 7 Jun 2023 21:03:20 GMT, Liam Miller-Cushon <cushon at openjdk.org> wrote:

> Hi,
> 
> Please consider this fix for an error handling bug in javac, which causes a deferred diagnostic to be lost when an `Abort` is thrown with annotation processing enabled. See https://bugs.openjdk.org/browse/JDK-8309499 for more details.
> 
> This fix is contributed by my colleague Paula Toth paulatoth at google.com.

src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java line 985:

> 983:             // missing java.lang error.
> 984:             if (deferredDiagnosticHandler != null) {
> 985:                 deferredDiagnosticHandler.reportDeferredDiagnostics();

The CI run shows some real test failures that still need to be addressed


java.lang.NullPointerException: Cannot invoke "java.util.Queue.poll()" because "this.deferred" is null
        at jdk.compiler/com.sun.tools.javac.util.Log$DeferredDiagnosticHandler.reportDeferredDiagnostics(Log.java:169)
        at jdk.compiler/com.sun.tools.javac.util.Log$DeferredDiagnosticHandler.reportDeferredDiagnostics(Log.java:163)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:985)
        at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:319)
        at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:178)
        at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
        at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)


It looks like `reportDeferredDiagnostics` is now being called twice for some invocations, and when it is called it sets the queue of deferred diagnostics to `null`, so the second call fails: https://github.com/openjdk/jdk/blob/45414fc2dfa41cbbfc6de7fec15eb47f41cf8986/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java#L173

One option would be to set `deferredDiagnosticHandler` to `null` after calling `reportDeferredDiagnostics` in `JavaCompiler`, so we can keep track of whether the deferred diagnostics have already been reported

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

PR Review Comment: https://git.openjdk.org/jdk/pull/14370#discussion_r1227048009


More information about the compiler-dev mailing list