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.
@@ -344,6 +344,21 @@ private Callback[] getCallbacks(Class<?> rootClass) throws Exception {
344
344
return callbacks ;
345
345
}
346
346
347
+ /**
348
+ * Invoke the given method with a CGLIB MethodProxy if possible, falling back
349
+ * to a plain reflection invocation in case of a fast-class generation failure.
350
+ */
351
+ private static Object invokeMethod (Object target , Method method , Object [] args , MethodProxy methodProxy )
352
+ throws Throwable {
353
+ try {
354
+ return methodProxy .invoke (target , args );
355
+ }
356
+ catch (CodeGenerationException ex ) {
357
+ logger .warn ("Unable to fast-class invoke method [" + method + "] on target [" + target + "]. Falling back to reflection." );
358
+ return AopUtils .invokeJoinpointUsingReflection (target , method , args );
359
+ }
360
+ }
361
+
347
362
/**
348
363
* Process a return value. Wraps a return of {@code this} if necessary to be the
349
364
* {@code proxy} and also verifies that {@code null} is not returned as a primitive.
@@ -400,7 +415,7 @@ public StaticUnadvisedInterceptor(Object target) {
400
415
401
416
@ Override
402
417
public Object intercept (Object proxy , Method method , Object [] args , MethodProxy methodProxy ) throws Throwable {
403
- Object retVal = methodProxy . invoke (this .target , args );
418
+ Object retVal = invokeMethod (this .target , method , args , methodProxy );
404
419
return processReturnType (proxy , this .target , method , retVal );
405
420
}
406
421
}
@@ -423,7 +438,7 @@ public Object intercept(Object proxy, Method method, Object[] args, MethodProxy
423
438
Object oldProxy = null ;
424
439
try {
425
440
oldProxy = AopContext .setCurrentProxy (proxy );
426
- Object retVal = methodProxy . invoke (this .target , args );
441
+ Object retVal = invokeMethod (this .target , method , args , methodProxy );
427
442
return processReturnType (proxy , this .target , method , retVal );
428
443
}
429
444
finally {
@@ -450,7 +465,7 @@ public DynamicUnadvisedInterceptor(TargetSource targetSource) {
450
465
public Object intercept (Object proxy , Method method , Object [] args , MethodProxy methodProxy ) throws Throwable {
451
466
Object target = this .targetSource .getTarget ();
452
467
try {
453
- Object retVal = methodProxy . invoke (target , args );
468
+ Object retVal = invokeMethod (target , method , args , methodProxy );
454
469
return processReturnType (proxy , target , method , retVal );
455
470
}
456
471
finally {
@@ -477,7 +492,7 @@ public Object intercept(Object proxy, Method method, Object[] args, MethodProxy
477
492
Object target = this .targetSource .getTarget ();
478
493
try {
479
494
oldProxy = AopContext .setCurrentProxy (proxy );
480
- Object retVal = methodProxy . invoke (target , args );
495
+ Object retVal = invokeMethod (target , method , args , methodProxy );
481
496
return processReturnType (proxy , target , method , retVal );
482
497
}
483
498
finally {
@@ -646,7 +661,8 @@ public Object intercept(Object proxy, Method method, Object[] args, MethodProxy
646
661
// Note that the final invoker must be an InvokerInterceptor, so we know
647
662
// it does nothing but a reflective operation on the target, and no hot
648
663
// swapping or fancy proxying.
649
- retVal = methodProxy .invoke (target , args );
664
+ Object [] argsToUse = AopProxyUtils .adaptArgumentsIfNecessary (method , args );
665
+ retVal = invokeMethod (target , method , argsToUse , methodProxy );
650
666
}
651
667
else {
652
668
// We need to create a method invocation...
@@ -715,7 +731,7 @@ public CglibMethodInvocation(Object proxy, Object target, Method method, Object[
715
731
@ Override
716
732
protected Object invokeJoinpoint () throws Throwable {
717
733
if (this .publicMethod ) {
718
- return this . methodProxy .invoke (this .target , this .arguments );
734
+ return methodProxy .invoke (this .target , this .arguments );
719
735
}
720
736
else {
721
737
return super .invokeJoinpoint ();
0 commit comments