RFR: 8254784: javac should reject records with @SafeVarargs applied to varargs record component

Vicente Romero vromero at openjdk.java.net
Fri Oct 16 00:35:21 UTC 2020


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 @SVA 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)

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

Commit messages:
 - 8254784: javac should reject records with @SafeVarargs applied to varargs record component

Changes: https://git.openjdk.java.net/jdk/pull/690/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=690&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8254784
  Stats: 62 lines in 4 files changed: 58 ins; 0 del; 4 mod
  Patch: https://git.openjdk.java.net/jdk/pull/690.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/690/head:pull/690

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


More information about the compiler-dev mailing list