Skip to content

Annotation processor's Filer can't read the files being compiled #189

@ghost

Description

I have a code in my annotation processor and it works fine when I compile sources using this annotation processor (with Maven, for example).
Simplified version of code looks like this:

try {
    FileObject fileObject = filer.getResource(StandardLocation.SOURCE_PATH, "org.example", "MyMapper.java");
    String content = fileObject.getCharContent(false).toString();
} catch (IOException e) {
    // ...
}

When I try to test my code using compile-testing, it fails on the first line with error:

java.io.FileNotFoundException: org.example/MyMapper.java

If I change the location from StandardLocation.SOURCE_PATH to StandardLocation.SOURCE_OUTPUT), then Filer will successfully return FileObject in the first line, but then the code will fail in the second line, where I try to read the contents of FileObject:

java.io.FileNotFoundException

FileNotFound without any message.

I have a small repro in this branch - https://github.com/jbreathe/corgi/tree/ct-issue.
You can find test itself here.
And class where Filer used here (getFileObject and readAllLines methods).

Version of Java is 14.

Maybe the second one is a known issue?
And about the first one - can I read FileObject using StandardLocation.SOURCE_PATH?

UPD: to be more clear - I'm trying to read a file that is passed to "Compiler#compile". See test for more details.

Metadata

Metadata

Assignees

Labels

P2type=defectBug, not working as expected

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions