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