From 97a81cee252ab35e8c8e0beb60cc3e6d1e2cebde Mon Sep 17 00:00:00 2001
From: Vicente Romero <vromero@openjdk.org>
Date: Wed, 4 Nov 2020 23:30:41 +0000
Subject: [PATCH] 8253385: annotation processors remove varargs information
 from record components

Reviewed-by: jjg
---
 .../com/sun/tools/javac/code/Symbol.java      | 10 +++++-
 .../javac/records/RecordCompilationTests.java | 35 +++++++++++++++++++
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java
index bcce5026a60..c0721e5695e 100644
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java
@@ -1785,6 +1785,8 @@ public abstract class Symbol extends AnnoConstruct implements PoolConstant, Elem
          */
         private final int pos;
 
+        private final boolean isVarargs;
+
         /**
          * Construct a record component, given its flags, name, type and owner.
          */
@@ -1792,12 +1794,18 @@ public abstract class Symbol extends AnnoConstruct implements PoolConstant, Elem
             super(PUBLIC, fieldDecl.sym.name, fieldDecl.sym.type, fieldDecl.sym.owner);
             this.originalAnnos = annotations;
             this.pos = fieldDecl.pos;
+            /* it is better to store the original information for this one, instead of relying
+             * on the info in the type of the symbol. This is because on the presence of APs
+             * the symbol will be blown out and we won't be able to know if the original
+             * record component was declared varargs or not.
+             */
+            this.isVarargs = type.hasTag(TypeTag.ARRAY) && ((ArrayType)type).isVarargs();
         }
 
         public List<JCAnnotation> getOriginalAnnos() { return originalAnnos; }
 
         public boolean isVarargs() {
-            return type.hasTag(TypeTag.ARRAY) && ((ArrayType)type).isVarargs();
+            return isVarargs;
         }
 
         @Override @DefinedBy(Api.LANGUAGE_MODEL)
diff --git a/test/langtools/tools/javac/records/RecordCompilationTests.java b/test/langtools/tools/javac/records/RecordCompilationTests.java
index ee9c99a8e7b..bc3be98c72d 100644
--- a/test/langtools/tools/javac/records/RecordCompilationTests.java
+++ b/test/langtools/tools/javac/records/RecordCompilationTests.java
@@ -1672,4 +1672,39 @@ public class RecordCompilationTests extends CompilationTestCase {
             removeLastCompileOptions(2);
         }
     }
+
+    public void testAnnotationsOnVarargsRecComp() {
+        assertOK(
+                """
+                import java.lang.annotation.*;
+
+                @Target({ElementType.TYPE_USE})
+                @interface Simple {}
+
+                record R(@Simple int... val) {
+                    static void test() {
+                        R rec = new R(10, 20);
+                    }
+                }
+                """
+        );
+        assertOK(
+                """
+                import java.lang.annotation.*;
+
+                @Target({ElementType.TYPE_USE})
+                @interface SimpleContainer{ Simple[] value(); }
+
+                @Repeatable(SimpleContainer.class)
+                @Target({ElementType.TYPE_USE})
+                @interface Simple {}
+
+                record R(@Simple int... val) {
+                    static void test() {
+                        R rec = new R(10, 20);
+                    }
+                }
+                """
+        );
+    }
 }