mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8269351: Proxy::newProxyInstance and MethodHandleProxies::asInterfaceInstance should reject sealed interfaces
Reviewed-by: darcy, alanb
This commit is contained in:
parent
824a51693e
commit
3d0d27ce57
4 changed files with 101 additions and 4 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();
|
||||
|
|
|
@ -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