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

NPE from Filer.getResource when sourcepath is not explicitly set

    Details

    • Type: Bug
    • Status: Open
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: core-libs

      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)
      ...

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                darcy Joe Darcy
                Reporter:
                darcy Joe Darcy
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Imported:
                  Indexed: