-
Notifications
You must be signed in to change notification settings - Fork 38.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unwrap CGLIB proxy when invoking non-proxied methods in ReflectionTestUtils
#33429
Comments
ReflectionTestUtils
and Spring-AOP
ReflectionTestUtils
and Spring-AOPReflectionTestUtils.invokeMethod()
and Spring-AOP
ReflectionTestUtils.invokeMethod()
and Spring-AOPReflectionTestUtils.invokeMethod()
and Spring AOP
ReflectionTestUtils.invokeMethod()
and Spring AOPReflectionTestUtils
should automatically unwrap proxies when invoking methods
ReflectionTestUtils
should automatically unwrap proxies when invoking methodsReflectionTestUtils
should automatically unwrap proxies when invoking private
methods
Hi @drachenpalme, Thanks for raising the issue.
The way to achieve that now is by invoking ReflectionTestUtils.invokeGetterMethod(AopTestUtils.getUltimateTargetObject(bean), "privateProperty");
That's correct: there should never be a reason to invoke a private method (or, more specifically, a non-proxied method) on a CGLIB proxy.
That's correct. We'll do something similar for method invocations with In the interim, please use |
ReflectionTestUtils
should automatically unwrap proxies when invoking private
methodsReflectionTestUtils
Hi @sbrannen , thanks a lot for the quick reaction. After some further digging: |
You're welcome.
Sounds like a good plan.
Yes, I have already added the new support to the following locally.
|
This has been addressed in For details, see commit 38a56b3. |
Overview
We are starting to use Spring AOP and have some issues with existing tests using
ReflectionTestUtils
.In one test, a private method of spring-bean
A
is invoked viaReflectionTestUtils.invokeMethod
. This method calls a method of an injected spring-beanB
.With
spring-aop
in use, this does not work anymore. CGlib will not provide a proxied version of the private method. Therefore the private method of the proxy is invoked, and the proxy does not have the DI-beans present and therefore we encounter aNullPointerException
.Now, my original assumption was that
ReflectionTestUtils
should handle this (as thesetField
/getField
methods explicitly deal with Spring proxies).My question is: Is my assumption wrong – and if so, how do we invoke private methods in test – or is this an omission in the
ReflectionTestUtils
?Form a user's perspective I would have hoped that
ReflectionTestUtils
would at least handle the invocation of private methods (there should never be a reason to invoke private methods on a proxy, should there?).I found issue #18622 which seems to be the point where AOP invocations in
setField
/getField
were considered.Related Issues
The text was updated successfully, but these errors were encountered: