[PATCH] JDK-8235458: Problem caused by imports in a module-info.java file
Jeremy Kuhn
jeremy.kuhn.java at gmail.com
Fri Dec 6 23:53:20 UTC 2019
Hi,
Following previous discussions please find enclosed a patch for the issue
referenced in JDK-8235458.
When the compiler initiates the annotation processing environment it scans
all compilation units to discover whether there are some with annotations
to process and create the first round of annotation processing. This is
done in the JavacProcessingEnvironment (line 1090 in the Round
constructor), module info files are filtered within the
getModuleInfoFiles() method (line 1515) but this method currently assumes a
module info files always starts with a module declaration even though
import statements can be present first according to the Java language
specification as a result an annotated module with import statements is
ignored during annotation processing.
In order to fix the issue, I've had to loop over the unit defs to ignore
any import statements until I found either a module tag in which case I can
include the module in the list of modules info files to process or any
other tag in which case I ignore the unit which is not a module.
You'll find a jtreg test in the patch as well, I've actually created three
modules for the test:
- annotation: which defines a simple module annotation
- processor: which provides the annotation processor reporting a message on
the annotated module
- mod: which contains a module annotated with the previous annotation with
import statements
The test is successful when the it runs without errors and the annotation
is properly processed by the compiler.
I didn't find a way to use jtreg tags to compile modules, so I've decided
to compile everything programmatically in the test main() method.
Please let me know if I can be of any further assistance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20191207/fc636be2/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 8235458.patch
Type: text/x-patch
Size: 8199 bytes
Desc: not available
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20191207/fc636be2/8235458-0001.patch>
More information about the compiler-dev
mailing list