Skip to content

fix(ric): resolve generic method types against handler class hierarchy - #670

Open
mayankcodes-dev wants to merge 1 commit into
aws:mainfrom
mayankcodes-dev:fix/generic-method-handler-types
Open

mayankcodes-dev wants to merge 1 commit into
aws:mainfrom
mayankcodes-dev:fix/generic-method-handler-types

Conversation

@mayankcodes-dev

Copy link
Copy Markdown

Issue #, if available:
Fixes #552

Description of changes:
When configuring a Lambda handler with method-name syntax (ClassName::methodName), EventHandlerLoader.getHandlerFromOverload previously passed Method.getGenericReturnType() and Method.getGenericParameterTypes() without resolving class-level type variables against the concrete handler subclass. In contrast, class-name syntax (ClassName) resolved RequestHandler<I, O> type arguments via findInterfaceParameters and ClassContext.

This left inherited generic parameters/return types as unresolved TypeVariable instances (for example InputT / OutputT), causing:

  • CustomPojoSerializer (fromJson / toJson) to receive unresolved TypeVariables instead of the concrete types.
  • Default Jackson deserialization to fall back to LinkedHashMap and fail invocation with ClassCastException.
  • Parameterized Void return types to miss isVoid(rType) and attempt response serialization.
  • Non-RequestHandler generic base classes, interface default methods, and multi-level nested generic types (List<T>, T[]) to fail type resolution.

Summary of Changes

  1. Resolve method parameter and return types against clazz in EventHandlerLoader.getHandlerFromOverload:
    • Added findClassContext(Class<?> clazz, Class<?> targetClass) using BFS over superclasses and interfaces (sharing nextClassContext traversal with findInterfaceParameters) to locate the parameterized context of m.getDeclaringClass().
    • Extended ClassContext with recursive resolveType support for TypeVariable, ParameterizedType, GenericArrayType, and WildcardType, plus lightweight ResolvedParameterizedType, ResolvedGenericArrayType, and ResolvedWildcardType implementations with standard JDK equals/hashCode/toString semantics for typeCache compatibility.
    • Matched TypeVariable by declaration identity (t.equals(variables[i])) instead of name-only equality so method-scoped type parameters are not shadowed by class-level type parameters of the same name.
  2. Unit tests in EventHandlerLoaderTest:
    • Verified CustomPojoSerializer and Jackson serialization with RequestHandler subclasses using ::handleRequest syntax.
    • Covered generic POJO base classes without RequestHandler, interface default methods, multi-level nested List<T> and T[] types, bounded generic base classes (bridge-method selection + resolution), Void return types, and method-level type-variable shadowing.

Local Verification

  • Checkstyle (build-tools/checkstyle.xml) on EventHandlerLoader.java: 0 violations.
  • Compiled with javac -source 8 -target 8.
  • EventHandlerLoaderTest (20 tests), PojoSerializerLoaderTest (6 tests), and HandlerInfoTest (13 tests): 39/39 passing (MockWebServer/JNI tests require Linux/Docker CI).

Target (OCI, Managed Runtime, both):
both

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copilot AI balanced review requested due to automatic review settings December 4, 2026 11:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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

None yet

Projects

None yet

2 participants