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

Evemose duke at openjdk.org
Sat May 25 14:39:06 UTC 2024


On Sat, 25 May 2024 10:06:50 GMT, Vicente Romero <vromero at openjdk.org> wrote:

>>> ok this is what I would do, please feel free to use it, it is applicable on top of your current code. As you can see I have reformatted the test to align it better with the rest of similar tests in our code base. Also as Jan suggested I have added an equivalent method to TreeTranslator for completeness.
>>> 
>>> ```
>>> diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeTranslator.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeTranslator.java
>>> index 59a7457e6d0..63778fb42ff 100644
>>> --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeTranslator.java
>>> +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeTranslator.java
>>> @@ -131,6 +131,11 @@ public void visitImport(JCImport tree) {
>>>          result = tree;
>>>      }
>>>  
>>> +    public void visitModuleImport(JCModuleImport tree) {
>>> +        tree.module = translate(tree.module);
>>> +        result = tree;
>>> +    }
>>> +
>>>      public void visitClassDef(JCClassDecl tree) {
>>>          tree.mods = translate(tree.mods);
>>>          tree.typarams = translateTypeParams(tree.typarams);
>>> diff --git a/test/langtools/tools/javac/processing/ModuleImportProcessingTest.java b/test/langtools/tools/javac/processing/ModuleImportProcessingTest.java
>>> index 88c7974a26e..760ec30820e 100644
>>> --- a/test/langtools/tools/javac/processing/ModuleImportProcessingTest.java
>>> +++ b/test/langtools/tools/javac/processing/ModuleImportProcessingTest.java
>>> @@ -21,7 +21,16 @@
>>>   * questions.
>>>   */
>>>  
>>> -import toolbox.*;
>>> +/**
>>> + * @test
>>> + * @bug 8332497
>>> + * @summary javac prints an AssertionError when annotation processing runs on program with module imports
>>> + * @library /tools/lib
>>> + * @modules jdk.compiler/com.sun.tools.javac.api
>>> + *          jdk.compiler/com.sun.tools.javac.main
>>> + * @build toolbox.JavacTask toolbox.ToolBox toolbox.Task
>>> + * @run main ModuleImportProcessingTest
>>> + */
>>>  
>>>  import javax.annotation.processing.AbstractProcessor;
>>>  import javax.annotation.processing.RoundEnvironment;
>>> @@ -32,40 +41,49 @@
>>>  import java.nio.file.Paths;
>>>  import java.util.Set;
>>>  
>>> -/**
>>> - * @test
>>> - * @bug 8332497
>>> - * @summary error: javac prints an AssertionError when annotation processing runs on program with module imports
>>> - * @library /tools/lib
>>> - * @modules jdk.compiler/com.sun.tools.javac.api
>>> - *          jdk.compiler/com.sun.tools.javac.main
>>> - * @build toolbox.JavacTask toolbox.ToolBox ...
>
>> > ok this is what I would do, please feel free to use it, it is applicable on top of your current code. As you can see I have reformatted the test to align it better with the rest of similar tests in our code base. Also as Jan suggested I have added an equivalent method to TreeTranslator for completeness.
>> > ```
>> > diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeTranslator.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeTranslator.java
>> > index 59a7457e6d0..63778fb42ff 100644
>> > --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeTranslator.java
>> > +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeTranslator.java
>> > @@ -131,6 +131,11 @@ public void visitImport(JCImport tree) {
>> >          result = tree;
>> >      }
>> >  
>> > +    public void visitModuleImport(JCModuleImport tree) {
>> > +        tree.module = translate(tree.module);
>> > +        result = tree;
>> > +    }
>> > +
>> >      public void visitClassDef(JCClassDecl tree) {
>> >          tree.mods = translate(tree.mods);
>> >          tree.typarams = translateTypeParams(tree.typarams);
>> > diff --git a/test/langtools/tools/javac/processing/ModuleImportProcessingTest.java b/test/langtools/tools/javac/processing/ModuleImportProcessingTest.java
>> > index 88c7974a26e..760ec30820e 100644
>> > --- a/test/langtools/tools/javac/processing/ModuleImportProcessingTest.java
>> > +++ b/test/langtools/tools/javac/processing/ModuleImportProcessingTest.java
>> > @@ -21,7 +21,16 @@
>> >   * questions.
>> >   */
>> >  
>> > -import toolbox.*;
>> > +/**
>> > + * @test
>> > + * @bug 8332497
>> > + * @summary javac prints an AssertionError when annotation processing runs on program with module imports
>> > + * @library /tools/lib
>> > + * @modules jdk.compiler/com.sun.tools.javac.api
>> > + *          jdk.compiler/com.sun.tools.javac.main
>> > + * @build toolbox.JavacTask toolbox.ToolBox toolbox.Task
>> > + * @run main ModuleImportProcessingTest
>> > + */
>> >  
>> >  import javax.annotation.processing.AbstractProcessor;
>> >  import javax.annotation.processing.RoundEnvironment;
>> > @@ -32,40 +41,49 @@
>> >  import java.nio.file.Paths;
>> >  import java.util.Set;
>> >  
>> > -/**
>> > - * @test
>> > - * @bug 8332497
>> > - * @summary error: javac prints an AssertionError when annotation processing runs on program with module imports
>> > - * @library /tools/lib
>> > - * @modules jdk.compiler/com.sun.tools.javac.api
>> > - *          jdk.compiler/com.sun.tools.javac.main
>>...

@vicente-romero-oracle could you sponsor please?

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

PR Comment: https://git.openjdk.org/jdk/pull/19292#issuecomment-2131297450


More information about the compiler-dev mailing list