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

JSR 199: Diagnostic.getSource() returns null for notes

XMLWordPrintable

    • b06
    • generic
    • generic
    • Verified

      Tried in Solaris10
      <JDK-version>
      java version "1.6.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-beta-b59)
      Java HotSpot(TM) Client VM (build 1.6.0-beta-b59, mixed mode)
      </JDK-version>
      Please see the code
      <code>
      import java.io.PrintWriter;
      import javax.tools.*;

      public class Test7 {
          public static void main(String... arg) throws Exception {
              JavaCompilerTool javac = ToolProvider.defaultJavaCompiler();
              JavaFileManager jfm = javac.getStandardFileManager();
              JavaFileObject jfo = jfm.getFileForInput("Test8.java");
              for(DiagnosticMessage message :
                      javac.run((PrintWriter)null, jfo).getDiagnostics()) {
                   System.out.println("Message.getSource :" + message.getSource());
                   System.out.println("Message.toString :" + message.toString());
             }
          }
      }
      </code>
      The compile source for the above code
      <code>
      import java.util.ArrayList;
      import java.util.List;
      public class Test8 {
          public static void main(String[] args) {
              List<String> list = new ArrayList();
          }
      }
      </code>

      To reproduce the problem, Keep Test7 and Test8 in the same directory.
      Note: Test7.java will compile Test8.java.
      Test8 will throw NOTE. When the output is NOTE then DiagnosticMessage will give null for getSource. See the output
      <output>
      bash-3.00$ javac Test7.java
      bash-3.00$ java Test7
      Message.getSource :null
      Message.toString :Note: Test8.java uses unchecked or unsafe operations.
      Message.getSource :null
      Message.toString :Note: Recompile with -Xlint:unchecked for details.
      bash-3.00$
      </output>

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: