src/share/classes/java/lang/reflect/Proxy.java

Print this page

        

@@ -29,10 +29,11 @@
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.Arrays;
 import java.util.IdentityHashMap;
 import java.util.Map;
+import java.util.Objects;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.function.BiFunction;
 import sun.misc.ProxyGenerator;
 import sun.misc.VM;
 import sun.reflect.CallerSensitive;

@@ -254,12 +255,16 @@
      * Constructs a new {@code Proxy} instance from a subclass
      * (typically, a dynamic proxy class) with the specified value
      * for its invocation handler.
      *
      * @param   h the invocation handler for this proxy instance
+     *
+     * @throws NullPointerException if the given invocation handler, {@code h},
+     *         is {@code null}.
      */
     protected Proxy(InvocationHandler h) {
+        Objects.requireNonNull(h);
         this.h = h;
     }
 
     /**
      * Returns the {@code java.lang.Class} object for a proxy class

@@ -696,13 +701,11 @@
     public static Object newProxyInstance(ClassLoader loader,
                                           Class<?>[] interfaces,
                                           InvocationHandler h)
         throws IllegalArgumentException
     {
-        if (h == null) {
-            throw new NullPointerException();
-        }
+        Objects.requireNonNull(h);
 
         final SecurityManager sm = System.getSecurityManager();
         if (sm != null) {
             checkProxyAccess(Reflection.getCallerClass(), loader, interfaces);
         }