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

If no -s<dir> options is given, createTextFile uses root, "/",under which to create file

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P3 P3
    • 6
    • 6
    • core-libs

      Filer.createTextFile(Location,pkg,File,charsetname) appends File to root, '/', is no -s dir options was used to launch processor and Location given is SOURCE_TREE.
      Copy below source to testAP.java, compile and run.
      javac testAP.java
      javac -proc:only -processor testAP testAP.java

      % cat testAP.java
      import javax.annotation.processing.*;
      import javax.lang.model.element.*;
      import java.util.Set;
      import java.util.Vector;
      import java.io.PrintWriter;
      import java.io.File;
      import static javax.tools.Diagnostic.Kind.*;
      import static javax.annotation.processing.Filer.Location.*;

      @SupportedSourceVersion(javax.lang.model.SourceVersion.RELEASE_6)
      @SupportedAnnotationTypes({"*"})
      public class testAP extends AbstractProcessor
      {
         public static Messager msgr = null;
      public static java.io.Writer FW = null;
      Filer _filer = null;
      File _reportFile = null;
      String myfile = "./report.html";

         public static String javaFile = null;

      public testAP() { }

         @Override
      public void init(ProcessingEnvironment penv) {
      processingEnv = penv;
      msgr = penv.getMessager();
      _filer = penv.getFiler();
      try { _reportFile = new java.io.File(myfile);}
      catch(Exception e1) {
      System.out.println("Exception trying to create File for " + myfile);
      }finally {
      try{System.out.println("File Name: " + _reportFile.getCanonicalPath() );}
      catch(java.io.IOException ioe){ ioe.printStackTrace(); }
      }

      try {
      // FW = _filer.createTextFile(CLASS_TREE,"", _reportFile ,null);
      FW = _filer.createTextFile(SOURCE_TREE,"", _reportFile ,null);
      }
      catch(FilerException fe) {
      System.out.println(fe.toString());
      }
      catch(Exception some_other_excep) {
      msgr.printMessage(ERROR, some_other_excep.toString());
      some_other_excep.printStackTrace();
      }
      }

         public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv)
      {
      return true;
          }
      }

            darcy Joe Darcy
            ssides Steve Sides
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: