RFR: 8335385: javac crash on unattributed piece of AST
Jan Lahoda
jlahoda at openjdk.org
Mon Jul 1 12:05:46 UTC 2024
Consider the following sources:
//B.java
package p;
public class B {
public interface I {}
}
Test.java
import p.B.I;
Then compile `B`, remove the `I` nested interface, and try to compile `Test` with the remaining classfiles of `B` on the classpath:
$ javac -d out B.java
$ rm out/p/B$I.class
$ javac -classpath out -XDdev Test.java
Test.java:1: error: cannot access I
import p.B.I;
^
class file for p.B$I not found
1 error
An exception has occurred in the compiler (24-internal). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com/) after checking the Bug Database (https://bugs.java.com/) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
java.lang.NullPointerException: Cannot read field "owner" because "s.sym" is null
at jdk.compiler/com.sun.tools.javac.comp.Check.isCanonical(Check.java:4264)
at jdk.compiler/com.sun.tools.javac.comp.Check.checkCanonical(Check.java:4256)
at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$ImportsPhase.doImport(TypeEnter.java:466)
at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$ImportsPhase.handleImports(TypeEnter.java:416)
at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$ImportsPhase.resolveImports(TypeEnter.java:389)
at jdk.compiler/com.sun.tools.javac.comp.TypeEnter.lambda$ensureImportsChecked$0(TypeEnter.java:165)
at jdk.compiler/com.sun.tools.javac.comp.TypeEnter.finishImports(TypeEnter.java:217)
at jdk.compiler/com.sun.tools.javac.comp.TypeEnter.ensureImportsChecked(TypeEnter.java:165)
at jdk.compiler/com.sun.tools.javac.comp.Enter.complete(Enter.java:650)
at jdk.compiler/com.sun.tools.javac.comp.Enter.main(Enter.java:600)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:1077)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:948)
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:66)
at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:52)
printing javac parameters to: /tmp/javac.20240701_092709.args
The reason is that when the import is attributed, `Resolve.findIdentInType` is called to find `I` in `p.B`. It will, however, fail with a `CompletionFailure`, as `I` does not exist. And the `CompletionFailure` won't be called sooner than in `Attr.attribTree`, and as a consequence, the `sym` field of the `p.B.I` select will remain `null`, as the code that sets it will be skipped due to the `CompletionFailure`. This then leads to the follow-up NPE.
The proposal herein is to change `Resolve.findIdentInType` and `Resolve.findIdent` to handle `CompletionFailures` immediately, report an error, and return a "missing" `Symbol`. Note that `Resolve.findIdentInPackage` will not throw `CompletionFailure`s, as it uses `Resolve.loadClass`, which handles `CompletionFailure`s. So, this should be making the behavior consistent across `findIdent`, `findIdentInPackage` and `findIdentInType`.
-------------
Commit messages:
- 8335385: javac crash on unattributed piece of AST
Changes: https://git.openjdk.org/jdk/pull/19969/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=19969&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8335385
Stats: 337 lines in 3 files changed: 329 ins; 0 del; 8 mod
Patch: https://git.openjdk.org/jdk/pull/19969.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/19969/head:pull/19969
PR: https://git.openjdk.org/jdk/pull/19969
More information about the compiler-dev
mailing list