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

JSR 199: StandardJavaFileManager.setLocation: exception not documented

    Details

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

      Description

      Throws needs to be added for StandardJavaFileManager.setLocation() API.
      setLocation will throw IllegalArgumentException when the list contains files for the locations, which only supports directories like SOURCE_OUTPUT.

      Please see the testcase :
      <testcase>
      import java.io.File;
      import java.util.Arrays;
      import java.util.List;
      import javax.tools.JavaCompilerTool;
      import javax.tools.StandardJavaFileManager;
      import javax.tools.StandardLocation;
      import javax.tools.ToolProvider;

      public class Foo {
          public static void main(String[] args) throws Exception {
              JavaCompilerTool jct = ToolProvider.getSystemJavaCompilerTool();
              StandardJavaFileManager sjfm = jct.getStandardFileManager(null);
              File file = new File("sjfmTemp.java");
              file.createNewFile();
              List<File> newFiles = Arrays.asList(file);
              StandardLocation s1 = StandardLocation.valueOf("CLASS_OUTPUT");
              StandardLocation s2 = StandardLocation.valueOf("SOURCE_OUTPUT");
              try {
                      sjfm.setLocation(s1, newFiles);
              } catch(IllegalArgumentException ex){
                  System.out.println(ex.getMessage());
              }
              try {
                      sjfm.setLocation(s2, newFiles);
          } catch(IllegalArgumentException ex){
                  System.out.println(ex.getMessage());
              }
              file.deleteOnExit();
          }
          
      }
      </testcase>

      When trying to add files for CLASS_OUTPUT and SOURCE_OUTPUT, compiler will throw IllegalArgumentException as expected. I think same needs to added in the spec.
      Pared down test case:

      import java.io.File;
      import java.util.*;
      import javax.tools.*;

      public class Test {

          public static void main(String[] args) throws Exception {
              JavaCompilerTool jct = ToolProvider.getSystemJavaCompilerTool();
              StandardJavaFileManager sjfm = jct.getStandardFileManager(null);
              List<File> newFiles = Arrays.asList(new File("Test.java"));
      sjfm.setLocation(StandardLocation.CLASS_OUTPUT, newFiles);
      sjfm.setLocation(StandardLocation.SOURCE_OUTPUT, newFiles);
          }

      }

        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: