1
1
/*
2
- * Copyright 2002-2019 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.
@@ -373,6 +373,21 @@ private static boolean implementsInterface(Method method, Set<Class<?>> ifcs) {
373
373
return false ;
374
374
}
375
375
376
+ /**
377
+ * Invoke the given method with a CGLIB MethodProxy if possible, falling back
378
+ * to a plain reflection invocation in case of a fast-class generation failure.
379
+ */
380
+ private static Object invokeMethod (Object target , Method method , Object [] args , MethodProxy methodProxy )
381
+ throws Throwable {
382
+ try {
383
+ return methodProxy .invoke (target , args );
384
+ }
385
+ catch (CodeGenerationException ex ) {
386
+ logger .warn ("Unable to fast-class invoke method [" + method + "] on target [" + target + "]. Falling back to reflection." );
387
+ return AopUtils .invokeJoinpointUsingReflection (target , method , args );
388
+ }
389
+ }
390
+
376
391
/**
377
392
* Process a return value. Wraps a return of {@code this} if necessary to be the
378
393
* {@code proxy} and also verifies that {@code null} is not returned as a primitive.
@@ -418,7 +433,7 @@ public StaticUnadvisedInterceptor(Object target) {
418
433
419
434
@ Override
420
435
public Object intercept (Object proxy , Method method , Object [] args , MethodProxy methodProxy ) throws Throwable {
421
- Object retVal = methodProxy . invoke (this .target , args );
436
+ Object retVal = invokeMethod (this .target , method , args , methodProxy );
422
437
return processReturnType (proxy , this .target , method , retVal );
423
438
}
424
439
}
@@ -441,7 +456,7 @@ public Object intercept(Object proxy, Method method, Object[] args, MethodProxy
441
456
Object oldProxy = null ;
442
457
try {
443
458
oldProxy = AopContext .setCurrentProxy (proxy );
444
- Object retVal = methodProxy . invoke (this .target , args );
459
+ Object retVal = invokeMethod (this .target , method , args , methodProxy );
445
460
return processReturnType (proxy , this .target , method , retVal );
446
461
}
447
462
finally {
@@ -468,7 +483,7 @@ public DynamicUnadvisedInterceptor(TargetSource targetSource) {
468
483
public Object intercept (Object proxy , Method method , Object [] args , MethodProxy methodProxy ) throws Throwable {
469
484
Object target = this .targetSource .getTarget ();
470
485
try {
471
- Object retVal = methodProxy . invoke (target , args );
486
+ Object retVal = invokeMethod (target , method , args , methodProxy );
472
487
return processReturnType (proxy , target , method , retVal );
473
488
}
474
489
finally {
@@ -495,7 +510,7 @@ public Object intercept(Object proxy, Method method, Object[] args, MethodProxy
495
510
Object target = this .targetSource .getTarget ();
496
511
try {
497
512
oldProxy = AopContext .setCurrentProxy (proxy );
498
- Object retVal = methodProxy . invoke (target , args );
513
+ Object retVal = invokeMethod (target , method , args , methodProxy );
499
514
return processReturnType (proxy , target , method , retVal );
500
515
}
501
516
finally {
@@ -665,7 +680,7 @@ public Object intercept(Object proxy, Method method, Object[] args, MethodProxy
665
680
// it does nothing but a reflective operation on the target, and no hot
666
681
// swapping or fancy proxying.
667
682
Object [] argsToUse = AopProxyUtils .adaptArgumentsIfNecessary (method , args );
668
- retVal = methodProxy . invoke (target , argsToUse );
683
+ retVal = invokeMethod (target , method , argsToUse , methodProxy );
669
684
}
670
685
else {
671
686
// We need to create a method invocation...
@@ -734,7 +749,7 @@ public CglibMethodInvocation(Object proxy, Object target, Method method, Object[
734
749
@ Override
735
750
protected Object invokeJoinpoint () throws Throwable {
736
751
if (this .publicMethod ) {
737
- return this . methodProxy .invoke (this .target , this .arguments );
752
+ return methodProxy .invoke (this .target , this .arguments );
738
753
}
739
754
else {
740
755
return super .invokeJoinpoint ();
0 commit comments