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

[lworld] a hidden value class can't have <vnew> static factory method

XMLWordPrintable

      The 'FIXME' in this method in java/lang/invoke/MemberName.java needs fixing:

          /** Create a name for the given reflected constructor. The
       resulting name will be in a resolved state. */
          @SuppressWarnings("LeakingThisInConstructor")
          public MemberName(Constructor<?> ctor) {
              Objects.requireNonNull(ctor);
              // fill in vmtarget, vmindex while we have ctor in hand:
              MethodHandleNatives.init(this, ctor);
              assert(isResolved() && this.clazz != null);
              this.name = CONSTRUCTOR_NAME;
              if (this.type == null) {
                  Class<?> rtype = void.class;
                  if (isStatic()) { // a static init factory, not a true constructor
                      rtype = getDeclaringClass();
                      // FIXME: If it's a hidden class, this sig won't work.
                  }
                  this.type = new Object[] { rtype, ctor.getParameterTypes() };
              }
          }

      The problem is that static init factory methods normally return the type of their declaring inline class. But, if the declaring class is a VM unsafe anonymous class then the return type is java.lang.Object.

      But, this code doesn't check if the declaring class is a VM unsafe anonymous class and it is unclear how it could do so.

            mchung Mandy Chung
            hseigel Harold Seigel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: