Skip to content

Commit 97a81ce

Browse files
author
Vicente Romero
committed
8253385: annotation processors remove varargs information from record components
Reviewed-by: jjg
1 parent 166c728 commit 97a81ce

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1785,19 +1785,27 @@ public static class RecordComponent extends VarSymbol implements RecordComponent
17851785
*/
17861786
private final int pos;
17871787

1788+
private final boolean isVarargs;
1789+
17881790
/**
17891791
* Construct a record component, given its flags, name, type and owner.
17901792
*/
17911793
public RecordComponent(JCVariableDecl fieldDecl, List<JCAnnotation> annotations) {
17921794
super(PUBLIC, fieldDecl.sym.name, fieldDecl.sym.type, fieldDecl.sym.owner);
17931795
this.originalAnnos = annotations;
17941796
this.pos = fieldDecl.pos;
1797+
/* it is better to store the original information for this one, instead of relying
1798+
* on the info in the type of the symbol. This is because on the presence of APs
1799+
* the symbol will be blown out and we won't be able to know if the original
1800+
* record component was declared varargs or not.
1801+
*/
1802+
this.isVarargs = type.hasTag(TypeTag.ARRAY) && ((ArrayType)type).isVarargs();
17951803
}
17961804

17971805
public List<JCAnnotation> getOriginalAnnos() { return originalAnnos; }
17981806

17991807
public boolean isVarargs() {
1800-
return type.hasTag(TypeTag.ARRAY) && ((ArrayType)type).isVarargs();
1808+
return isVarargs;
18011809
}
18021810

18031811
@Override @DefinedBy(Api.LANGUAGE_MODEL)

test/langtools/tools/javac/records/RecordCompilationTests.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,4 +1672,39 @@ record R() implements java.io.Serializable {}
16721672
removeLastCompileOptions(2);
16731673
}
16741674
}
1675+
1676+
public void testAnnotationsOnVarargsRecComp() {
1677+
assertOK(
1678+
"""
1679+
import java.lang.annotation.*;
1680+
1681+
@Target({ElementType.TYPE_USE})
1682+
@interface Simple {}
1683+
1684+
record R(@Simple int... val) {
1685+
static void test() {
1686+
R rec = new R(10, 20);
1687+
}
1688+
}
1689+
"""
1690+
);
1691+
assertOK(
1692+
"""
1693+
import java.lang.annotation.*;
1694+
1695+
@Target({ElementType.TYPE_USE})
1696+
@interface SimpleContainer{ Simple[] value(); }
1697+
1698+
@Repeatable(SimpleContainer.class)
1699+
@Target({ElementType.TYPE_USE})
1700+
@interface Simple {}
1701+
1702+
record R(@Simple int... val) {
1703+
static void test() {
1704+
R rec = new R(10, 20);
1705+
}
1706+
}
1707+
"""
1708+
);
1709+
}
16751710
}

0 commit comments

Comments
 (0)