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

Lookup::accessClass fails with IAE when accessing an arrayClass with a protected inner class as component class

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 17
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      low
    • Compatibility Risk Description:
      The compatibility risk is low. `Lookup::accessClass` used to throw IllegalAccessException on an array type of an accessible element type but in the new implementation it will succeed as expected.
    • Scope:
      SE

      Description

      Summary

      Clarify the specification of Lookup::accessClass that if the specified target class is an array type, the target class is accessible if its element type is accessible.

      Problem

      The implementation throws IllegalAccessException if the target class is an array type of a protected inner class in a different package which is the superclass of the target class and is accessible to the target class.

      Solution

      Fix the implementation and update the specification of Lookup::accessClass to clarify what this method does if the specified target class is an array type.

      Specification

      1. Lookup::accessClass - specify if the target class is an array type, it's accessible if its element type is accessible. In addition, fix the spec to document NPE thrown if the argument is null.
               /**
                * Determines if a class can be accessed from the lookup context defined by
                * this {@code Lookup} object. The static initializer of the class is not run.
      +         * If {@code targetClass} is an array class, {@code targetClass} is accessible
      +         * if the element type of the array class is accessible.  Otherwise,
      +         * {@code targetClass} is determined as accessible as follows.
      +         *
                * <p>
      -         * If the {@code targetClass} is in the same module as the lookup class,
      +         * If {@code targetClass} is in the same module as the lookup class,
                * the lookup class is {@code LC} in module {@code M1} and
                * the previous lookup class is in module {@code M0} or
                * {@code null} if not present,
      @@ -2861,7 +2866,7 @@ assertEquals("[x, y, z]", pb.command().toString());
                * can access public types in all modules when the type is in a package
                * that is exported unconditionally.
                * <p>
      -         * Otherwise, the target class is in a different module from {@code lookupClass},
      +         * Otherwise, {@code targetClass} is in a different module from {@code lookupClass},
                * and if this lookup does not have {@code PUBLIC} access, {@code lookupClass}
                * is inaccessible.
                * <p>
      @@ -2897,13 +2902,14 @@ assertEquals("[x, y, z]", pb.command().toString());
                * @return the class that has been access-checked
                * @throws IllegalAccessException if the class is not accessible from the lookup class
                * and previous lookup class, if present, using the allowed access modes.
      -         * @throws    SecurityException if a security manager is present and it
      -         *                              <a href="MethodHandles.Lookup.html#secmgr">refuses access</a>
      +         * @throws SecurityException if a security manager is present and it
      +         *                           <a href="MethodHandles.Lookup.html#secmgr">refuses access</a>
      +         * @throws NullPointerException if {@code targetClass} is {@code null}
                * @since 9
                * @see <a href="#cross-module-lookup">Cross-module lookups</a>
                */
               public Class<?> accessClass(Class<?> targetClass) throws IllegalAccessException {
      1. Lookup::findClass - fix the spec to specify that NPE is thrown if the argument is null
      @@ -2768,6 +2768,7 @@ assertEquals("[x, y, z]", pb.command().toString());
                * @throws ClassNotFoundException if the class cannot be loaded by the lookup class' loader.
                * @throws IllegalAccessException if the class is not accessible, using the allowed access
                * modes.
      +         * @throws NullPointerException if {@code targetName} is null
                * @since 9
                * @jvms 5.4.3.1 Class and Interface Resolution
                */
                 public Class<?> findClass(String targetName) throws ClassNotFoundException, IllegalAccessException {
      
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mchung Mandy Chung
              Reporter:
              rpatil Ramanand Patil
              Reviewed By:
              Alan Bateman, Chris Hegarty
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: