Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8186030

NPE in visitIdent in javac when addition of module(s) is missing in compilation

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P3 P3
    • None
    • 9, 10
    • tools
    • None
    • generic
    • generic

      We noticed the issue below in jdk9/jdk10 (current builds).
      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 not 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);
                  }
              }

      Btw I found a similar bug and addition from Coleen Phillimore.

      NPE in Flow.visitIdent

      https://bugs.openjdk.java.net/browse/JDK-7194212

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



      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)

      (same issue for JDK10)

            jlahoda Jan Lahoda
            mbaesken Matthias Baesken
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: