Integrated: 8254784: javac should reject records with @SafeVarargs applied to varargs record component
Vicente Romero
vromero at openjdk.java.net
Mon Dec 7 16:49:18 UTC 2020
On Fri, 16 Oct 2020 00:26:24 GMT, Vicente Romero <vromero at openjdk.org> wrote:
> Please review this fix for issue [1]. This is the background, for a record defined like:
>
> record R(@SafeVarargs String... s) {}
>
> an the following accessor will be generated:
>
> `@SafeVararags public String[] s() { return s; }`
>
> this code is incorrect as the accessor is not a varargs method. But still the compiler is not generating a compiler error. The reason for this is that the method defining the accessor is not generated until the compiler get to its backend phase (at Lower to be more specific) and the check for incorrect @SafeVarargs use in the compiler happen before that, in Attr.
>
> We decided to do not generate record related code until late phases in order to avoid generating code in the compiler frontend and because if code is generated in early stages then APs could see ASTs not created from user defined code.
>
> The proposed fix is to issue an error as soon as the compiler finds out that the @SafeVarargs annotation is applied to a compiler generated accessor because in other case the compiler would be forced to generate incorrect code.
>
> TIA for the reviews,
> Vicente
>
> [1] [https://bugs.openjdk.java.net/browse/JDK-8254784](https://bugs.openjdk.java.net/browse/JDK-8254784)
This pull request has now been integrated.
Changeset: b4b9828c
Author: Vicente Romero <vromero at openjdk.org>
URL: https://git.openjdk.java.net/jdk/commit/b4b9828c
Stats: 62 lines in 4 files changed: 58 ins; 0 del; 4 mod
8254784: javac should reject records with @SafeVarargs applied to varargs record component
Reviewed-by: mcimadamore
-------------
PR: https://git.openjdk.java.net/jdk/pull/690
More information about the compiler-dev
mailing list