1
1
/*
2
- * Copyright 2002-2015 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.
@@ -334,6 +334,21 @@ private Callback[] getCallbacks(Class<?> rootClass) throws Exception {
334
334
return callbacks ;
335
335
}
336
336
337
+ /**
338
+ * Invoke the given method with a CGLIB MethodProxy if possible, falling back
339
+ * to a plain reflection invocation in case of a fast-class generation failure.
340
+ */
341
+ private static Object invokeMethod (Object target , Method method , Object [] args , MethodProxy methodProxy )
342
+ throws Throwable {
343
+ try {
344
+ return methodProxy .invoke (target , args );
345
+ }
346
+ catch (CodeGenerationException ex ) {
347
+ logger .warn ("Unable to fast-class invoke method [" + method + "] on target [" + target + "]. Falling back to reflection." );
348
+ return AopUtils .invokeJoinpointUsingReflection (target , method , args );
349
+ }
350
+ }
351
+
337
352
/**
338
353
* Process a return value. Wraps a return of {@code this} if necessary to be the
339
354
* {@code proxy} and also verifies that {@code null} is not returned as a primitive.
@@ -389,7 +404,7 @@ public StaticUnadvisedInterceptor(Object target) {
389
404
}
390
405
391
406
public Object intercept (Object proxy , Method method , Object [] args , MethodProxy methodProxy ) throws Throwable {
392
- Object retVal = methodProxy . invoke (this .target , args );
407
+ Object retVal = invokeMethod (this .target , method , args , methodProxy );
393
408
return processReturnType (proxy , this .target , method , retVal );
394
409
}
395
410
}
@@ -411,7 +426,7 @@ public Object intercept(Object proxy, Method method, Object[] args, MethodProxy
411
426
Object oldProxy = null ;
412
427
try {
413
428
oldProxy = AopContext .setCurrentProxy (proxy );
414
- Object retVal = methodProxy . invoke (this .target , args );
429
+ Object retVal = invokeMethod (this .target , method , args , methodProxy );
415
430
return processReturnType (proxy , this .target , method , retVal );
416
431
}
417
432
finally {
@@ -437,7 +452,7 @@ public DynamicUnadvisedInterceptor(TargetSource targetSource) {
437
452
public Object intercept (Object proxy , Method method , Object [] args , MethodProxy methodProxy ) throws Throwable {
438
453
Object target = this .targetSource .getTarget ();
439
454
try {
440
- Object retVal = methodProxy . invoke (target , args );
455
+ Object retVal = invokeMethod (target , method , args , methodProxy );
441
456
return processReturnType (proxy , target , method , retVal );
442
457
}
443
458
finally {
@@ -463,7 +478,7 @@ public Object intercept(Object proxy, Method method, Object[] args, MethodProxy
463
478
Object target = this .targetSource .getTarget ();
464
479
try {
465
480
oldProxy = AopContext .setCurrentProxy (proxy );
466
- Object retVal = methodProxy . invoke (target , args );
481
+ Object retVal = invokeMethod (target , method , args , methodProxy );
467
482
return processReturnType (proxy , target , method , retVal );
468
483
}
469
484
finally {
@@ -626,7 +641,8 @@ public Object intercept(Object proxy, Method method, Object[] args, MethodProxy
626
641
// Note that the final invoker must be an InvokerInterceptor, so we know
627
642
// it does nothing but a reflective operation on the target, and no hot
628
643
// swapping or fancy proxying.
629
- retVal = methodProxy .invoke (target , args );
644
+ Object [] argsToUse = AopProxyUtils .adaptArgumentsIfNecessary (method , args );
645
+ retVal = invokeMethod (target , method , argsToUse , methodProxy );
630
646
}
631
647
else {
632
648
// We need to create a method invocation...
0 commit comments