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 {
```
2. `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 {
```