RFR: 8288130: compiler error with AP and explicit record accessor [v3]

Vicente Romero vromero at openjdk.org
Wed Jun 22 15:00:37 UTC 2022


> Please review this PR which is fixing a tricky bug in records. Right now this code is trivial to compile by javac:
> 
> record TestRecord<T>(T someValue) {
>     public T someValue() {
>         return this.someValue;
>     }
> }
> 
> but in the presence of an annotation processor this code is entered at least two times. Every one of those times a new type variable is created. Now for records this have some implications. Record components are created once, in most cases unless there is an error for example, meaning that the type of the record component in this case was not in sync with the type of the accessor, and this is a mismatch reported as an error by the compiler. Note that if the accessor was not explicitly declared but generated this wouldn't happen as the accessor is generated from the info in the record component so a generated accessor is always in sync with its corresponding record component.
> 
> A possible solution to this issue could be to recreate the record component if there is at least a type variable in its type. But I decided to go for an all in solution recreating the record component always so if there are annotation processor rounds, a new record component would be created for each of them. This way we can future-proof this area of records which has seen bugs in the past and be sure that we are always dealing with a fresh instance of the record components.
> 
> TIA

Vicente Romero has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains four additional commits since the last revision:

 - Merge branch 'master' into JDK-8288130
 - adding some documentation
 - adding accompanying regression test
 - 8288130: compiler error with AP and explicit record accessor

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/9160/files
  - new: https://git.openjdk.org/jdk/pull/9160/files/af03c68d..d0d86769

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=9160&range=02
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=9160&range=01-02

  Stats: 26450 lines in 921 files changed: 14299 ins; 9582 del; 2569 mod
  Patch: https://git.openjdk.org/jdk/pull/9160.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/9160/head:pull/9160

PR: https://git.openjdk.org/jdk/pull/9160


More information about the compiler-dev mailing list