RFR: 8332497: javac prints an AssertionError when annotation processing runs on program with module imports [v18]

Chen Liang liach at openjdk.org
Sat May 25 05:43:03 UTC 2024


On Sat, 25 May 2024 05:39:34 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 two additional commits since the last revision:
> 
>  - Refactored test to use TestRunner
>  - Overridden visitModuleImport in TreeTranslator

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

> 58:           @Retention(RetentionPolicy.RUNTIME)
> 59:           @Target(ElementType.METHOD)
> 60:           public @interface Ann {}

Suggestion:

            public static void main(String[] args) {
                List.of();
            }
            @Ann
            private void test() {}
            @Retention(RetentionPolicy.RUNTIME)
            @Target(ElementType.METHOD)
            public @interface Ann {}

Indentation.

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

> 71: 
> 72:     protected void runTests() throws Exception {
> 73:         runTests(m -> new Object[] { Paths.get(m.getName()) });

Suggestion:

        runTests(m -> new Object[] { Path.of(m.getName()) });

`Paths` exists because Path was added in JDK 7, before static methods were supported in interfaces in JDK 8.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/19292#discussion_r1614368340
PR Review Comment: https://git.openjdk.org/jdk/pull/19292#discussion_r1614368508


More information about the compiler-dev mailing list