quarkusio/quarkus · error · IllegalStateException

Unable to find handleRequest method in <handlerClass.getName

Error message

Unable to find handleRequest method in <handlerClass.getName()>

What it means

AmazonLambdaRecorder.initializeHandlerClass uses reflection to locate the handleRequest(InputType, Context) method on the handler's host class for collection-input handlers. If that method signature cannot be found (or reflection otherwise fails), it throws IllegalStateException wrapping the cause, naming the handler class.

Source

Thrown at extensions/amazon-lambda/runtime/src/main/java/io/quarkus/amazon/lambda/runtime/AmazonLambdaRecorder.java:67

    public void setStreamHandlerClass(Class<? extends RequestStreamHandler> handler) {
        streamHandlerClass = handler;
    }

    static void initializeHandlerClass(RequestHandlerDefinition requestHandlerDefinition) {
        handlerClass = requestHandlerDefinition.handlerClass();
        ObjectMapper objectMapper = AmazonLambdaMapperRecorder.objectMapper;

        if (requestHandlerDefinition.inputType().equals(S3Event.class)) {
            objectReader = new S3EventInputReader(objectMapper);
        } else if (Collection.class.isAssignableFrom(requestHandlerDefinition.inputType())) {
            // we have to use reflection to figure out the element generic type
            try {
                Method handleRequestMethod = requestHandlerDefinition.handleRequestMethodHostClass().getMethod("handleRequest",
                        requestHandlerDefinition.inputType(), Context.class);
                objectReader = new CollectionInputReader<>(objectMapper, handleRequestMethod.getGenericParameterTypes()[0]);
            } catch (Exception e) {
                throw new IllegalStateException("Unable to find handleRequest method in " + handlerClass.getName(), e);
            }
        } else {
            objectReader = new JacksonInputReader(objectMapper.readerFor(requestHandlerDefinition.inputType()));
        }

        Class<?> outputTypeForWriter = requestHandlerDefinition.outputType();
        if (Record.class.equals(requestHandlerDefinition.outputType())) {
            // Jackson won't properly serialize if the type is `Record`
            outputTypeForWriter = Object.class;
        }
        objectWriter = new JacksonOutputWriter(objectMapper.writerFor(outputTypeForWriter));
    }

    public void setBeanContainer(BeanContainer container) {
        beanContainer = container;
    }

    /**

View on GitHub (pinned to e1c734241f)

Solutions

  1. Implement exactly handleRequest(InputType, Context) with the concrete input type in the class named as the handler
  2. Ensure the handler class declares concrete generics (e.g. implements RequestHandler<MyIn, MyOut>), not raw types
  3. Rebuild so the deployment and handler definitions agree on the input type
  4. Check the wrapped cause for the exact reflection error (NoSuchMethodException etc.)

Example fix

// before
class MyHandler implements RequestHandler<Map<String, Object>, String> { // raw/erased usage
    public String handleRequest(Object in, Context ctx) {...}
}
// after
class MyHandler implements RequestHandler<Map<String, Object>, String> {
    public String handleRequest(Map<String, Object> in, Context ctx) {...}
}
Defensive patterns

Strategy: validation

Validate before calling

// build-time check: ensure the handler exposes the exact signature
Class<?> h = MyHandler.class;
Method m;
try {
    m = h.getMethod("handleRequest", Map.class, Context.class);
} catch (NoSuchMethodException e) {
    throw new IllegalStateException("handler must declare handleRequest(InputType, Context)", e);
}

Type guard

static boolean hasHandleRequest(Class<?> c, Class<?> input) {
    try { c.getMethod("handleRequest", input, Context.class); return true; }
    catch (NoSuchMethodException e) { return false; }
}

Try / catch

try { deploy(handler); } catch (IllegalStateException e) { throw new AssertionError("Bad handler signature: " + e.getCause(), e); }

Prevention

When it happens

Trigger: Deploying a handler implementing a collection/generic RequestHandler whose host class lacks a handleRequest(InputType, Context) method matching the declared generic types — e.g. wrong generics, renamed/overloaded method, or native-image reflection issues.

Common situations: Generic RequestHandler<Input,Output> implementations where type erasure confuses the resolved host class; handlers implemented via intermediate abstract classes; signature mismatch after refactoring.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/d777eef9bbcad4dc. Report an issue: GitHub.