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

Method com.sun.tools.javac.file.Locations.getPathEntries throws java.lang.NullPointerException when using JDK 8 tools.jar with JDK 9

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      FULL PRODUCT VERSION :
      java version "9.0.1"
      Java(TM) SE Runtime Environment (build 9.0.1+11)
      Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 10.0.15063]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Since JDK 9 the com.sun.tools.javac.main.Main compilation is deprecated
      https://docs.oracle.com/javase/9/docs/api/jdk.compiler-summary.html

      So, the used tools.jar file is taken from the JDK 8 folder.
      C:\Program Files\Java\jdk1.8.0_162

      A DESCRIPTION OF THE PROBLEM :
      Method com.sun.tools.javac.file.Locations.getPathEntries throws java.lang.NullPointerException when using JDK 8 tools.jar with JDK 9

      The command line is:

      java -DcompileTarget=1.8 -classpath "C:\Program Files\Java\jdk1.8.0_162\lib\tools.jar;force-wsc-41.0.0-uber.jar" com.sforce.ws.tools.wsdlc enterprise.wsdl.xml "C:\project\target\enterprise.jar"

      The output is:

      [WSC][wsdlc.main:71]Generating Java files from schema ...
      [WSC][wsdlc.main:71]Generated 707 java files.
      [WSC][wsdlc.main:71]Compiling to target 1.8...
      An exception has occurred in the compiler (1.8.0_162-ea). 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 com.sun.tools.javac.file.Locations.getPathEntries(Locations.java:149)
              at com.sun.tools.javac.file.Locations.getPathEntries(Locations.java:134)
              at com.sun.tools.javac.file.Locations.access$000(Locations.java:71)
              at com.sun.tools.javac.file.Locations$BootClassPathLocationHandler.computePath(Locations.java:617)
              at com.sun.tools.javac.file.Locations$BootClassPathLocationHandler.lazy(Locations.java:643)
              at com.sun.tools.javac.file.Locations$BootClassPathLocationHandler.getLocation(Locations.java:577)
              at com.sun.tools.javac.file.Locations.getLocation(Locations.java:678)
              at com.sun.tools.javac.file.JavacFileManager.getLocation(JavacFileManager.java:803)
              at com.sun.tools.javac.file.JavacFileManager.list(JavacFileManager.java:617)
              at com.sun.tools.javac.jvm.ClassReader.fillIn(ClassReader.java:2750)
              at com.sun.tools.javac.jvm.ClassReader.complete(ClassReader.java:2446)
              at com.sun.tools.javac.jvm.ClassReader.access$000(ClassReader.java:76)
              at com.sun.tools.javac.jvm.ClassReader$1.complete(ClassReader.java:240)
              at com.sun.tools.javac.code.Symbol.complete(Symbol.java:574)
              at com.sun.tools.javac.comp.Enter.visitTopLevel(Enter.java:300)
              at com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:518)
              at com.sun.tools.javac.comp.Enter.classEnter(Enter.java:258)
              at com.sun.tools.javac.comp.Enter.classEnter(Enter.java:272)
              at com.sun.tools.javac.comp.Enter.complete(Enter.java:486)
              at com.sun.tools.javac.comp.Enter.main(Enter.java:471)
              at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:982)
              at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:857)
              at com.sun.tools.javac.main.Main.compile(Main.java:523)
              at com.sun.tools.javac.main.Main.compile(Main.java:381)
              at com.sun.tools.javac.main.Main.compile(Main.java:370)
              at com.sun.tools.javac.main.Main.compile(Main.java:361)
              at com.sun.tools.javac.Main.compile(Main.java:56)
              at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
              at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
              at java.base/java.lang.reflect.Method.invoke(Unknown Source)
              at com.sforce.ws.codegen.Compiler.compile(Compiler.java:107)
              at com.sforce.ws.codegen.Generator.compileTypes(Generator.java:141)
              at com.sforce.ws.tools.wsdlc.run(wsdlc.java:117)
              at com.sforce.ws.tools.wsdlc.run(wsdlc.java:149)
              at com.sforce.ws.tools.wsdlc.main(wsdlc.java:71)
      Error: Failed to compile

      Even though using the jar file from previous JDK might seem weird, the thrown NullPointerException shows that come cases are not implemented in the Locations.getPathEntries method, introduced with JDK 9 and newer.

      REGRESSION. Last worked in version 8u162

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.8.0_162-ea"
      Java(TM) SE Runtime Environment (build 1.8.0_162-ea-b01)
      Java HotSpot(TM) 64-Bit Server VM (build 25.162-b01, mixed mode)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Install JDK 1.8.0_162

      2. Install JDK 9.0.1

      3. Optionally generate and save the Salesforce Enterprise WSDL file into enterprise.wsdl.xml

      4. Download and store file http://central.maven.org/maven2/com/force/api/force-wsc/41.0.0/force-wsc-41.0.0-uber.jar

      5. Call the command line:
      java -DcompileTarget=1.8 -classpath "C:\Program Files\Java\jdk1.8.0_162\lib\tools.jar;force-wsc-41.0.0-uber.jar" com.sforce.ws.tools.wsdlc enterprise.wsdl.xml "C:\project\target\enterprise.jar"

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expected successful generation like in JDK 8 or a detailed typed exception explaining the reason why exactly it was thrown.
      ACTUAL -
      Method com.sun.tools.javac.file.Locations.getPathEntries throws unexpected NullPointerException without any message in it.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      An exception has occurred in the compiler (1.8.0_162-ea). 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 com.sun.tools.javac.file.Locations.getPathEntries(Locations.java:149)
              at com.sun.tools.javac.file.Locations.getPathEntries(Locations.java:134)
              at com.sun.tools.javac.file.Locations.access$000(Locations.java:71)
              at com.sun.tools.javac.file.Locations$BootClassPathLocationHandler.computePath(Locations.java:617)
              at com.sun.tools.javac.file.Locations$BootClassPathLocationHandler.lazy(Locations.java:643)
              at com.sun.tools.javac.file.Locations$BootClassPathLocationHandler.getLocation(Locations.java:577)
              at com.sun.tools.javac.file.Locations.getLocation(Locations.java:678)
              at com.sun.tools.javac.file.JavacFileManager.getLocation(JavacFileManager.java:803)
              at com.sun.tools.javac.file.JavacFileManager.list(JavacFileManager.java:617)
              at com.sun.tools.javac.jvm.ClassReader.fillIn(ClassReader.java:2750)
              at com.sun.tools.javac.jvm.ClassReader.complete(ClassReader.java:2446)
              at com.sun.tools.javac.jvm.ClassReader.access$000(ClassReader.java:76)
              at com.sun.tools.javac.jvm.ClassReader$1.complete(ClassReader.java:240)
              at com.sun.tools.javac.code.Symbol.complete(Symbol.java:574)
              at com.sun.tools.javac.comp.Enter.visitTopLevel(Enter.java:300)
              at com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:518)
              at com.sun.tools.javac.comp.Enter.classEnter(Enter.java:258)
              at com.sun.tools.javac.comp.Enter.classEnter(Enter.java:272)
              at com.sun.tools.javac.comp.Enter.complete(Enter.java:486)
              at com.sun.tools.javac.comp.Enter.main(Enter.java:471)
              at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:982)
              at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:857)
              at com.sun.tools.javac.main.Main.compile(Main.java:523)
              at com.sun.tools.javac.main.Main.compile(Main.java:381)
              at com.sun.tools.javac.main.Main.compile(Main.java:370)
              at com.sun.tools.javac.main.Main.compile(Main.java:361)
              at com.sun.tools.javac.Main.compile(Main.java:56)
              at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
              at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
              at java.base/java.lang.reflect.Method.invoke(Unknown Source)
              at com.sforce.ws.codegen.Compiler.compile(Compiler.java:107)
              at com.sforce.ws.codegen.Generator.compileTypes(Generator.java:141)
              at com.sforce.ws.tools.wsdlc.run(wsdlc.java:117)
              at com.sforce.ws.tools.wsdlc.run(wsdlc.java:149)
              at com.sforce.ws.tools.wsdlc.main(wsdlc.java:71)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      https://github.com/forcedotcom/wsc/blob/master/src/main/java/com/sforce/ws/codegen/Compiler.java

          @SuppressWarnings("unchecked")
          private void findCompiler(ClassLoader loader)
                  throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException {

              Class c = loader.loadClass("com.sun.tools.javac.Main");
              Class arg = (new String[0]).getClass();
              main = c.newInstance();
              method = c.getMethod("compile", arg);
          }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      The workaround is to fall back to JDK 8 while Salesforce WSC (Web Service Connector) Compiler does not support a proper compilation method.
      https://github.com/forcedotcom/wsc/blob/master/src/main/java/com/sforce/ws/codegen/Compiler.java

      SUPPORT :
      YES

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: