Repository: aries-rsa Updated Branches: refs/heads/master 389bae151 -> 44943bcef
fastbin equals on proxy did not work correctly Project: http://git-wip-us.apache.org/repos/asf/aries-rsa/repo Commit: http://git-wip-us.apache.org/repos/asf/aries-rsa/commit/44943bce Tree: http://git-wip-us.apache.org/repos/asf/aries-rsa/tree/44943bce Diff: http://git-wip-us.apache.org/repos/asf/aries-rsa/diff/44943bce Branch: refs/heads/master Commit: 44943bcefaf59ff6ba0c8f76edecd484673cffdd Parents: 389bae1 Author: Johannes Utzig <[email protected]> Authored: Tue Feb 6 17:44:25 2018 +0100 Committer: Johannes Utzig <[email protected]> Committed: Tue Feb 6 17:56:48 2018 +0100 ---------------------------------------------------------------------- .../rsa/provider/fastbin/tcp/ClientInvokerImpl.java | 13 ++++++++++++- .../aries/rsa/provider/fastbin/InvocationTest.java | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/44943bce/provider/fastbin/src/main/java/org/apache/aries/rsa/provider/fastbin/tcp/ClientInvokerImpl.java ---------------------------------------------------------------------- diff --git a/provider/fastbin/src/main/java/org/apache/aries/rsa/provider/fastbin/tcp/ClientInvokerImpl.java b/provider/fastbin/src/main/java/org/apache/aries/rsa/provider/fastbin/tcp/ClientInvokerImpl.java index 191a896..521445c 100644 --- a/provider/fastbin/src/main/java/org/apache/aries/rsa/provider/fastbin/tcp/ClientInvokerImpl.java +++ b/provider/fastbin/src/main/java/org/apache/aries/rsa/provider/fastbin/tcp/ClientInvokerImpl.java @@ -295,7 +295,18 @@ public class ClientInvokerImpl implements ClientInvoker, Dispatched { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { if(method.getDeclaringClass()==Object.class) { - //shortcut for equals, hashcode,... + + if (args != null && args.length == 1 && "equals".equals(method.getName())) { + //special treatment for equals to make sure proxy.equals(proxy) -> true + Object arg = args[0]; + if (arg == null) { + return false; + } + if (proxy == arg) { + return true; + } + } + //shortcut for hashcode, toString... return method.invoke(this, args); } return request(this, address, service, classLoader, method, args); http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/44943bce/provider/fastbin/src/test/java/org/apache/aries/rsa/provider/fastbin/InvocationTest.java ---------------------------------------------------------------------- diff --git a/provider/fastbin/src/test/java/org/apache/aries/rsa/provider/fastbin/InvocationTest.java b/provider/fastbin/src/test/java/org/apache/aries/rsa/provider/fastbin/InvocationTest.java index 647d8b6..bd918a8 100644 --- a/provider/fastbin/src/test/java/org/apache/aries/rsa/provider/fastbin/InvocationTest.java +++ b/provider/fastbin/src/test/java/org/apache/aries/rsa/provider/fastbin/InvocationTest.java @@ -191,6 +191,9 @@ public class InvocationTest { Hello hello = (Hello) Proxy.newProxyInstance(HelloImpl.class.getClassLoader(), new Class[] { Hello.class }, handler); assertNotEquals("Hashcode should be handled by the proxy and not be a remote call",-7, hello.hashCode()); assertFalse("equals should be handled by the proxy and not be a remote call",hello.equals(serviceImpl)); + assertTrue("the proxy must equal itself",hello.equals(hello)); + assertFalse(hello.equals(null)); + assertFalse(serviceImpl.equals(hello)); } finally { server.stop();
