Wrong detection of event type on ApplicationListener<> when using lambdas (ClassCast Exception) [SPR-14109] #18681
Comments
Juergen Hoeller commented This is unfortunately a known limitation with lambda-defined callbacks: We cannot reliably introspect generic type declarations there upfront. That said, we should at least make our event processing defensive enough: catching |
Michael Simons commented Hello Juergen, Sorry, didn't find the other ticket. If you skip the listener, a big warning is need, i think. Just for your interest: We've been using TypeTools which are linked in the SO question in #17130 for detecting generic types of Lambdas successfully. Thanks again, |
Juergen Hoeller commented Skipping the listener in case of a |
Michael Simons commented Thanks for clarifying, now i understand, i thought you meant skipping that listener from being registered at all. |
Hans-Peter Werner commented Hello Juergen, I try to catch and log exceptions at the site where an event is fired. When a listener is throwing a ClassCastException, this happens without being noticed (provided the log-level is not debug) because of that exception being catched within the SimpleApplicationEventMulticaster. I don't know a perfect solution for that problem, but I would rather have too much exceptions than too few :) Cheers |
Juergen Hoeller commented As of 4.3.4 / 4.2.9, we're now just swallowing a |
Michael Simons commented Thanks Jürgen for the update. Good to know. |
Michael Simons opened SPR-14109 and commented
Hello there,
i hope this is indeed a Spring Framework and not a Spring Boot bug. If not, please excuse and move it to the right place.
In my application i have a WebSocketMessageBroker (enabled through
@EnableWebSocketMessageBroker
) as well as a HttpSessionEventPublisher (enabled via@Bean
) and a ApplicationListener<HttpSessionCreatedEvent>.If i use an anonymous inner class for the ApplicationListener, everything works fine.
If i use a lambda like so
the generic type of my listener is incorrectly identified and a BrokerAvailabilityEvent is passed to it leading to:
I guess that might happen with other events, too, but i noticed it in context of messaging.
I have attached a demo application that reproduces that bug.
Affects: 4.2.5
Attachments:
Issue Links:
The text was updated successfully, but these errors were encountered: