RFR: 8255560: Class::isRecord should check that the current class is final and not abstract [v3]

Chris Hegarty chegar at openjdk.java.net
Wed Dec 2 09:38:15 UTC 2020


> Update Class::isRecord to only return true for classes that are final.
> 
> The removal of non-specified JVM checks on classes with a Record Attribute (see JDK-8255342), has resulted in more types of loadable classes that may contain a Record Attribute. Since these checks are not performed by the JVM anymore, Class::isRecord, and by extension Class::getRecordComponents, may return true or component values, respectively, for classes that are not well-formed record classes (as per the JLS), .e.g. non-final or abstract classes, that contain a record Attribute.
> 
> Core Reflection, Class::isRecord, already asserts checks that the JVM does not, e.g. that the direct superclass is java.lang.Record. Some points from the Java Language Specification for record classes:
> 
>  1. It is a compile-time error if a record declaration has the modifier abstract.
>  2. A record declaration is implicitly final.
>  3. The direct superclass type of a record class is Record.
> 
> Class::isRecord already ensures no.3. This issue proposes to add explicit checks in Core Reflection to ensure no.1 and no.2, since the JVM now allows such classes that contain a Record Attribute to be loaded.

Chris Hegarty has updated the pull request incrementally with one additional commit since the last revision:

  review comments

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

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/1543/files
  - new: https://git.openjdk.java.net/jdk/pull/1543/files/d626eeed..1aa59363

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=1543&range=02
 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=1543&range=01-02

  Stats: 4 lines in 1 file changed: 0 ins; 0 del; 4 mod
  Patch: https://git.openjdk.java.net/jdk/pull/1543.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/1543/head:pull/1543

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


More information about the core-libs-dev mailing list