changeset 11281:9537ffca1fd3

8076339: Better handling of remote object invocation Reviewed-by: asmotrak, igerasim, skoivu
author igerasim
date Fri, 31 Jul 2015 00:48:36 +0300
parents 73d8704c8e30
children 066aa0697634
files src/share/classes/java/rmi/server/RemoteObjectInvocationHandler.java
diffstat 1 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/rmi/server/RemoteObjectInvocationHandler.java	Thu Jul 30 07:31:07 2015 -0700
+++ b/src/share/classes/java/rmi/server/RemoteObjectInvocationHandler.java	Fri Jul 31 00:48:36 2015 +0300
@@ -162,6 +162,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 &&
@@ -186,11 +194,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);