-
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
Change in BeanFactoryUtils.beanNamesForTypeIncludingAncestors() Behavior in Spring Framework 6.2.x causing ClassCastExceptions #34300
Comments
Looked into the issues, it seems related but unfortunately, the tests are still failing even with:
Validated the classpath to be sure.
#33982 and #34234 are interesting because now I need to check |
Updated the GitHub Project
|
Could you try the latest 6.2.3 build snapshot if you get the chance? Your repro tests pass for me now. |
Sounds good. I'll revert back as soon as possible.
|
With 6.2.3-SNAPSHOT, it is now behaving similar to 6.1.x version. Thanks @jhoeller and Spring Team.
|
Good to hear, thanks for the immediate feedback! |
There is an unexpected change in behavior in how
BeanFactoryUtils.beanNamesForTypeIncludingAncestors()
as well asListableBeanFactory.getBeanNamesForType(ResolvableType)
handles generic types in the new Spring Framework 6.2.x compared to 6.1 and even in 5.x.HOW TO REPRODUCE
I was able to reproduce the issue and verify it in the older versions. Just clone the repository, change the Spring Boot version accordingly, build and run the one and only JUnit test: https://github.com/rj-cam/beans-for-type/tree/main
Please refer to the README.MD for a summary of the code.
IMPACT
Unfortunately, due to additional beans being included that are superclasses of the expected generic type, we are now facing a slew of unexpected
java.lang.ClassCastException
.For example:
Please advise if this is the expected behavior in Spring Framework from now on and if there is a way to access the old functionality. Or if not, hopefully, it's a simple fix.
Sadly, this is a showstopper for our upgrade to the latest Spring Framework version. I'm thinking of a workaround to double-check the generic type and ensure it is a sub-class of the expected type (
CharlieRequest
inProcessor<CharlieRequest>
) but I am stuck trying to get the actual type. UsingResolvableType.forInstance(bean).getGeneric(0)
on the errantCharlieSubGenericProcessor<REQ extends CharlieSubRequest>
bean returned byBeanFactoryUtils
is returning?
for its generics type.The text was updated successfully, but these errors were encountered: