aws / aws-sdk-java-v2

The official AWS SDK for Java - Version 2
Apache License 2.0
2.16k stars 833 forks source link

DynamoDB Enhanced : Getting IndexOutOfBoundsException for missing converter #3845

Open MichalFab opened 1 year ago

MichalFab commented 1 year ago

Describe the bug

DefaultAttributeConverterProvider.findConverter(EnhancedType type) throws java.lang.IndexOutOfBoundsException: Index: 0 when cannot find a converter for Map<String,Object>.

Expected Behavior

DefaultAttributeConverterProvider.findConverter(EnhancedType type) should log "No converter available for (..)" when it cannot find a converter for Map<String, Object>.

Current Behavior

The method Optional<AttributeConverter> converter = this.findConverterInternal(type); cannot resolve finding the missing converter for objects of type Map<String, Object>. Stacktrace with error: image

Reproduction Steps

  1. Create model class with @DynamoDbBean annotation.
  2. Add a Map<String, Object> field to the created class, for example: private Map<String, Object> data;
  3. Create the DynamoDbEnhancedAsyncClient instance, e.g: ` DynamoDbAsyncClientBuilder asyncClientBuilder = DynamoDbAsyncClient.builder();

    if (endpoint != null) { try { asyncClientBuilder.endpointOverride(new URI("your endpoint)); } catch (Exception e) { logger.error("Failed to setup up custom endpoint " + endpoint, e); } }

    return DynamoDbEnhancedAsyncClient.builder() .dynamoDbClient(asyncClientBuilder.build()) .build(); }`

  4. Run the application.

Possible Solution

No response

Additional Information/Context

No response

AWS Java SDK version used

2.20.27

JDK version used

17

Operating System and version

Mac OS Ventura 13.1

debora-ito commented 1 year ago

@MichalFab we don't have a native AttributeConverter for the Object type, my guess this causing the error.

You can write a custom AttributeConverter, or use one of the types that the SDK provides a converter by default - you can see the list in the "All Known Implementing Classes" here : https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/enhanced/dynamodb/AttributeConverter.html)

We have some examples showing how to provide a custom AttributeConverter in the Enhanced Client Overview : https://github.com/aws/aws-sdk-java-v2/tree/master/services-custom/dynamodb-enhanced#control-attribute-conversion

MichalFab commented 1 year ago

@MichalFab we don't have a native AttributeConverter for the Object type, my guess this causing the error.

You can write a custom AttributeConverter, or use one of the types that the SDK provides a converter by default - you can see the list in the "All Known Implementing Classes" here : https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/enhanced/dynamodb/AttributeConverter.html)

We have some examples showing how to provide a custom AttributeConverter in the Enhanced Client Overview : https://github.com/aws/aws-sdk-java-v2/tree/master/services-custom/dynamodb-enhanced#control-attribute-conversion

@debora-ito , thanks for the response. I know that there is no dedicated converter, but it seems to me that the library should handle such a case by logging an appropriate error instead of throwing a IndexOutOfBoundsException

debora-ito commented 1 year ago

Oh I see, the "bug" threw me off. We can improve the error message, I agree. Changing this to a feature request then.