RFR: 8253385: annotation processors remove varargs information from record components

Jonathan Gibbons jjg at openjdk.java.net
Wed Nov 4 00:50:55 UTC 2020

On Fri, 16 Oct 2020 19:50:31 GMT, Vicente Romero <vromero at openjdk.org> wrote:

> Please review this fix for a corner case bug. Essentially for code like:
> import java.lang.annotation.*;
> @Target({ElementType.TYPE_USE})
> @interface Simple {}
> record R(@Simple int ...val) {
>     static void test() {
>         R rec = new R(10, 20);
>     }
> }
> assuming that there is an AP present, after the first annotation processing round, the record component's symbol is set to `null` and thus the flags info is lost. So once the symbols and their types are determined again after every annotation processing round, there is no recollection that the record component was a varargs. Remember that the AST for the record component declaration is not kept but it is used to extract information from it and to derive compiler generated code like fields, canonical constructor, etc. The proposed solution is to keep the information about the vararg-ness of the record component in a dedicated field in the record component so that this information can be recovered later on as needed.
> TIA,
> Vicente

minor suggestions in comments

src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java line 1788:

> 1786:         private final int pos;
> 1787: 
> 1788:         private boolean isVarargs;

field can be final?

test/langtools/tools/javac/records/RecordCompilationTests.java line 1694:

> 1692:                 @interface Simple {}
> 1693: 
> 1694:                 record R(@Simple int ...val) {

(minor) unusual typography for "int ...val". Suggest "int... val"

test/langtools/tools/javac/records/RecordCompilationTests.java line 1712:

> 1710:                 @interface Simple {}
> 1711: 
> 1712:                 record R(@Simple int ...val) {

(minor) unusual typography for "int ...val". Suggest "int... val"


Marked as reviewed by jjg (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/709

More information about the compiler-dev mailing list