Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8255904

Remove superfluous use of reflection in Class::isRecord

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 16
    • 16
    • core-libs
    • b26

      For a Class to be considered a record class at runtime, Class::isRecord requires that the direct superclass is j.l.Record. While previewing, the implementation did this check reflectively, to avoid a static dependency on a previewing API. Now that records are final, the implementation can simply refer to j.l.Record statically.


      --- a/src/java.base/share/classes/java/lang/Class.java
      +++ b/src/java.base/share/classes/java/lang/Class.java
      @@ -3661,16 +3661,6 @@ public final class Class<T> implements java.io.Serializable,
               this.getSuperclass() == java.lang.Enum.class;
           }
       
      - /** java.lang.Record.class */
      - private static final Class<?> JAVA_LANG_RECORD_CLASS = javaLangRecordClass();
      - private static Class<?> javaLangRecordClass() {
      - try {
      - return Class.forName0("java.lang.Record", false, null, null);
      - } catch (ClassNotFoundException e) {
      - throw new InternalError("should not reach here", e);
      - }
      - }
      -
           /**
            * Returns {@code true} if and only if this class is a record class.
            *
      @@ -3687,7 +3677,7 @@ public final class Class<T> implements java.io.Serializable,
            * @since 16
            */
           public boolean isRecord() {
      - return getSuperclass() == JAVA_LANG_RECORD_CLASS && isRecord0();
      + return getSuperclass() == java.lang.Record.class && isRecord0();
           }
       

            chegar Chris Hegarty
            chegar Chris Hegarty
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: