-
Notifications
You must be signed in to change notification settings - Fork 38.5k
CastClass exception when wiring Map of beans (NullBean instead of 'null' in the map) [SPR-16033] #20582
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
Francisco Lozano commented Fixing temporarily as: @Bean
@Profile("BATCH")
HealthcheckConfigSet eventListenerAdapterHealthcheckConfigSet(
@Autowired(required = false) @Lazy Map<String, EventListenerAdapter> eventListenerAdapters) {
if (eventListenerAdapters == null || eventListenerAdapters.isEmpty()) {
return null;
}
HealthcheckConfigSet set = new HealthcheckConfigSet(HealthcheckGroup.HEALTH);
for (Entry<String, EventListenerAdapter> a : eventListenerAdapters.entrySet()) {
String key = a.getKey();
EventListenerAdapter value;
// TODO remove this when #20582 is solved
try {
value = a.getValue();
} catch (ClassCastException e) {
LOGGER.info("Cannot configure healthcheck for EventListenerAdapter " + key, e);
continue;
}
if (value == null) {
LOGGER.info("Cannot configure healthcheck for EventListenerAdapter {}: the adapter is null", key);
continue;
} else {
LOGGER.info("Configuring healthcheck for EventListenerAdapter {}", key);
Healthcheck hc = new EventListenerAdapterHealthcheck(key, value);
set.add("event-listener-adapter-" + key, hc);
}
}
return set;
} |
Francisco Lozano commented Also reproduced somewhere else (in test code) by doing: Map<String, EventListenerAdapter> beanMap = ctx.getBeansOfType(EventListenerAdapter.class);
|
Juergen Hoeller commented This is indeed a consequence of a recent change where we're never exposing |
Francisco Lozano commented One question: if I change the |
Juergen Hoeller commented We don't support nested That said, on your end, I avoid |
Francisco Lozano commented I'm still getting this:
Line 44 is: Map<String, EventListenerAdapter> beanMap = ctx.getBeansOfType(EventListenerAdapter.class); |
Francisco Lozano commented (Using Spring 5.0.1.RELEASE). |
Juergen Hoeller commented Francisco Lozano, could you please create a separate follow-up issue for this specific case? Indeed, |
Francisco Lozano commented I CANNOT reproduce with very simple code, however: @Configuration
public class ConfigClass {
@Bean
public Dummy bean1() {
return new Dummy();
}
@Bean
public Dummy bean2() {
return new Dummy();
}
@Bean
public Dummy bean3() {
return new Dummy();
}
@Bean
public Object bean4() {
return null;
}
} try (AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext()) {
ctx.register(ConfigClass.class);
ctx.refresh();
Map<String, Dummy> beans = ctx.getBeansOfType(Dummy.class);
assertNotNull(beans.get("bean1"));
assertNotNull(beans.get("bean2"));
assertNotNull(beans.get("bean3"));
assertNull(beans.get("bean4"));
} |
Juergen Hoeller commented I've managed to reproduce it next to my |
Francisco Lozano commented spring-attic/spring-framework-issues#173 managed to reproduce too. I'll open a new issue. |
Juergen Hoeller commented Yes please. For better or for worse, |
Francisco Lozano commented #20711 here it is. Thanks! |
Francisco Lozano opened SPR-16033 and commented
Offending code has been working since 4.1 at least, up until 5.0.0.RC3. It just started failing in GA.
Offending bean is defined as:
From the code, I understand that at some point the Map contained null values, and now it seems the map contains NullBean instances.
Affects: 5.0 GA
Issue Links:
@Bean
return nullReferenced from: commits c9d3c26
The text was updated successfully, but these errors were encountered: