RFR: 8335385: javac crash on unattributed piece of AST

Vicente Romero vromero at openjdk.org
Tue Jul 2 19:19:21 UTC 2024


On Mon, 1 Jul 2024 12:00:14 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> 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...

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java line 2427:

> 2425:     Symbol findIdent(DiagnosticPosition pos, Env<AttrContext> env, Name name, KindSelector kind) {
> 2426:         try {
> 2427:             return checkNonExistentType(checkRestrictedType(pos, findIdentInternal(pos, env, name, kind), name));

should the new code be moved into `checkNonExistentType` so that all of its clients benefit from it?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/19969#discussion_r1663040672


More information about the compiler-dev mailing list