RFR: 8332497: javac crashes when annotation processing runs on program with module imports [v9]

Chen Liang liach at openjdk.org
Wed May 22 13:54:05 UTC 2024


On Wed, 22 May 2024 13:31:32 GMT, Evemose <duke at openjdk.org> wrote:

>> Fix is pretty simple: visitModuleImport in com.sun.tools.javac.tree.TreeScanner has notbeen overriden, so defaulted to Visitor::visitModuleImport, which forwards to Visitor::visitTree, which is also not overriden, and, therefore, threw AssertionError. 
>> 
>> PS: Im not even sure how it worked before without crashing, seems like there is some intermidiate implementation between this TreeScanner and actual scanners because otherwise it should have resultedin compile error the moment it encounter module importin any visitor
>
> Evemose has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Added --enable-preview flag

Changes requested by liach (Author).

test/langtools/tools/javac/processing/ModuleImportProcessingTest.java line 36:

> 34:  * @modules jdk.compiler
> 35:  * @build JavacTestingAbstractProcessor ModuleImportProcessingTest
> 36:  * @compile/process --enable-preview --release 23 -processor ModuleImportProcessingTest ModuleImportProcessingTest.java

You should use an `@enablePreview` tag if the building of other classes doesn't have a source version restriction.

In the worst scenario, if you have a version restriction (say testing behavior for `--release 14`), you can use `--enable-preview --source ${jdk.version}`.

There are 2 problems with your command line here:
1. `--release` will fail because you are specifying modules (see https://bugs.openjdk.org/browse/CODETOOLS-7902754)
2. `23` will break when JDK bumps version

As a result, I recommend just using a `@enablePreview` tag.

-------------

PR Review: https://git.openjdk.org/jdk/pull/19292#pullrequestreview-2071283892
PR Review Comment: https://git.openjdk.org/jdk/pull/19292#discussion_r1610003637


More information about the compiler-dev mailing list