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

JavaCompilerTool.run(null) method should throw NullPointerException for null arguments

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Cannot Reproduce
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: tools
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      Please see the following code

      Case 1:

      <code>
      import java.io.Writer;
      import javax.tools.*;
      import javax.tools.JavaFileObject.Kind;
       
      public class CompileFromString {
          public static void main(String... args) throws Exception {
              JavaCompilerTool compiler = ToolProvider.defaultJavaCompiler();
              compiler.setOption("-Xlint");
              compiler.run((Writer)null, (JavaFileObject)null);
          }
      }

      </code>

      Output when executed it throws Null pointer but with the following details.

      <output>
      bash-2.05$ java CompileFromString
      An exception has occurred in the compiler (1.6.0-internal). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
      java.lang.NullPointerException
              at com.sun.tools.javac.main.JavaCompiler.readSource(JavaCompiler.java:289)
              at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:341)
              at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:476)
              at com.sun.tools.javac.main.Main.compile(Main.java:662)
              at com.sun.tools.javac.Tool.run(Tool.java:106)
              at CompileFromString.main(CompileFromString.java:125)
      bash-2.05$
      </output>

      Case 2:

      When setOption() is removed then compiler throws different output. Please check the following code.

      <code>
      import java.io.Writer;
      import javax.tools.*;
      import javax.tools.JavaFileObject.Kind;
       
       
      public class CompileFromString {
          public static void main(String... args) throws Exception {
              JavaCompilerTool compiler = ToolProvider.defaultJavaCompiler();
              //compiler.setOption("-Xlint");
              compiler.run((Writer)null, (JavaFileObject)null);
          }
      }
      </code>

      Output of the code when executed.

      <Output>
      bash-2.05$ java CompileFromString
      Usage: javac <options> <source files>
      where possible options include:
        -g Generate all debugging info
        -g:none Generate no debugging info
        -g:{lines,vars,source} Generate only some debugging info
        -nowarn Generate no warnings
        -verbose Output messages about what the compiler is doing
        -deprecation Output source locations where deprecated APIs are u
      sed
        -classpath <path> Specify where to find user class files
        -cp <path> Specify where to find user class files
        -sourcepath <path> Specify where to find input source files
        -bootclasspath <path> Override location of bootstrap class files
        -extdirs <dirs> Override location of installed extensions
        -endorseddirs <dirs> Override location of endorsed standards path
        -d <directory> Specify where to place generated class files
        -encoding <encoding> Specify character encoding used by source files
        -source <release> Provide source compatibility with specified release
        -target <release> Generate class files for specific VM version
        -version Version information
        -help Print a synopsis of standard options
        -X Print a synopsis of nonstandard options
        -J<flag> Pass <flag> directly to the runtime system

      </Output>


      ###@###.### 2005-06-24 18:42:26 GMT
      ###@###.### 2005-06-25 02:28:04 GMT

        Attachments

          Activity

            People

            Assignee:
            jjg Jonathan Gibbons
            Reporter:
            savadhansunw Seetharama Avadhanam (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: