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

Proxy::newProxyInstance and MethodHandleProxies::asInterfaceInstance should reject sealed interfaces

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P2
    • Resolution: Approved
    • Fix Version/s: 17
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      JEP 409 Sealed classes becomes a permanent Java SE feature in 17. No compatibility risk with this spec change.
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      Summary

      java.lang.reflect.Proxy::newProxyInstance will throw IllegalArgumentException if one of the given proxy interfaces is sealed. Similiarly, java.lang.invoke.MethodHandleProxies::asInterfaceInstance will throw IllegalArgumentException if the given interface is sealed.

      Problem

      Proxy and MethodHandleProxies API do not specify how to deal with sealed interfaces.

      Solution

      Update the specification of Proxy::newProxyInstance and MethodHandleProxies::asInterfaceInstance to restrict proxy interfaces to be non-sealed; otherwise, it will throw IllegalArgumentException

      Specification

      Changes to java.lang.reflect.Proxy::newProxyInstance spec:

            * <a id="restrictions">{@code IllegalArgumentException} will be thrown
            * 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

      and changes to java.lang.invoke.MethodHandleProxies::asInterfaceInstance

      --- a/src/java.base/share/classes/java/lang/invoke/MethodHandleProxies.java
      +++ b/src/java.base/share/classes/java/lang/invoke/MethodHandleProxies.java
      @@ -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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mchung Mandy Chung
              Reporter:
              alanb Alan Bateman
              Reviewed By:
              Alan Bateman
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: