This is a follow-up on JDK-8255342 that removes non-specified JVM checks on 
classes with Record attributes.  That introduces a regression in 
`InstanceKlass::is_record` that returns true on a non-record class which has 
`RecordComponents` attribute present.   This causes unexpected semantics in 
`JVM_IsRecord` and `JVM_GetRecordComponents` and also a regression to trust 
final fields for non-record classes.

I propose to change `InstanceKlass::is_record` to match the JLS semantic of a 
record class, i.e. final direct subclass of `java.lang.Record` with the 
presence of `RecordComponents` attribute.  There is no change to JVM class file 
validation.   Also I propose clearly define:
    - `JVM_IsRecord` returns true if the given class is a record i.e. final and 
direct subclass of `java.lang.Record` with `RecordComponents` attribute
    - `JVM_GetRecordComponents` returns an `RecordComponents` array  if 
`RecordComponents` attribute is present; otherwise, returns NULL.  This does 
not check if it's a record class or not.  So it may return non-null on a 
non-record class if it has `RecordComponents` attribute.  So 
`JVM_GetRecordComponents` returns the content of the classfile.

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

Commit messages:
 - 8257596: Clarify trusted final fields for record classes

Changes: https://git.openjdk.java.net/jdk/pull/1706/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=1706&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8257596
  Stats: 60 lines in 4 files changed: 30 ins; 10 del; 20 mod
  Patch: https://git.openjdk.java.net/jdk/pull/1706.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/1706/head:pull/1706

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

Reply via email to