Consistent fallback in case of fast-class generation failure
Closes gh-28138
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2021 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -375,6 +375,22 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke the given method with a CGLIB MethodProxy if possible, falling back
|
||||||
|
* to a plain reflection invocation in case of a fast-class generation failure.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
private static Object invokeMethod(@Nullable Object target, Method method, Object[] args, MethodProxy methodProxy)
|
||||||
|
throws Throwable {
|
||||||
|
try {
|
||||||
|
return methodProxy.invoke(target, args);
|
||||||
|
}
|
||||||
|
catch (CodeGenerationException ex) {
|
||||||
|
CglibMethodInvocation.logFastClassGenerationFailure(method);
|
||||||
|
return AopUtils.invokeJoinpointUsingReflection(target, method, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process a return value. Wraps a return of {@code this} if necessary to be the
|
* Process a return value. Wraps a return of {@code this} if necessary to be the
|
||||||
* {@code proxy} and also verifies that {@code null} is not returned as a primitive.
|
* {@code proxy} and also verifies that {@code null} is not returned as a primitive.
|
||||||
@@ -425,7 +441,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
||||||
Object retVal = methodProxy.invoke(this.target, args);
|
Object retVal = invokeMethod(this.target, method, args, methodProxy);
|
||||||
return processReturnType(proxy, this.target, method, retVal);
|
return processReturnType(proxy, this.target, method, retVal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -450,7 +466,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||||||
Object oldProxy = null;
|
Object oldProxy = null;
|
||||||
try {
|
try {
|
||||||
oldProxy = AopContext.setCurrentProxy(proxy);
|
oldProxy = AopContext.setCurrentProxy(proxy);
|
||||||
Object retVal = methodProxy.invoke(this.target, args);
|
Object retVal = invokeMethod(this.target, method, args, methodProxy);
|
||||||
return processReturnType(proxy, this.target, method, retVal);
|
return processReturnType(proxy, this.target, method, retVal);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
@@ -478,7 +494,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||||||
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
||||||
Object target = this.targetSource.getTarget();
|
Object target = this.targetSource.getTarget();
|
||||||
try {
|
try {
|
||||||
Object retVal = methodProxy.invoke(target, args);
|
Object retVal = invokeMethod(target, method, args, methodProxy);
|
||||||
return processReturnType(proxy, target, method, retVal);
|
return processReturnType(proxy, target, method, retVal);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
@@ -508,7 +524,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||||||
Object target = this.targetSource.getTarget();
|
Object target = this.targetSource.getTarget();
|
||||||
try {
|
try {
|
||||||
oldProxy = AopContext.setCurrentProxy(proxy);
|
oldProxy = AopContext.setCurrentProxy(proxy);
|
||||||
Object retVal = methodProxy.invoke(target, args);
|
Object retVal = invokeMethod(target, method, args, methodProxy);
|
||||||
return processReturnType(proxy, target, method, retVal);
|
return processReturnType(proxy, target, method, retVal);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
@@ -685,13 +701,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||||||
// it does nothing but a reflective operation on the target, and no hot
|
// it does nothing but a reflective operation on the target, and no hot
|
||||||
// swapping or fancy proxying.
|
// swapping or fancy proxying.
|
||||||
Object[] argsToUse = AopProxyUtils.adaptArgumentsIfNecessary(method, args);
|
Object[] argsToUse = AopProxyUtils.adaptArgumentsIfNecessary(method, args);
|
||||||
try {
|
retVal = invokeMethod(target, method, argsToUse, methodProxy);
|
||||||
retVal = methodProxy.invoke(target, argsToUse);
|
|
||||||
}
|
|
||||||
catch (CodeGenerationException ex) {
|
|
||||||
CglibMethodInvocation.logFastClassGenerationFailure(method);
|
|
||||||
retVal = AopUtils.invokeJoinpointUsingReflection(target, method, argsToUse);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// We need to create a method invocation...
|
// We need to create a method invocation...
|
||||||
|
|||||||
Reference in New Issue
Block a user