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

setOption() and setExtendedOption() of JavacTool will throw exception for some defined options

XMLWordPrintable

    • b47
    • generic
    • generic
    • Verified

      setOption() and setExtendedOption() of JavacTool will throw exception for some defined options.

      Please see the testcase :
      <code>
      import java.io.*;
      import javax.tools.*;

      public class Test10 {
          public static void test (String... args) {
              JavacTool javac = com.sun.tools.javac.Tool.create();
              javac.setOption("-target","1.5");
              DiagnosticListener dl = new DiagnosticListener() {
                      public void problemFound (DiagnosticMessage message) {
                          System.out.println (
                                  new File(message.getSourceName().toString()).getName()
                                  +":"+message.getStartPosition()+":"
                                  +message.getStartPosition()+":"+message.getPosition());
                          System.out.println(message.toString());
                          System.out.format("Found problem: %s%n", message.getKey());
                          System.out.flush();
                      }
              };
              PrintWriter writer = null;
              javac.run ( (InputLocator) null, null, dl, writer, args);
          }
          public static void main (String... arg) {
              Test10 test = new Test10();
              test.test("/home/sa151881/javatrails/SWarnings/unchecked/Test26.java");
          }
      }
      </code>

      <output>
      An exception has occurred in the compiler ($(RELEASE)). 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.util.Diagnostic.getSourceName(Diagnostic.java:383)
              at com.sun.tools.javac.util.Diagnostic.getSourceName(Diagnostic.java:25)
              at Test10$1.problemFound(Test10.java:10)
              at com.sun.tools.javac.util.Log.writeDiagnostic(Log.java:430)
              at com.sun.tools.javac.util.Log.report(Log.java:398)
              at com.sun.tools.javac.util.Log.mandatoryNote(Log.java:380)
              at com.sun.tools.javac.util.MandatoryWarningHandler.reportDeferredDiagnostic(MandatoryWarningHandler.java:149)
              at com.sun.tools.javac.comp.Check.reportDeferredDiagnostics(Check.java:161)
              at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:556)
              at com.sun.tools.javac.main.Main.compile(Main.java:648)
              at com.sun.tools.javac.Tool.run(Tool.java:95)
              at Test10.test(Test10.java:20)
              at Test10.main(Test10.java:24)

      </output>

      The same output will come for the following options
             javac.setOption("-d","/home/sa151881/javatrails/SWarnings/unchecked/");
             javac.setOption("-verbose");
      // First it give the output but at the end it gives the same output
             javac.setOption("-cp","/home/sa151881/javatrails/SWarnings/unchecked");
             javac.setOption("-classpath","/home/sa151881/javatrails/SWarnings/unchecked");
             javac.setOption("-encoding","UTF-8");
             javac.setOption("-target","1.5");
             javac.setOption("-sourcepath",".");
             javac.setOption("-Xstdout","out.txt");
             //Creates the out put file the same exception
             javac.setOption("-endorseddirs", "/home");
             javac.setOption("-source", "1.5");
             javac.setOption("-help");
             //First displays the help and then the same output
             javac.setOption("-X");
             //First displays -X options and then the same output

      setOption will throw NullPointerException when the following options are used
      javac.setOption("-bootclasspath","");
              javac.setOption("extdirs",";");
              javac.setOption("-J-Xms48m");

      ###@###.### 2005-05-04 09:07:44 GMT

            ahe Peter Ahe
            savadhansunw Seetharama Avadhanam (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: