This discussion is archived
4 Replies Latest reply: Jan 10, 2011 5:17 AM by JoachimSauer RSS

Error during creation of resource file beginning with "."

828882 Newbie
Currently Being Moderated
Hi all,

I have a problem with AP. I try to generate a resource file with the name starting with "." symbol, e.g. "*.example.txt*". The problem is that DefaultFileManager throws an exception saying "*relativeName is invalid*":
java.lang.IllegalArgumentException: relativeName is invalid
     at com.sun.tools.javac.util.DefaultFileManager.getFileForOutput(DefaultFileManager.java:1050)
     at com.sun.tools.javac.processing.JavacFiler.createResource(JavacFiler.java:404)
Is there any workaround to create resource files starting with dot?

Thanks,
Tomek
  • 1. Re: Error during creation of resource file beginning with "."
    sabre150 Expert
    Currently Being Moderated
    Are you sure the problem is caused by the '.' ? Are you trying to write the file into a jar file? If not, can you create an SSCCE (http://pscode.org/sscce.html) that illustrates the problem.
  • 2. Re: Error during creation of resource file beginning with "."
    828882 Newbie
    Currently Being Moderated
    Hi Sabre,

    Thanks for you reply, I actually found the workaround today, but I also found a situation where workaround cannot be applied. See following code:
    // Following throws an exception
    processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "foo", ".example.txt", null);
    
    // Workaround is to put the package/folder as part of the filename.
    // Or maybe it is not a workaround, but the preferred way of resource creation?
    processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", "foo/.example.txt", null);
    
    // But what about creating resources in root output directory ? - it always throws an exception
    processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", ".example.txt", null);
    The problems appears when filename starts with ".". In other case, all the examples would work.

    Cheers,
    Tomek

    Edited by: fibon on 2011-01-06 20:42

    Edited by: fibon on 2011-01-06 20:43

    Edited by: fibon on 2011-01-06 21:23
  • 3. Re: Error during creation of resource file beginning with "."
    sabre150 Expert
    Currently Being Moderated
    fibon wrote:
    The problems appears when filename starts with ".". In other case, all the examples would work.
    I'm not convinced that this is not a bug in your code but your code fragment is too small and without an SSCCE I can't really comment any further.
  • 4. Re: Error during creation of resource file beginning with "."
    JoachimSauer Journeyer
    Currently Being Moderated
    If there is indeed buggy code involved (for example code that tries to detect the presence of relative paths with directory names by only checking for a leading "."), then you might be able to work around the issue by using the filename "./.example.txt".

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points