dynamodb-enhanced cannot be used with GraalVM 21.1
See original GitHub issueHi,
I’m trying to compile dynamodb-enhanced client with Graalvm 21.1 and awssdk.version=2.16.50
Here the code:
DynamoDbTable<Book> dynamoDbTable = dynamoDbEnhancedClient.table(TABLE_NAME, TableSchema.fromBean(Book.class));
Reflection config doesn’t help. I generated native-image artifacts with -agentlib: but it still doesn’t help. GraalVM 21.1 supports Method Handler, I hope it can be fixed. https://github.com/aws/aws-sdk-java-v2/blob/master/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/mapper/LambdaToMethodBridgeBuilder.java#L76
Error:
Exception in thread "main" java.lang.ExceptionInInitializerError at com.oracle.svm.core.classinitialization.ClassInitializationInfo.initialize(ClassInitializationInfo.java:315) Caused by: java.lang.IllegalArgumentException: Failed to generate method handle. at software.amazon.awssdk.enhanced.dynamodb.internal.mapper.LambdaToMethodBridgeBuilder.build(LambdaToMethodBridgeBuilder.java:92) at software.amazon.awssdk.enhanced.dynamodb.internal.mapper.ObjectConstructor.create(ObjectConstructor.java:37) at software.amazon.awssdk.enhanced.dynamodb.mapper.BeanTableSchema.newObjectSupplierForClass(BeanTableSchema.java:361) at software.amazon.awssdk.enhanced.dynamodb.mapper.BeanTableSchema.createStaticTableSchema(BeanTableSchema.java:172) at software.amazon.awssdk.enhanced.dynamodb.mapper.BeanTableSchema.create(BeanTableSchema.java:129) at software.amazon.awssdk.enhanced.dynamodb.mapper.BeanTableSchema.create(BeanTableSchema.java:121) at software.amazon.awssdk.enhanced.dynamodb.TableSchema.fromBean(TableSchema.java:81) at com.filichkin.blog.lambda.v3.handler.test.Main.initDispatcher(Main.java:39)
No problem with simple dynamoDb client, it can be compiled with GraalVM
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:5 (1 by maintainers)
Hello! I am currently looking to make dynamodb-enhanced (specifically the BeanTableSchema) compatible with graalvm native image and quarkus.
I looked into this issue and found out that the error message is misleading. The problem has nothing to do with
MethodHandle
s (they are fully supported) but rather with using the LambdaMetafactory. Behind the scenes it creates a lambda class which is then attempted to be loaded but loading a class is not possible because everything in a native image is pre-compiled.My solution to this problem currently is to substitute the use of the LambdaMetafactory for the native-image with a MethodHandle and an inner class which seems to work fine (minus the likely performance hit).
While trying to fix this particular problem I stumbled upon another issue with the LambdaToMethodBridgeBuilder. It uses the Lookup wrong and crashes if the bean class is loaded in a different classloader than the AWS SDK, but this is probably better dicussed in another issue.
I have made a proof of concept as quarkus extension which at least seems to work for my very basic test case https://github.com/Nithanim/quarkus-dynamodb-enhanced.
Hi @Aleksandr-Filichkin thanks for reporting the issue. We will investigate to see if we can fix it for
BeanTableSchema
. I should note thatStaticTableSchema
might work better for GraalVM native image since it doesn’t involve any reflections.Test code: https://github.com/aws/aws-sdk-java-v2/blob/8763931a0fe92081f7ddfc7f6d18213da55c92fd/test/sdk-native-image-test/src/main/java/software/amazon/awssdk/nativeimagetest/DynamoDbEnhancedClientTestRunner.java#L39-L62