CglibAopProxy skips method proxy for equals/hashCode/toString override

Issue: SPR-17500
This commit is contained in:
Juergen Hoeller
2018-11-20 22:04:28 +01:00
parent f5aeb81473
commit 2a5d7690b6
2 changed files with 51 additions and 5 deletions

View File

@@ -723,17 +723,20 @@ class CglibAopProxy implements AopProxy, Serializable {
*/
private static class CglibMethodInvocation extends ReflectiveMethodInvocation {
@Nullable
private final MethodProxy methodProxy;
private final boolean publicMethod;
public CglibMethodInvocation(Object proxy, @Nullable Object target, Method method,
Object[] arguments, @Nullable Class<?> targetClass,
List<Object> interceptorsAndDynamicMethodMatchers, MethodProxy methodProxy) {
super(proxy, target, method, arguments, targetClass, interceptorsAndDynamicMethodMatchers);
this.methodProxy = methodProxy;
this.publicMethod = Modifier.isPublic(method.getModifiers());
// Only use method proxy for public methods not derived from java.lang.Object
this.methodProxy = (Modifier.isPublic(method.getModifiers()) &&
method.getDeclaringClass() != Object.class && !AopUtils.isEqualsMethod(method) &&
!AopUtils.isHashCodeMethod(method) && !AopUtils.isToStringMethod(method) ?
methodProxy : null);
}
/**
@@ -742,7 +745,7 @@ class CglibAopProxy implements AopProxy, Serializable {
*/
@Override
protected Object invokeJoinpoint() throws Throwable {
if (this.publicMethod && getMethod().getDeclaringClass() != Object.class) {
if (this.methodProxy != null) {
return this.methodProxy.invoke(this.target, this.arguments);
}
else {