changeset 12946:4a64fcb2f34f

8076339: Better handling of remote object invocation Reviewed-by: asmotrak, igerasim, skoivu
author smarks
date Mon, 20 Jul 2015 14:37:20 -0700
parents 5a5525f17ba1
children a9dbc8a56c73
files src/java.rmi/share/classes/java/rmi/server/RemoteObjectInvocationHandler.java
diffstat 1 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.rmi/share/classes/java/rmi/server/RemoteObjectInvocationHandler.java	Mon Jul 20 01:45:23 2015 +0000
+++ b/src/java.rmi/share/classes/java/rmi/server/RemoteObjectInvocationHandler.java	Mon Jul 20 14:37:20 2015 -0700
@@ -145,6 +145,14 @@
     public Object invoke(Object proxy, Method method, Object[] args)
         throws Throwable
     {
+        if (! Proxy.isProxyClass(proxy.getClass())) {
+            throw new IllegalArgumentException("not a proxy");
+        }
+
+        if (Proxy.getInvocationHandler(proxy) != this) {
+            throw new IllegalArgumentException("handler mismatch");
+        }
+
         if (method.getDeclaringClass() == Object.class) {
             return invokeObjectMethod(proxy, method, args);
         } else if ("finalize".equals(method.getName()) && method.getParameterCount() == 0) {
@@ -168,11 +176,13 @@
 
         } else if (name.equals("equals")) {
             Object obj = args[0];
+            InvocationHandler hdlr;
             return
                 proxy == obj ||
                 (obj != null &&
                  Proxy.isProxyClass(obj.getClass()) &&
-                 equals(Proxy.getInvocationHandler(obj)));
+                 (hdlr = Proxy.getInvocationHandler(obj)) instanceof RemoteObjectInvocationHandler &&
+                 this.equals(hdlr));
 
         } else if (name.equals("toString")) {
             return proxyToString(proxy);