1
1
/*
2
- * Copyright 2002-2021 the original author or authors.
2
+ * Copyright 2002-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* 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) {
375
375
return false ;
376
376
}
377
377
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
+
378
394
/**
379
395
* Process a return value. Wraps a return of {@code this} if necessary to be the
380
396
* {@code proxy} and also verifies that {@code null} is not returned as a primitive.
@@ -425,7 +441,7 @@ public StaticUnadvisedInterceptor(@Nullable Object target) {
425
441
@ Override
426
442
@ Nullable
427
443
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 );
429
445
return processReturnType (proxy , this .target , method , retVal );
430
446
}
431
447
}
@@ -450,7 +466,7 @@ public Object intercept(Object proxy, Method method, Object[] args, MethodProxy
450
466
Object oldProxy = null ;
451
467
try {
452
468
oldProxy = AopContext .setCurrentProxy (proxy );
453
- Object retVal = methodProxy . invoke (this .target , args );
469
+ Object retVal = invokeMethod (this .target , method , args , methodProxy );
454
470
return processReturnType (proxy , this .target , method , retVal );
455
471
}
456
472
finally {
@@ -478,7 +494,7 @@ public DynamicUnadvisedInterceptor(TargetSource targetSource) {
478
494
public Object intercept (Object proxy , Method method , Object [] args , MethodProxy methodProxy ) throws Throwable {
479
495
Object target = this .targetSource .getTarget ();
480
496
try {
481
- Object retVal = methodProxy . invoke (target , args );
497
+ Object retVal = invokeMethod (target , method , args , methodProxy );
482
498
return processReturnType (proxy , target , method , retVal );
483
499
}
484
500
finally {
@@ -508,7 +524,7 @@ public Object intercept(Object proxy, Method method, Object[] args, MethodProxy
508
524
Object target = this .targetSource .getTarget ();
509
525
try {
510
526
oldProxy = AopContext .setCurrentProxy (proxy );
511
- Object retVal = methodProxy . invoke (target , args );
527
+ Object retVal = invokeMethod (target , method , args , methodProxy );
512
528
return processReturnType (proxy , target , method , retVal );
513
529
}
514
530
finally {
@@ -685,13 +701,7 @@ public Object intercept(Object proxy, Method method, Object[] args, MethodProxy
685
701
// it does nothing but a reflective operation on the target, and no hot
686
702
// swapping or fancy proxying.
687
703
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 );
695
705
}
696
706
else {
697
707
// We need to create a method invocation...
0 commit comments