Details

    • Subcomponent:
    • Understanding:
      Fix Understood

      Description

      As discussed in JDK-8171335:

      The goal is to allow initialization of a conceptual single private static final field for the new class prior to execution of <clinit>, which is unnamed. The type of the conceptual field is java.lang.Object, so it can contain any Object instance.

      There is NO constant pool which represents this field, so no way to directly access it via bytecodes or reflection, MethodHandles, VarHandles, etc. This field will not be represented in the ConstantValue attributes.

      A <clinit> or any other method in the new class or in a nestmate can read this value only via Lookup.findclassData(), so via a condy BSM. There is no way to write this field, even via SetAccessible().

      Eg. from an email from John

      here is an example BSM:
      public static <T> T classData(Lookup lookup, String ignore, Class<T> type) {
        Object cd = lookup.findClassData(lookup.lookupClass());
        return type.cast(cd);
      }

      Note: the Lookup here is created for the condy and is a Lookup for the class which is calling the BSM, i.e. the newly defined class, not the creator of the class.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dholmes David Holmes
                Reporter:
                dholmes David Holmes
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated: