Fix ApplicationListenerMethodAdapter#supportsEventType check
This commit fixes the check by avoiding a fallback to eventType's hasUnresolvableGenerics(). This could previously lead to checking a generic event type `A<T>` against a listener which accepts unrelated `B` and return `true` despite the inconsistency. Note that this wouldn't necessarily surface to the user because there is a `catch (ClassCastException e)` down the line, which was primarily put in place to deal with lambda-based listeners but happens to catch an exception thrown due to the bad result of `supportsEventType`. The `supportsEventType` now matches generic `PayloadApplicationEvent` types with a raw counterpart, using the above fallback only in that case and otherwise ultimately returning `false`. Closes gh-30399
This commit is contained in:
@@ -173,12 +173,12 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe
|
||||
}
|
||||
if (PayloadApplicationEvent.class.isAssignableFrom(eventType.toClass())) {
|
||||
ResolvableType payloadType = eventType.as(PayloadApplicationEvent.class).getGeneric();
|
||||
if (declaredEventType.isAssignableFrom(payloadType)) {
|
||||
if (declaredEventType.isAssignableFrom(payloadType) || eventType.hasUnresolvableGenerics()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return eventType.hasUnresolvableGenerics();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user