Filer.getResource() always throws FileNotFoundException

James Perkins jperkins at
Mon Jun 20 17:24:24 PDT 2011

The implementation of javax.annotation.processing.Filer 
( always throws a 
FileNotFoundException when invoking getResource(). This appears to be a 
bug introduced in commit  
The method should be using JavaFileManager.getFileForOutput() not 

My testing with the following change works:

     public FileObject getResource(JavaFileManager.Location location,
                                   CharSequence pkg,
                                   CharSequence relativeName) throws 
IOException {
         String strPkg = pkg.toString();
         if (strPkg.length() > 0)

         // TODO: Only support reading resources in selected output
         // locations?  Only allow reading of non-source, non-class
         // files from the supported input locations?
         FileObject fileObject = fileManager.getFileForOutput(location, 
pkg.toString(), relativeName.toString(), null);
         if (fileObject == null) {
             String name = (pkg.length() == 0)
                     ? relativeName.toString() : (pkg + "/" + relativeName);
             throw new FileNotFoundException(name);

         // If the path was already opened for writing, throw an exception.
         checkFileReopening(fileObject, false);
         return new FilerInputFileObject(fileObject);

I have filed an issue for this already Not sure 
what I did wrong, but the bugs not showing up for me yet.

James R. Perkins
JBoss by Red Hat

More information about the compiler-dev mailing list