-
Notifications
You must be signed in to change notification settings - Fork 38.2k
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
ApplicationListener
no longer invoked for generic ApplicationEvent
with 6.2.0
#33982
Comments
If you make the parameterized type for context.publishEvent(new TestEvent<ITest>("") {}); Note the use of So this might have been a bug fix instead of a bug/regression. @jhoeller, thoughts? |
The following all-in-one test class demonstrates this. @SpringJUnitConfig
class GenericApplicationEventListenerTests {
@Test
void test(ApplicationContext context) {
context.publishEvent(new TestEvent<ITest>("") {
});
}
@Configuration
@Import({MethodListener.class, SimpleTestListener.class})
static class Config {
}
interface ITest {
}
static class TestEvent<T extends ITest> extends ApplicationEvent {
TestEvent(Object source) {
super(source);
}
}
static class MethodListener {
@EventListener
public void handleTestEvent(TestEvent<ITest> iTest) {
System.err.println(getClass().getSimpleName() + " DONE!");
}
}
static class SimpleTestListener implements ApplicationListener<TestEvent<ITest>> {
@Override
public void onApplicationEvent(TestEvent<ITest> event) {
System.err.println(getClass().getSimpleName() + " DONE!");
}
}
} Output:
|
ApplicationListener
no longer invoked for generic ApplicationEvent
with 6.2.0
Hi @sbrannen, I'm a Java developer who want to contribute to the framework. How can I get this issue/task assigned (to me)? Thanks |
@sbrannen thanks for your reaction! Yep, this version works: context.publishEvent(new TestEvent<ITest>("") {}); But it's not convenient and there are a lot of places where old version works. And there is also one weird case, if i add "? extends" my listenerer will work: @Configuration
public class WildcardSimpleTestListener implements ApplicationListener<TestEvent<? extends ITest>>
{
@Override
public void onApplicationEvent(TestEvent<? extends ITest> event)
{
System.out.println(this.getClass() + " DONE!");
}
} It works on Spring 6.2! class ...WildcardSimpleTestListener$$SpringCGLIB$$0 DONE! |
Probably related to #33968. |
Thanks for the feedback, @denAbramoff. In light of the above, I believe this is a regression, and we'll look into it. @jhoeller, I have tentatively assigned this to you due to your work on related issues. Potentially Related Issues
|
Hi @anaconda875, Thanks for the offer! As you can see above, I've assigned to this @jhoeller, since he has done the most recent work in this area. However, if you feel confident in fixing this regression, please post your ideas here first before submitting a PR. |
Hi @sbrannen , WildcardBounds ourBounds = WildcardBounds.get(this); //ourBounds IS NULL SINCE this PASSED TO WildcardBounds.get() IS A ResolvableType OF ITest
WildcardBounds typeBounds = WildcardBounds.get(other); //typeBounds IS NOT NULL SINCE other PASSED TO WildcardBounds.get() IS ResolvableType OF <T extends ITest> Inside red circle is newly added. |
This turned out to be rather involved, a consequence of the partial generics matching that we do as of 6.2 now where we also take the bounds of an unresolvable type variable into account. The solution that I went with is a rather minimal tweaking of the existing @anaconda875 I ended up with a different approach but thanks for the PR in any case! |
I tested with Thanks, Juergen! |
Hello!
I have simple interface like this:
and the simple event:
and two listeners:
and when i trying to send an event via the spring context like this:
i have different result in depends on the version Spring. When i use Spring 6.2 i can see in the log this:
when i use Spring 6.1.15 i see both results:
I guess it's a bug.
The text was updated successfully, but these errors were encountered: