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

JSR 199: In the method JavaCompilerTool.getTask 'options' can be supplied in the place of 'classes'

    Details

    • Subcomponent:
    • Resolved In Build:
      b91
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      In the method JavaCompilerTool.getTask() 'options' can be supplied in the place of 'classes' and still JavaCompilerTool will work fine.
      Please see the code:
      <code>
      import java.io.File;
      import java.util.ArrayList;
      import java.util.Arrays;
      import java.util.List;
      import javax.tools.*;

      import static javax.tools.StandardJavaFileManager.StandardLocation.*;
      import static javax.tools.JavaFileObject.Kind.*;

      public class Foo1 {
           private void test(String... args) throws Throwable {
              JavaCompilerTool javac = ToolProvider.getSystemJavaCompilerTool();
              DiagnosticListener<? super javax.tools.JavaFileObject> dl =
                          new DiagnosticListener<javax.tools.JavaFileObject>() {
                  public void report(Diagnostic message) {
                      System.out.print("\nFile Name : "+new File(
                              message.getSource().toString()).getName());
                      System.out.print("\nProblem Found : "+message.getKind());
                      System.out.print("\nLine Number : "+message.getLineNumber());
                      System.out.print("\nMessage : "+message.toString());
                      System.out.println("\nCode : "+message.getCode());
                  }
              };
              JavaFileManager jfm = javac.getStandardFileManager(null);
              JavaFileObject jfo = jfm.getJavaFileForInput(CLASS_PATH,args[0],SOURCE);
              StandardJavaFileManager sjfm = javac.getStandardFileManager(dl);
              Iterable<? extends JavaFileObject> iteJFO = sjfm.getJavaFileObjectsFromFiles(
                                                     Arrays.asList(new File(args[0])));
              List<String> options = new ArrayList<String>();
              options.add("-Xlint");
              JavaCompilerTool.CompilationTask task =
                      javac.getTask(null,sjfm,dl,null,options,iteJFO);
              task.run();
          }
          public static void main(String... arg) throws Throwable {
              try{
                  List<Integer> list = new ArrayList();
                  Foo1 test = new Foo1();
                  test.test("Foo1.java");
              } catch(Exception ex) {
                      ex.printStackTrace();
                      System.exit(1);
              }
          }
      }
      </code>
      In the above code I am passsing options in the place of classes, still it works fine instead of throwing exception.
      <output>
      bash-3.00$ java Foo1

      File Name : Foo1.java
      Problem Found : MANDATORY_WARNING
      Line Number : 37
      Message : Foo1.java:37: warning: [unchecked] unchecked conversion
      found : java.util.ArrayList
      required: java.util.List<java.lang.Integer>
      Code : compiler.warn.prob.found.req
      </output>
      JavaCompilerTool successfully expanded -Xlint though it is given in the place of classes.

      <java-version>
      bash-3.00$ java -version
      java version "1.6.0-beta2"
      Java(TM) SE Runtime Environment (build 1.6.0-beta2-b82)
      Java HotSpot(TM) Client VM (build 1.6.0-beta2-b82, mixed mode)
      </java-version>

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: