Skip to content

Fix "argument type mismatch" on link save - #2606

Open
ruthst00 wants to merge 2 commits into
spring-projects:mainfrom
ruthst00:issue/2172
Open

ruthst00 wants to merge 2 commits into
spring-projects:mainfrom
ruthst00:issue/2172

Conversation

@ruthst00

Copy link
Copy Markdown

Fixes #2172

Root Cause & Fix (AnnotatedEventHandlerInvoker.java)

In onApplicationEvent(), when processing a LinkedEntityEvent, 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 via continue.

Test (AnnotatedEventHandlerInvokerUnitTests.java)

Added invokesOnlyMatchingLinkedEntityTypeHandlerForLinkSaveEvent() (tagged GH-2172) which registers a MultiLinkedEntityHandler with two @HandleBeforeLinkSave methods — one for TaskStatus and one for TaskCategory — and verifies that firing a BeforeLinkSaveEvent with each linked type invokes only the correct handler without throwing an exception.

The commit (16382620) includes Signed-off-by: ruthes00 <ruthes00@gmail.com> and @author Steve Rutherford in both changed file headers.

  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

…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>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"argument type mismatch" on link save

2 participants