jdk9 / jdk10 : NPE in visitIdent in javac when addition of module(s) is missing in compilation

Baesken, Matthias matthias.baesken at sap.com
Wed Aug 9 14:26:26 UTC 2017


Hello ,
     we noticed the issue below in jdk9/jdk10 (current builds).
See also bug  https://bugs.openjdk.java.net/browse/JDK-8186030     .
In case of missing modules , the javac compilation might run into an NPE.
One can of course work around this by adding null check, but maybe you have something "better" in mind.

This is the example program (please note that when directly importing
"import javax.rmi.PortableRemoteObject;"
we get a decent error message and not the NPE).
----------------------------- snip -------------------------------------------
import javax.rmi.*;

// this leads however to "error: package javax.rmi is not visible"
//import javax.rmi.PortableRemoteObject;

import java.io.File;
import java.rmi.RemoteException;

public class Sample extends PortableRemoteObject {

    public Sample(File file) throws RemoteException {
    }
}
-------------------------------------------------------------------------------

When adding the missing module in the compilation (--add-modules java.se.ee) all works fine and compiles.
Otherwise we get the NPE because some fields ( e.g. sym) are null and this is not handled.
9/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java

        public void visitIdent(JCIdent tree) {
            // comment added : tree.sym is null in our special missing module case of the example
            // we could add here e.g. some error generation
            //if (tree.sym == null) {
            //    ... error message ??
            //}
            if (tree.sym.kind == VAR) {
                checkInit(tree.pos(), (VarSymbol)tree.sym);
                referenced(tree.sym);
            }
        }

So  should I make a change and generate a  proper error  in  visitIdent   when  sym is null ?
Or has someone something better in mind ?


Btw I found a similar bug and  recent addition addition by Coleen Phillimore :

NPE in Flow.visitIdent
https://bugs.openjdk.java.net/browse/JDK-7194212

(Coleen Phillimore added a comment - 2017-05-23 11:24  , looks similar ).


First the working compilation :
-------------------------------------

/openjdk/nb/linuxx86_64/last_known_good/output-jdk9/images/jdk/bin/javac --add-modules java.se.ee Sample.java
Now the NPE when the module is not added (jdk9 and jdk10 show the error).
---------------------------------------------------------------------------
/openjdk/nb/linuxx86_64/last_known_good/output-jdk9/images/jdk/bin/javac Sample.java
An exception has occurred in the compiler (9.0.0.1-internal).
 Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates.
 Include your program and the following diagnostic in your report. Thank you.
java.lang.NullPointerException
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.visitIdent(Flow.java:2478)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCIdent.accept(JCTree.java:2237)
                at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:393)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.scan(Flow.java:1451)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.scanExpr(Flow.java:1707)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.visitApply(Flow.java:2331)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1628)
                at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:393)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.scan(Flow.java:1451)
                at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitExec(TreeScanner.java:213)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1446)
                at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:393)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.scan(Flow.java:1451)
                at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.visitBlock(Flow.java:1956)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1014)
                at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:393)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.scan(Flow.java:1451)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.visitMethodDef(Flow.java:1884)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:866)
                at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:393)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.scan(Flow.java:1451)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.visitClassDef(Flow.java:1822)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:774)
                at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:393)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.scan(Flow.java:1451)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.analyzeTree(Flow.java:2521)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.analyzeTree(Flow.java:2504)
                at jdk.compiler/com.sun.tools.javac.comp.Flow.analyzeTree(Flow.java:212)
                at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1389)
                at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1363)
                at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:959)
                at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:302)
                at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:162)
                at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
                at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)


/openjdk/nb/linuxx86_64/last_known_good/output-jdk10/images/jdk/bin/javac Sample.java
An exception has occurred in the compiler (10.0.0.1-internal).
Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates.
Include your program and the following diagnostic in your report. Thank you.
java.lang.NullPointerException
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.visitIdent(Flow.java:2477)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCIdent.accept(JCTree.java:2237)
                at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:395)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.scan(Flow.java:1450)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.scanExpr(Flow.java:1706)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.visitApply(Flow.java:2330)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1628)
                at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:395)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.scan(Flow.java:1450)
                at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitExec(TreeScanner.java:213)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1446)
                at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:395)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.scan(Flow.java:1450)
                at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.visitBlock(Flow.java:1955)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1014)
                at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:395)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.scan(Flow.java:1450)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.visitMethodDef(Flow.java:1883)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:866)
                at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:395)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.scan(Flow.java:1450)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.visitClassDef(Flow.java:1821)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:774)
                at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:395)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.scan(Flow.java:1450)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.analyzeTree(Flow.java:2520)
                at jdk.compiler/com.sun.tools.javac.comp.Flow$AssignAnalyzer.analyzeTree(Flow.java:2503)
                at jdk.compiler/com.sun.tools.javac.comp.Flow.analyzeTree(Flow.java:214)
                at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1392)
                at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1366)
                at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:964)
                at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:305)
                at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:165)
                at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
                at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)


Thanks, Matthias


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20170809/f5d4a0f7/attachment-0001.html>


More information about the compiler-dev mailing list