mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8266269: Lookup::accessClass fails with IAE when accessing an arrayClass with a protected inner class as component class
Reviewed-by: chegar, alanb
This commit is contained in:
parent
3d0d27ce57
commit
6eb734a60f
5 changed files with 126 additions and 13 deletions
|
@ -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
|
||||
*/
|
||||
|
@ -2837,8 +2838,12 @@ assertEquals("[x, y, z]", pb.command().toString());
|
|||
/**
|
||||
* 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 {
|
||||
if (!VerifyAccess.isClassAccessible(targetClass, lookupClass, prevLookupClass, allowedModes)) {
|
||||
if (!isClassAccessible(targetClass)) {
|
||||
throw makeAccessException(targetClass);
|
||||
}
|
||||
checkSecurityManager(targetClass);
|
||||
|
@ -3684,7 +3690,11 @@ return mh1;
|
|||
boolean isClassAccessible(Class<?> refc) {
|
||||
Objects.requireNonNull(refc);
|
||||
Class<?> caller = lookupClassOrNull();
|
||||
return caller == null || VerifyAccess.isClassAccessible(refc, caller, prevLookupClass, allowedModes);
|
||||
Class<?> type = refc;
|
||||
while (type.isArray()) {
|
||||
type = type.getComponentType();
|
||||
}
|
||||
return caller == null || VerifyAccess.isClassAccessible(type, caller, prevLookupClass, allowedModes);
|
||||
}
|
||||
|
||||
/** Check name for an illegal leading "<" character. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue