Filer.getResource() always throws FileNotFoundException
James Perkins
jperkins at redhat.com
Mon Jun 20 17:24:24 PDT 2011
The implementation of javax.annotation.processing.Filer
(com.sun.tools.javac.processing.JavacFiler.java) always throws a
FileNotFoundException when invoking getResource(). This appears to be a
bug introduced in commit
http://hg.openjdk.java.net/jdk7/jdk7/langtools/diff/f3323b1c65ee/src/share/classes/com/sun/tools/javac/processing/JavacFiler.java.
The method should be using JavaFileManager.getFileForOutput() not
JavaFileManager.getFileForInput().
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)
checkName(strPkg);
// 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
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7057153. 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