1
1
/*
2
- * Copyright 2002-2014 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.
@@ -335,6 +335,21 @@ private Callback[] getCallbacks(Class<?> rootClass) throws Exception {
335
335
return callbacks ;
336
336
}
337
337
338
+ /**
339
+ * Invoke the given method with a CGLIB MethodProxy if possible, falling back
340
+ * to a plain reflection invocation in case of a fast-class generation failure.
341
+ */
342
+ private static Object invokeMethod (Object target , Method method , Object [] args , MethodProxy methodProxy )
343
+ throws Throwable {
344
+ try {
345
+ return methodProxy .invoke (target , args );
346
+ }
347
+ catch (CodeGenerationException ex ) {
348
+ logger .warn ("Unable to fast-class invoke method [" + method + "] on target [" + target + "]. Falling back to reflection." );
349
+ return AopUtils .invokeJoinpointUsingReflection (target , method , args );
350
+ }
351
+ }
352
+
338
353
/**
339
354
* Process a return value. Wraps a return of {@code this} if necessary to be the
340
355
* {@code proxy} and also verifies that {@code null} is not returned as a primitive.
@@ -391,7 +406,7 @@ public StaticUnadvisedInterceptor(Object target) {
391
406
392
407
@ Override
393
408
public Object intercept (Object proxy , Method method , Object [] args , MethodProxy methodProxy ) throws Throwable {
394
- Object retVal = methodProxy . invoke (this .target , args );
409
+ Object retVal = invokeMethod (this .target , method , args , methodProxy );
395
410
return processReturnType (proxy , this .target , method , retVal );
396
411
}
397
412
}
@@ -414,7 +429,7 @@ public Object intercept(Object proxy, Method method, Object[] args, MethodProxy
414
429
Object oldProxy = null ;
415
430
try {
416
431
oldProxy = AopContext .setCurrentProxy (proxy );
417
- Object retVal = methodProxy . invoke (this .target , args );
432
+ Object retVal = invokeMethod (this .target , method , args , methodProxy );
418
433
return processReturnType (proxy , this .target , method , retVal );
419
434
}
420
435
finally {
@@ -441,7 +456,7 @@ public DynamicUnadvisedInterceptor(TargetSource targetSource) {
441
456
public Object intercept (Object proxy , Method method , Object [] args , MethodProxy methodProxy ) throws Throwable {
442
457
Object target = this .targetSource .getTarget ();
443
458
try {
444
- Object retVal = methodProxy . invoke (target , args );
459
+ Object retVal = invokeMethod (target , method , args , methodProxy );
445
460
return processReturnType (proxy , target , method , retVal );
446
461
}
447
462
finally {
@@ -468,7 +483,7 @@ public Object intercept(Object proxy, Method method, Object[] args, MethodProxy
468
483
Object target = this .targetSource .getTarget ();
469
484
try {
470
485
oldProxy = AopContext .setCurrentProxy (proxy );
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 {
@@ -637,7 +652,8 @@ public Object intercept(Object proxy, Method method, Object[] args, MethodProxy
637
652
// Note that the final invoker must be an InvokerInterceptor, so we know
638
653
// it does nothing but a reflective operation on the target, and no hot
639
654
// swapping or fancy proxying.
640
- retVal = methodProxy .invoke (target , args );
655
+ Object [] argsToUse = AopProxyUtils .adaptArgumentsIfNecessary (method , args );
656
+ retVal = invokeMethod (target , method , argsToUse , methodProxy );
641
657
}
642
658
else {
643
659
// We need to create a method invocation...
@@ -705,7 +721,7 @@ public CglibMethodInvocation(Object proxy, Object target, Method method, Object[
705
721
@ Override
706
722
protected Object invokeJoinpoint () throws Throwable {
707
723
if (this .publicMethod ) {
708
- return this . methodProxy .invoke (this .target , this .arguments );
724
+ return methodProxy .invoke (this .target , this .arguments );
709
725
}
710
726
else {
711
727
return super .invokeJoinpoint ();
0 commit comments