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

ApplicationListenerMethodAdapter supports non-matching generic events #30399

Closed
odrotbohm opened this issue Apr 29, 2023 · 2 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@odrotbohm
Copy link
Member

ApplicationListenerMethodAdapter wrongly indicates it would support a generic event type exposing unresolved generics, even if there's no type relationship between the events at all. See the following, failing test case:

class ApplicationListenerMethodAdapterTests {

	@Test
	void testName() throws Exception {

		var method = ApplicationListenerMethodAdapterTests.class.getDeclaredMethod("listener", SomeOtherEvent.class);
		var adapter = new ApplicationListenerMethodAdapter(null, ApplicationListenerMethodAdapterTests.class, method);

		assertThat(adapter.supportsEventType(ResolvableType.forClass(SomeGenericEvent.class))).isFalse();
	}

	@EventListener
	void listener(SomeOtherEvent event) {}

	static class SomeGenericEvent<T> {}

	static class SomeOtherEvent {}
}

Note how the adapter signals the event listener method would support SomeGenericEvent when it clearly doesn't.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 29, 2023
@sbrannen sbrannen added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) labels Apr 29, 2023
@sbrannen
Copy link
Member

Thanks for reporting the issue, @odrotbohm.

It looks like the fallback to return eventType.hasUnresolvableGenerics() in ApplicationListenerMethodAdapter.supportsEventType(ResolvableType) is the culprit.

@odrotbohm
Copy link
Member Author

Yes, I ended up at the same place. Wonder whether this needs to be augmented with at least a raw type assignability check?

odrotbohm added a commit to spring-projects/spring-modulith that referenced this issue Apr 29, 2023
…ractApplicationEventMulticaster.

AbstractApplicationEventMulticaster.supportsEvent(…) currently doesn't properly match unresolved, generic ApplicationEvents (see [0]). We now work around this problem by additionally matching the raw event types in a custom override of supportsEvent(…).

[0] spring-projects/spring-framework#30399
odrotbohm added a commit to spring-projects/spring-modulith that referenced this issue Apr 30, 2023
…ractApplicationEventMulticaster.

AbstractApplicationEventMulticaster.supportsEvent(…) currently doesn't properly match unresolved, generic ApplicationEvents (see [0]). We now work around this problem by additionally matching the raw event types in a custom override of supportsEvent(…).

[0] spring-projects/spring-framework#30399
@simonbasle simonbasle self-assigned this May 10, 2023
@simonbasle simonbasle removed the status: waiting-for-triage An issue we've not yet triaged or decided on label May 10, 2023
@simonbasle simonbasle added this to the 6.0.9 milestone May 10, 2023
odrotbohm added a commit to spring-projects/spring-modulith that referenced this issue Jul 17, 2023
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: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants