JDK-8234445 : spurious error message for record constructors with receiver parameters
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2019-11-20
  • Updated: 2020-01-09
  • Resolved: 2020-01-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 14 JDK 15
14 b31Fixed 15Fixed
Related Reports
Relates :  
Description
this code:

record R(int i) {
    public R(R this, int i) {
        this.i = i;
    }
}

fails with a spurious error message. The error message should be similar to the one for an equivalent class.
Comments
URL: https://hg.openjdk.java.net/jdk/jdk14/rev/2a5117972a35 User: vromero Date: 2020-01-07 14:21:31 +0000
07-01-2020

the attached patch seems to fix the issue, basically for records we are altering the order in which members are entered, this is because the compiler needs to check if a user provided constructor has the same erasure as the canonical constructor or not and depending on this generate one or not. The only way to have access to this information is to enter all the constructors before the compiler gets to the point when it needs to decide if a canonical should be generated or not. The current implementation forgot to add `this` and `super` to the class environment before entering all the constructors. This is the reason for the spurious error message: because `this` was not yet entered when user defined constructors were entered
17-12-2019