Conversation
…rs exist for different linked types When a RepositoryEventHandler defines multiple @HandleBeforeLinkSave (or other LinkedEntityEvent) methods for different linked-entity types, the AnnotatedEventHandlerInvoker would invoke all handlers whose source/parent type matched, regardless of whether the linked object's type was compatible with the handler method's second parameter. This caused an IllegalArgumentException: argument type mismatch at runtime. The fix adds a type-compatibility check for the linked object against the handler method's second parameter type before invoking the method, skipping handlers whose linked-entity parameter type does not match. Fixes: spring-projectsGH-2172 Signed-off-by: ruthes00 <ruthes00@gmail.com>
Signed-off-by: ruthes00 <ruthes00@gmail.com>
ruthst00
force-pushed
the
issue/2172
branch
from
September 13, 2026 18:03
6c8786c to
bc52053
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2172
Root Cause & Fix (
AnnotatedEventHandlerInvoker.java)In
onApplicationEvent(), when processing aLinkedEntityEvent, the code correctly filtered handlers by the source/parent type but blindly passed the linked object to all matching handlers — even those whose second parameter expected a different linked-entity type. The fix adds a type-compatibility check: if the handler method has a second parameter and the linked object's type is not assignable to it, the handler is skipped viacontinue.Test (
AnnotatedEventHandlerInvokerUnitTests.java)Added
invokesOnlyMatchingLinkedEntityTypeHandlerForLinkSaveEvent()(taggedGH-2172) which registers aMultiLinkedEntityHandlerwith two@HandleBeforeLinkSavemethods — one forTaskStatusand one forTaskCategory— and verifies that firing aBeforeLinkSaveEventwith each linked type invokes only the correct handler without throwing an exception.The commit (
16382620) includesSigned-off-by: ruthes00 <ruthes00@gmail.com>and@author Steve Rutherfordin both changed file headers.