11/*
2- * Copyright 2002-2021 the original author or authors.
2+ * Copyright 2002-2022 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -375,6 +375,22 @@ private static boolean implementsInterface(Method method, Set<Class<?>> ifcs) {
375375 return false ;
376376 }
377377
378+ /**
379+ * Invoke the given method with a CGLIB MethodProxy if possible, falling back
380+ * to a plain reflection invocation in case of a fast-class generation failure.
381+ */
382+ @ Nullable
383+ private static Object invokeMethod (@ Nullable Object target , Method method , Object [] args , MethodProxy methodProxy )
384+ throws Throwable {
385+ try {
386+ return methodProxy .invoke (target , args );
387+ }
388+ catch (CodeGenerationException ex ) {
389+ CglibMethodInvocation .logFastClassGenerationFailure (method );
390+ return AopUtils .invokeJoinpointUsingReflection (target , method , args );
391+ }
392+ }
393+
378394 /**
379395 * Process a return value. Wraps a return of {@code this} if necessary to be the
380396 * {@code proxy} and also verifies that {@code null} is not returned as a primitive.
@@ -425,7 +441,7 @@ public StaticUnadvisedInterceptor(@Nullable Object target) {
425441 @ Override
426442 @ Nullable
427443 public Object intercept (Object proxy , Method method , Object [] args , MethodProxy methodProxy ) throws Throwable {
428- Object retVal = methodProxy . invoke (this .target , args );
444+ Object retVal = invokeMethod (this .target , method , args , methodProxy );
429445 return processReturnType (proxy , this .target , method , retVal );
430446 }
431447 }
@@ -450,7 +466,7 @@ public Object intercept(Object proxy, Method method, Object[] args, MethodProxy
450466 Object oldProxy = null ;
451467 try {
452468 oldProxy = AopContext .setCurrentProxy (proxy );
453- Object retVal = methodProxy . invoke (this .target , args );
469+ Object retVal = invokeMethod (this .target , method , args , methodProxy );
454470 return processReturnType (proxy , this .target , method , retVal );
455471 }
456472 finally {
@@ -478,7 +494,7 @@ public DynamicUnadvisedInterceptor(TargetSource targetSource) {
478494 public Object intercept (Object proxy , Method method , Object [] args , MethodProxy methodProxy ) throws Throwable {
479495 Object target = this .targetSource .getTarget ();
480496 try {
481- Object retVal = methodProxy . invoke (target , args );
497+ Object retVal = invokeMethod (target , method , args , methodProxy );
482498 return processReturnType (proxy , target , method , retVal );
483499 }
484500 finally {
@@ -508,7 +524,7 @@ public Object intercept(Object proxy, Method method, Object[] args, MethodProxy
508524 Object target = this .targetSource .getTarget ();
509525 try {
510526 oldProxy = AopContext .setCurrentProxy (proxy );
511- Object retVal = methodProxy . invoke (target , args );
527+ Object retVal = invokeMethod (target , method , args , methodProxy );
512528 return processReturnType (proxy , target , method , retVal );
513529 }
514530 finally {
@@ -685,13 +701,7 @@ public Object intercept(Object proxy, Method method, Object[] args, MethodProxy
685701 // it does nothing but a reflective operation on the target, and no hot
686702 // swapping or fancy proxying.
687703 Object [] argsToUse = AopProxyUtils .adaptArgumentsIfNecessary (method , args );
688- try {
689- retVal = methodProxy .invoke (target , argsToUse );
690- }
691- catch (CodeGenerationException ex ) {
692- CglibMethodInvocation .logFastClassGenerationFailure (method );
693- retVal = AopUtils .invokeJoinpointUsingReflection (target , method , argsToUse );
694- }
704+ retVal = invokeMethod (target , method , argsToUse , methodProxy );
695705 }
696706 else {
697707 // We need to create a method invocation...
0 commit comments