RFR: JDK-8242478: compiler implementation for records (Second Preview)

Vicente Romero vicente.romero at oracle.com
Thu Apr 30 15:10:32 UTC 2020

Hi all,

Please review the patch for the second preview of records at [1], the 
bug entry is at [2] the related spec can be found at [3], the JEP is at 
[4]. This patch implements the following changes:

- local enums and interfaces, along with local records
- removed possibility of final modifier for record components
- removed requirement that canonical constructor must be public. Any 
access modifier must provide at least as much access as the record 
class. If a canonical constructor is implicitly declared, then its 
access modifier is the same as the record class
- check that there is a iff relation between a varargs record component 
and the corresponding parameter in the canonical constructor so:

    record R(int... i) { R(int... i) {...}} is allowed but:
    record R(int... i) { R(int[] i) {...}} is not

- new case for using @Override annotation to declare that a method is an 
accessor method for a record component

These are the main changes, plus:
- there is one liner change to java.io.ObjectStreamClass, this is 
related to the fact that now the canonical record don't necessarily has 
to be public thus the use of Class::getDeclaredConstructor
- there is a one liner change concerning the flags of the generated 
toString method, this is a bug fix, toString didn't have the same flags 
as hashCode and equals
- I have added several tests to enforce other rules in the spec like the 
one saying that in a compact constructor fields have to be initialized 
in the same order in which the corresponding record component has been 
declared, plus some additional tests
- test RecordCompilationTests is executed twice now, first in a mode 
that is equivalent to the original test and then using an "empty" 
annotation processor. This is because some regressions have been 
discovered in the past when an annotation processor is present. I have 
also made some changes to the libraries this test uses.


[1] http://cr.openjdk.java.net/~vromero/8242478/webrev.00
[2] https://bugs.openjdk.java.net/browse/JDK-8242478
[4] https://bugs.openjdk.java.net/browse/JDK-8242303
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20200430/9e179dd5/attachment.htm>

More information about the compiler-dev mailing list