Lazily check log level within validation conditions

See gh-24672
This commit is contained in:
Juergen Hoeller 2020-03-13 23:14:38 +01:00
parent 7c4f0318bb
commit 33642345a4
1 changed files with 3 additions and 5 deletions

View File

@ -253,24 +253,22 @@ class CglibAopProxy implements AopProxy, Serializable {
*/
private void doValidateClass(Class<?> proxySuperClass, @Nullable ClassLoader proxyClassLoader, Set<Class<?>> ifcs) {
if (proxySuperClass != Object.class) {
final boolean infoEnabled = logger.isInfoEnabled();
final boolean debugEnabled = logger.isDebugEnabled();
Method[] methods = proxySuperClass.getDeclaredMethods();
for (Method method : methods) {
int mod = method.getModifiers();
if (!Modifier.isStatic(mod) && !Modifier.isPrivate(mod)) {
if (Modifier.isFinal(mod)) {
if (infoEnabled && implementsInterface(method, ifcs)) {
if (logger.isInfoEnabled() && implementsInterface(method, ifcs)) {
logger.info("Unable to proxy interface-implementing method [" + method + "] because " +
"it is marked as final: Consider using interface-based JDK proxies instead!");
}
if (debugEnabled) {
if (logger.isDebugEnabled()) {
logger.debug("Final method [" + method + "] cannot get proxied via CGLIB: " +
"Calls to this method will NOT be routed to the target instance and " +
"might lead to NPEs against uninitialized fields in the proxy instance.");
}
}
else if (debugEnabled && !Modifier.isPublic(mod) && !Modifier.isProtected(mod) &&
else if (logger.isDebugEnabled() && !Modifier.isPublic(mod) && !Modifier.isProtected(mod) &&
proxyClassLoader != null && proxySuperClass.getClassLoader() != proxyClassLoader) {
logger.debug("Method [" + method + "] is package-visible across different ClassLoaders " +
"and cannot get proxied via CGLIB: Declare this method as public or protected " +