United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 6647998 NPE from Filer.getResource when sourcepath is not explicitly set
6647998 : NPE from Filer.getResource when sourcepath is not explicitly set

Details
Type:
Bug
Submit Date:
2008-01-08
Status:
Open
Updated Date:
2011-04-14
Project Name:
JDK
Resolved Date:
Component:
core-libs
OS:
generic
Sub-Component:
javax.annotation.processing
CPU:
generic
Priority:
P3
Resolution:
Unresolved
Affected Versions:
6
Targeted Versions:
8

Related Reports
Relates:
Relates:

Sub Tasks

Description
It has been reported that Filer.getResource will throw an NPE if sourcepath is not set explicitly:

http://forum.java.sun.com/thread.jspa?threadID=5240996

In my annotation processor, I wanted to locate a file in source path, so I wrote the following code:
FileObject fo = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, "", "META-INF/persistence.xml");

It throws NullPointerException if I do *not* specify -sourcepath option while invoking javac. I have two questions:

1) Is "." not the default value for source search path?

2) Instead of throwing an IOException as per the javadocs of getResource, why is it throwing an NPE?

The stack trace is:
java.lang.NullPointerException
at com.sun.tools.javac.util.DefaultFileManager.getFileForOutput(DefaultFileManager.java:974)
at com.sun.tools.javac.util.DefaultFileManager.getFileForOutput(DefaultFileManager.java:950)
at com.sun.tools.javac.processing.JavacFiler.getResource(JavacFiler.java:434)
at foo.Ap.readDD(Ap.java:182)
at foo.Ap.init(Ap.java:101)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$ProcessorState.(JavacProcessingEnvironment.java:339)
...

                                    

Comments
EVALUATION

To answer point (1) in the description, no, "." is not a default value for the source path.
                                     
2011-01-08
EVALUATION

Will investigate.
                                     
2008-01-08



Hardware and Software, Engineered to Work Together