`DefaultAttributeConvererProvider` throws `IndexOutOfBoundException` on `Object` class
- Lingua principale
- Java
- Stelle
- 2.6k
- Fork
- 1k
- Merge medio
- 2g 9h
- PR unite (30g)
- 51
Descrizione
`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
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia in services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/DefaultAttributeConverterProvider.java, in particolare in findConverter e createMapConverter nelle posizioni dello stack trace. Riproduci converterFor(EnhancedType.of(Object.class)) e analizza gli altri controlli isAssignableFrom menzionati nell’issue. Il lavoro è completato quando Object e i tipi generici interessati non generano più IndexOutOfBoundsException né selezionano un converter errato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java
- Ambito
- database
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100