mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
Merge
This commit is contained in:
commit
a29953d805
90 changed files with 1714 additions and 489 deletions
|
@ -59,7 +59,8 @@ public class MethodHandleProxies {
|
|||
* even though it re-declares the {@code Object.equals} method and also
|
||||
* declares default methods, such as {@code Comparator.reverse}.
|
||||
* <p>
|
||||
* The interface must be public. No additional access checks are performed.
|
||||
* The interface must be public and not {@linkplain Class#isSealed() sealed}.
|
||||
* No additional access checks are performed.
|
||||
* <p>
|
||||
* The resulting instance of the required type will respond to
|
||||
* invocation of the type's uniquely named method by calling
|
||||
|
@ -156,6 +157,8 @@ public class MethodHandleProxies {
|
|||
public static <T> T asInterfaceInstance(final Class<T> intfc, final MethodHandle target) {
|
||||
if (!intfc.isInterface() || !Modifier.isPublic(intfc.getModifiers()))
|
||||
throw newIllegalArgumentException("not a public interface", intfc.getName());
|
||||
if (intfc.isSealed())
|
||||
throw newIllegalArgumentException("a sealed interface", intfc.getName());
|
||||
final MethodHandle mh;
|
||||
if (System.getSecurityManager() != null) {
|
||||
final Class<?> caller = Reflection.getCallerClass();
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -710,6 +710,10 @@ public class Proxy implements java.io.Serializable {
|
|||
throw new IllegalArgumentException(intf.getName() + " is a hidden interface");
|
||||
}
|
||||
|
||||
if (intf.isSealed()) {
|
||||
throw new IllegalArgumentException(intf.getName() + " is a sealed interface");
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify that the class loader resolves the name of this
|
||||
* interface to the same Class object.
|
||||
|
@ -930,7 +934,8 @@ public class Proxy implements java.io.Serializable {
|
|||
* if any of the following restrictions is violated:</a>
|
||||
* <ul>
|
||||
* <li>All of {@code Class} objects in the given {@code interfaces} array
|
||||
* must represent {@linkplain Class#isHidden() non-hidden} interfaces,
|
||||
* must represent {@linkplain Class#isHidden() non-hidden} and
|
||||
* {@linkplain Class#isSealed() non-sealed} interfaces,
|
||||
* not classes or primitive types.
|
||||
*
|
||||
* <li>No two elements in the {@code interfaces} array may
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue