Skip to content
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 double generic ApplicationEvent with 6.2.1 #34234

Closed
denAbramoff opened this issue Jan 10, 2025 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Milestone

Comments

@denAbramoff
Copy link

This issue is next step this issue.

So:

I have simple interface like this:

public interface ITest
{
}

and this:

public interface ITest2
{
}

and the simple event:

public class TestEvent<T extends ITest> extends ApplicationEvent
{
    public TestEvent(Object source)
    {
        super(source);
    }
}

and listener:

import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

@Component
public class MyListener<T extends ITest & ITest2> implements ApplicationListener<TestEvent<T>>
{
    @Override
    public void onApplicationEvent(TestEvent<T> event)
    {
        System.out.println(this.getClass() + " DONE!");
    }
}

and when i trying to send an event via the spring context like this:

public class MySpringApplication
{
    public static void main(String[] args)
    {
        ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
        context.publishEvent(new TestEvent<>(""));
    }
}

I have different result in depends on the version Spring.
When i use Spring 6.2.1 i can't see in the log anything.

when i use Spring 6.1.16 i see this result:

class ...MyListener DONE!

I guess it's a bug.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 10, 2025
@jhoeller jhoeller added the in: core Issues in core modules (aop, beans, core, context, expression) label Jan 10, 2025
@jhoeller jhoeller self-assigned this Jan 10, 2025
@jhoeller jhoeller added type: regression A bug that is also a regression and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 10, 2025
@jhoeller jhoeller added this to the 6.2.2 milestone Jan 10, 2025
@jhoeller
Copy link
Contributor

Strictly speaking, the above is actually by design, following proper multiple bounds support in 6.2: #22902

A TestEvent<T extends ITest & ITest2> is not assignable from a plain TestEvent<T extends ITest> since the latter does not match the ITest2 part of the specification. This used to be ignored by accident and has been revised in 6.2 to actually honor all such bounds.

That said, there is nevertheless a revision of the algorithm coming up in 6.2.2 which also includes a fix for multiple bounds matching: #34119

So if TestEvent itself is declared as public class TestEvent<T extends ITest & ITest2>, the above will work as of 6.2.2 now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

3 participants