-
CSR
-
Resolution: Approved
-
P3
-
behavioral
-
minimal
-
Programs with an existing ClassFile attribute named Record may notice a change in behavior. Such programs are expected to be rare.
-
Class file construct
-
SE
Summary
Introduce a Record attribute in the class
file format, so that the JVM can provide reflection support for components of record types.
Problem
Record classes (JEP 359) are a preview feature of Java SE 14. The JVM will need to support reflecting over records and their components.
Solution
A Record attribute will be defined in the ClassFile
format, containing information about the record class and its components. The JVM will use the attribute's contents to satisfy reflection requests when the Java API Class::getRecordComponents
is used.
The format of the Record attribute is checked by the JVM even if no reflection is performed. The checking is done at class load time, and is similar to format checking of attributes such as Exceptions and InnerClasses. For example, the JVM checks that the attribute's constant pool indexes are valid and that each component's attributes occur only once. This contrasts with other attributes, such as MethodParameters, that are not examined unless reflection is performed.
Note that the Record attribute could potentially be useful in other ways, for example, in determining if a class is a record.
The specifications for class redefinition and retransformation, in the JVM TI specification are enhanced to disallow any modification of the Record
attribute.
Specification
Java Virtual Machine Spec changes for the Record attribute are attached.
The JVM TI specification changes are as follows:
@@ -7633,8 +7633,8 @@
(unless explicitly prohibited).
The retransformation must not add, remove or rename fields or methods, change the
signatures of methods, change modifiers, or change inheritance.
- The retransformation must not change the <code>NestHost</code> or
- <code>NestMembers</code> attributes.
+ The retransformation must not change the <code>NestHost</code>,
+ <code>NestMembers</code>, or <code>Record</code> attributes.
These restrictions may be lifted in future versions.
See the error return description below for information on error codes
returned if an unsupported retransformation is attempted.
@@ -7786,11 +7786,11 @@
(unless explicitly prohibited).
The redefinition must not add, remove or rename fields or methods, change the
signatures of methods, change modifiers, or change inheritance.
- The retransformation must not change the <code>NestHost</code> or
- <code>NestMembers</code> attributes.
+ The redefinition must not change the <code>NestHost</code>,
+ <code>NestMembers</code>, or <code>Record</code> attributes.
These restrictions may be lifted in future versions.
- See the error return description below for information on error codes
- returned if an unsupported redefinition is attempted.
+ See the error return description below for information on error codes
+ returned if an unsupported redefinition is attempted.
The class file bytes are not verified or installed until they have passed
through the chain of <eventlink id="ClassFileLoadHook"/> events, thus the
returned error code reflects the result of the transformations applied
- csr of
-
JDK-8233526 JVM support for records
- Resolved
- relates to
-
JDK-8233436 Preview APIs support for records
- Closed
-
JDK-8225058 JVMS changes for Records (Preview)
- Resolved
-
JDK-8255342 Remove non-specified JVM checks on Classes with Record attributes
- Resolved