-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Mis-proxying of Mockito mock and poor diagnostics for type mismatch on proxy injection [SPR-14478] #19047
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
Comments
Stéphane Nicoll commented For what is worth, I believe the same issue applied if |
Phil Webb commented I've encountered this before without Mockito in the mix, it's a particularly difficult issue to track down. I wonder if Spring Framework 5 should make |
Juergen Hoeller commented Our That said, we might be able to exclude Mockito interfaces in our AOP proxy type decision in |
Juergen Hoeller commented I've got both steps implemented now:
Both of those are candidates for 4.3.2 but no further back, not least of it all since this builds on some refinements that we only really implemented for 4.3 before. |
Andy Wilkinson opened SPR-14478 and commented
There's a small sample application in the referenced Spring Boot issue that reproduces the problem.
There's a Mockito-created mock bean in the context. Due to
@EnableAsync
this bean is proxied using a JDK proxy (proxyTarget
class isfalse
). An attempt is then made to autowire the mocked bean into another class. This fails because the JDK proxy is for a Mockito interface. This in itself could perhaps be considered a problem as the proxy has the wrong form.The proxy is considered to be a viable candidate for autowiring due to
predictBeanType
onAbstractAutowireCapableBeanFactory
returning the type of the underlying bean, ignoring the proxying that'll be performed byAsyncAnnotationBeanPostProcessor
. Ultimately this results in aBeanInstantiationException
that doesn't shed much light on what's actually gone wrong:There are three areas where things are going wrong, each probably a knock-on effect of the previous one:
IllegalArgumentException
don't reveal anything about the arguments that were passed to the constructor and their types so you can't immediately see why it might have failed.Affects: 4.3.1
Reference URL: spring-projects/spring-boot#6405
Issue Links:
Referenced from: commits 0e3f0bd, 503d65d
0 votes, 6 watchers
The text was updated successfully, but these errors were encountered: