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

Clarify the targetName parameter of Lookup::findClass

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 21, 22
    • core-libs
    • None
    • minimal
    • specification update to match the current implementation
    • Java API
    • SE

      Summary

      Clarify the specification of Lookup::findClass to match the implementation that accepts a binary name or a string representing an array in the form returned by Class::getName.

      Problem

      The targetName is specified as a "fully qualified name" that does not match the current implementation and also JVMS 5.1 about resolving a symbolic reference from CONSTANT_Class_info for ldc bytecode. The name is the form returned from Class::getName.

      Solution

      Update the specification of Lookup::findClass that the name is a binary name for a class or an interface and a string representing an array class in the form as described in Class::getName.

      Specification

      --- a/src/java.base/share/classes/java/lang/invoke/MethodHandles.java
      +++ b/src/java.base/share/classes/java/lang/invoke/MethodHandles.java
      @@ -2844,10 +2844,16 @@ assertEquals("[x, y, z]", pb.command().toString());
                * Such a resolution, as specified in JVMS {@jvms 5.4.3.1}, attempts to locate and load the class,
                * and then determines whether the class is accessible to this lookup object.
                * <p>
      +         * For a class or an interface, the name is the {@linkplain ClassLoader##binary-name binary name}.
      +         * For an array class of {@code n} dimensions, the name begins with {@code n} occurrences
      +         * of {@code '['} and followed by the element type as encoded in the
      +         * {@linkplain Class##nameFormat table} specified in {@link Class#getName}.
      +         * <p>
                * The lookup context here is determined by the {@linkplain #lookupClass() lookup class},
                * its class loader, and the {@linkplain #lookupModes() lookup modes}.
                *
      -         * @param targetName the fully qualified name of the class to be looked up.
      +         * @param targetName the {@linkplain ClassLoader##binary-name binary name} of the class
      +         *                   or the string representing an array class
                * @return the requested class.
                * @throws SecurityException if a security manager is present and it
                *                           <a href="MethodHandles.Lookup.html#secmgr">refuses access</a>
      @@ -2857,6 +2863,7 @@ assertEquals("[x, y, z]", pb.command().toString());
                * modes.
                * @throws NullPointerException if {@code targetName} is null
                * @since 9
      +         * @jvms 5.1 The Runtime Constant Pool
                * @jvms 5.4.3.1 Class and Interface Resolution
                */
               public Class<?> findClass(String targetName) throws ClassNotFoundException, IllegalAccessException {

            mchung Mandy Chung (Inactive)
            mchung Mandy Chung (Inactive)
            Brent Christian, Roger Riggs
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: