Restore ability to return original method for proxy-derived method

Closes gh-32365
This commit is contained in:
Juergen Hoeller
2024-03-04 22:48:46 +01:00
parent 7493ce86b6
commit 24759a75f4
2 changed files with 41 additions and 1 deletions

View File

@@ -17,6 +17,7 @@
package org.springframework.core;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
@@ -86,7 +87,10 @@ public final class BridgeMethodResolver {
* @see org.springframework.util.ClassUtils#getMostSpecificMethod
*/
public static Method getMostSpecificMethod(Method bridgeMethod, @Nullable Class<?> targetClass) {
if (targetClass != null && !bridgeMethod.getDeclaringClass().isAssignableFrom(targetClass)) {
if (targetClass != null &&
!ClassUtils.getUserClass(bridgeMethod.getDeclaringClass()).isAssignableFrom(targetClass) &&
!Proxy.isProxyClass(bridgeMethod.getDeclaringClass())) {
// From a different class hierarchy, and not a JDK or CGLIB proxy either -> return as-is.
return bridgeMethod;
}