question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dynamodb-enhanced cannot be used with GraalVM 21.1

See original GitHub issue

Hi,

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:open
  • Created 2 years ago
  • Reactions:4
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Nithanimcommented, Jul 17, 2021

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 MethodHandles (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.

2reactions
zoewanggcommented, Apr 29, 2021

Hi @Aleksandr-Filichkin thanks for reporting the issue. We will investigate to see if we can fix it for BeanTableSchema. I should note that StaticTableSchema 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

Read more comments on GitHub >

github_iconTop Results From Across the Web

aws/aws-sdk-java-v2 - Gitter
Is dynamodb-enhanced compatible with GraalVM native? I'm getting. Exception in thread "main" java.lang.ExceptionInInitializerError at com.
Read more >
Using the DynamoDB Enhanced Client in the AWS SDK for ...
The DynamoDB enhanced client is a high-level library that is part of the AWS SDK for Java version 2 (v2). It offers a...
Read more >
aws - Bountysource
I am working on fetching items using paginated queries. For this, I have implemented the query request which uses exclusive start key to...
Read more >
Photons@Graal - Dr. Rodrigo Bruno
GraalVM is a novel Java VM implementation designed to achieve better performance (throughput, memory, and start-up latency) that can also be used to...
Read more >
Maven Archetype Catalog
... A Maven Archetype for Publishing Dropwizard-based Services on AWS' Elastic ... a aplicação JAVAEE com JARCH br.com.jarch javaee-archetype 21.1.0 Projeto ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found