aws / aws/aws-sdk-java-v2

`DefaultAttributeConvererProvider` throws `IndexOutOfBoundException` on `Object` class

Open
#2,296 9 comments 5 reactions 0 assignees View on GitHub
bug dynamodb-enhanced p2
Dominant language
Java
Stars
2.6k
Forks
1k
Avg merge
2d 9h
Merged PRs (30d)
51

Description

`DefaultAttributeConvererProvider` of dynamodb retrieves its matched types incorrectly.
This causes it to create a wrong converter for some generic types.

## Describe the bug

The minimal reproduction scenario is:

```
new DefaultAttributeConverterProvider().converterFor(EnhancedType.of(Object.class));
```

It generates the following stacktrace:

```
java.lang.IndexOutOfBoundsException: Index: 0
at java.util.Collections$EmptyList.get(Collections.java:4456)
at software.amazon.awssdk.enhanced.dynamodb.DefaultAttributeConverterProvider.createMapConverter(DefaultAttributeConverterProvider.java:179)
at software.amazon.awssdk.enhanced.dynamodb.DefaultAttributeConverterProvider.findConverter(DefaultAttributeConverterProvider.java:149)
at software.amazon.awssdk.enhanced.dynamodb.DefaultAttributeConverterProvider.converterFor(DefaultAttributeConverterProvider.java:133)
```

## Possible Solution

I think the code should be:

```
if (type.rawClass() == Map.class) {
```

Be aware this not only happens here, but also appears on other places in this class.

The problem is caused because the [`DefaultAttributeConverterProvider`](https://github.com/aws/aws-sdk-java-v2/blob/master/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/DefaultAttributeConverterProvider.java#L148) is using the `isAssignableFrom` call. It writes:

```
if (type.rawClass().isAssignableFrom(Map.class)) {
```

## Context

Found this while writing with a converer.

## Your Environment
* AWS Java SDK version used: latest

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.