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

Proxy.getInvocationHandler throws NullPointerException instead of IllegalArgumentException for null

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 25
    • core-libs
    • None
    • behavioral
    • minimal
    • Adjusts specification to match longstanding actual behavior.
    • Java API
    • SE

      Summary

      Specify java.lang.reflect.Proxy::getInvocationHandler throws a NullPointerException instead of an IllegalArgumentException if the input argument is null.

      Problem

      Proxy.getInvocationHandler specifies any non-proxy-instance arguments result in an IllegalArgumentException. This does not match the actual behavior, that when null is passed, a NullPointerException is thrown.

      Solution

      Update the specification to match the actual behavior, which has been the case since the earliest OpenJDK history back in 2007.

      Specification

      diff --git a/src/java.base/share/classes/java/lang/reflect/Proxy.java b/src/java.base/share/classes/java/lang/reflect/Proxy.java
      index 83a1520ce082f..1658d135cb3b4 100644
      --- a/src/java.base/share/classes/java/lang/reflect/Proxy.java
      +++ b/src/java.base/share/classes/java/lang/reflect/Proxy.java
      @@ -967,6 +967,7 @@ public static boolean isProxyClass(Class<?> cl) {
            * @return  the invocation handler for the proxy instance
            * @throws  IllegalArgumentException if the argument is not a
            *          proxy instance
      +     * @throws  NullPointerException if {@code proxy} is {@code null}
            */
           public static InvocationHandler getInvocationHandler(Object proxy)
               throws IllegalArgumentException

            liach Chen Liang
            liach Chen Liang
            Alan Bateman, Roger Riggs
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: