From 99042d68a65c7ae30138d06ec75a0c61863a67cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Nie=C3=9Fing?= Date: Tue, 9 May 2023 19:32:35 +0200 Subject: [PATCH] Handle equals and hashCode delegating its calls to the InvocationHandler objects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Steffen Nießing --- .../restclient/ProxyInvocationHandler.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/ProxyInvocationHandler.java b/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/ProxyInvocationHandler.java index 9f317c785e..ee4d202ac5 100644 --- a/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/ProxyInvocationHandler.java +++ b/ext/microprofile/mp-rest-client/src/main/java/org/glassfish/jersey/microprofile/restclient/ProxyInvocationHandler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -18,6 +18,7 @@ import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; +import java.lang.reflect.Proxy; import java.util.concurrent.atomic.AtomicBoolean; import javax.ws.rs.client.Client; @@ -56,6 +57,18 @@ public Object invoke(Object proxy, Method method, Object[] args) { if (method.getName().equals("toString") && (args == null || args.length == 0)) { return restClientModel.toString(); } + + if (args == null && method.getName().equals("hashCode")) { + return hashCode(); + } + + if (args != null && args.length == 1 && method.getName().equals("equals")) { + if (!(args[0] instanceof Proxy)) { + return false; + } + return equals(Proxy.getInvocationHandler(args[0])); + } + if (method.getName().equals("close") && (args == null || args.length == 0)) { closed.set(true); if (null != client) {