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

Remove superfluous use of reflection in Class::isRecord

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 16
    • Fix Version/s: 16
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b26

      Description

      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();
           }
       

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: