spring-cloud / spring-cloud-function

Apache License 2.0
1.04k stars 615 forks source link

4.1.3 getting ClassCastException when integrating with AWS lambda functions #1161

Open danMarshmallow opened 2 months ago

danMarshmallow commented 2 months ago

bump to version 4.1.3 breaking our integration to aws lambda with this stack trace:

class [B cannot be cast to class XXX.events.LambdaBatch ([B is in module java.base of loader 'bootstrap'; 
XXX.events.LambdaBatch is in unnamed module of loader com.amazonaws.services.lambda.runtime.api.client.CustomerClassLoader @3cc41abc): java.lang.ClassCastException
java.lang.ClassCastException: class [B cannot be cast to class XXX.events.LambdaBatch ([B is in module java.base of loader 'bootstrap'; XXX.events.LambdaBatch is in unnamed module of loader com.amazonaws.services.lambda.runtime.api.client.CustomerClassLoader @3cc41abc)
    at XXX.lambdas.AddOnLoggingLambda.accept(AddOnLoggingLambda.java:19)
    at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.invokeConsumer(SimpleFunctionRegistry.java:1063)
    at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.doApply(SimpleFunctionRegistry.java:761)
    at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.apply(SimpleFunctionRegistry.java:592)
    at org.springframework.cloud.function.adapter.aws.FunctionInvoker.handleRequest(FunctionInvoker.java:91)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)

the class that throwing the exception looks like that:

import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.function.Consumer;

@Slf4j
@Component
@RequiredArgsConstructor
public class AddOnLoggingLambda implements Consumer<LambdaBatch> {

    @Override
    public void accept(final LambdaBatch events) {
        // logic here
    }
}
olegz commented 2 days ago

Any chance you can provide a reproducible sample?