RFR: 8341070: javac fails with an exception when compiling import module under source level 8
Adam Sotona
asotona at openjdk.org
Thu Oct 10 14:04:09 UTC 2024
On Mon, 30 Sep 2024 11:37:33 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> Consider code like:
>
> package test;
>
> import module java.base;
>
> public class Test {
> List<String> l;
> }
>
>
> Compiling this may cause javac to fail with an exception under some circumstances:
>
> $ javac --source 8 -XDshould-stop.at=FLOW -XDdev /tmp/Test.java
> warning: [options] bootstrap class path is not set in conjunction with -source 8
> not setting the bootstrap class path may lead to class files that cannot run on JDK 8
> --release 8 is recommended instead of -source 8 because it sets the bootstrap class path automatically
> warning: [options] source value 8 is obsolete and will be removed in a future release
> warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
> /tmp/Test.java:3: error: module imports are a preview feature and are disabled by default.
> import module java.base;
> ^
> (use --enable-preview to enable module imports)
> 1 error
> 3 warnings
> An exception has occurred in the compiler (23-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 invoke "java.util.Set.contains(Object)" because "this.env.toplevel.modle.readModules" is null
> at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$ImportsPhase.doModuleImport(TypeEnter.java:477)
> at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$ImportsPhase.handleImports(TypeEnter.java:414)
> at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$ImportsPhase.resolveImports(TypeEnter.java:389)
> at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$ImportsPhase.runPhase(TypeEnter.java:318)
> at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$Phase.doCompleteEnvs(TypeEnter.java:279)
> at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$Phase.completeEnvs(TypeEnter.java:248)
> at jdk.compiler/com.sun.tools.javac.comp.TypeEnter.complete(TypeEnter.java:195)
> at jdk.compiler/com.sun.tools.javac.code.Symbol.complete(Symbol.java:687)
> at jdk.compiler/com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:1455)
> at jdk.compiler/com.sun.tools.javac.comp.Enter.complete(Enter.java:632)
> at jdk.compiler/com.sun.tools.javac.comp.Enter.main(Enter.java:599)
> at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.enterTrees(J...
Looks good to me.
-------------
Marked as reviewed by asotona (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/21262#pullrequestreview-2360473715
More information about the compiler-dev
mailing list