Skip to content

[#4579] Invoke the subtype handler over a shadowed supertype handler#4733

Merged
smcvb merged 1 commit into
AxonIQ:mainfrom
Develop-KIM:bug/4579/shadowed-supertype-handler
Jul 13, 2026
Merged

[#4579] Invoke the subtype handler over a shadowed supertype handler#4733
smcvb merged 1 commit into
AxonIQ:mainfrom
Develop-KIM:bug/4579/shadowed-supertype-handler

Conversation

@Develop-KIM

Copy link
Copy Markdown
Contributor

Issue

Closes #4579.

Annotated message handling components could invoke a private handler declared in a supertype instead of the matching handler declared in the actual (inspected) type.

Root cause

AnnotatedHandlerInspector#getUniqueHandlers returned, per method signature, the first member in HandlerComparator order. The comparator's final tiebreaker is Executable#toGenericString(), which orders by the declaring class name. When a supertype and the inspected subtype declare a handler with the same signature (same priority, payload type and parameters), the supertype was selected whenever its class name sorts first lexically.

For public/protected methods this is invisible, because reflective invocation is virtually dispatched to the subtype's override. For private methods there is no virtual dispatch, so the supertype's implementation was actually executed.

Fix

getUniqueHandlers now keeps, per method signature, the member declared by the most specific type. The subtype's own handler wins over a shadowed supertype handler, while an inherited handler that is not shadowed by the subtype is still used — so a private handler declared only in a base class keeps working for subtype instances.

Tests

Added two behavioural tests to AnnotatedEventHandlingComponentTest:

  • a supertype and a subtype both declaring a private @EventHandler → the subtype's handler is invoked (fails before the fix);
  • a subtype without its own handler → the private supertype handler is still invoked (guards against over-filtering).

./mvnw -pl messaging,modelling test passes.

Note

This change was prepared with AI assistance; I have reviewed and verified the analysis, fix and tests locally.

…ndler

When a supertype and a subtype declare a message handler with the same
signature, AnnotatedHandlerInspector#getUniqueHandlers kept the first
member in HandlerComparator order. Its final tiebreaker is the
Executable's generic string, which orders by declaring-class name, so a
supertype whose name sorts first was selected. This is harmless for
public or protected methods, since reflective invocation is virtually
dispatched to the subtype, but private methods are bound statically, so
the supertype's implementation was invoked instead of the subtype's.

getUniqueHandlers now keeps, per method signature, the member declared
by the most specific type. The subtype's handler wins, while an
inherited handler that is not shadowed is still used.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Develop-KIM
Develop-KIM requested a review from a team as a code owner July 9, 2026 18:59
@Develop-KIM
Develop-KIM requested review from hatzlj, laura-devriendt-lemon and zambrovski and removed request for a team July 9, 2026 18:59
@CLAassistant

CLAassistant commented Jul 9, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@smcvb smcvb added this to the Release 5.3.0 milestone Jul 13, 2026
@smcvb smcvb added Type: Bug Use to signal issues that describe a bug within the system. Priority 3: Could Low priority. Issues that are nice to have but have a straightforward workaround. labels Jul 13, 2026

@smcvb smcvb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍

@smcvb
smcvb merged commit 15cfde9 into AxonIQ:main Jul 13, 2026
10 of 11 checks passed
@smcvb

smcvb commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Thanks for picking this up, @Develop-KIM! I've just reviewed, approved, and merged your fix. Given that it points to main, it'll be part of 5.3.0.

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

Labels

Priority 3: Could Low priority. Issues that are nice to have but have a straightforward workaround. Type: Bug Use to signal issues that describe a bug within the system.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Annotated Message Handling components might unintentionally invoke supertype handlers due to handler ordering by the AnnotatedHandlerInspector

3 participants