`DefaultAttributeConvererProvider` throws `IndexOutOfBoundException` on `Object` class
See original GitHub issueDefaultAttributeConvererProvider 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 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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:7 (5 by maintainers)
Top Results From Across the Web
IndexOutOfBoundsException (Java Platform SE 7 )
Thrown to indicate that an index of some sort (such as to an array, to a string, or to a vector) is out...
Read more >Java ArrayList remove object - IndexOutOfBoundsException
in a class which already declares m(Object) causes m(Object) to no longer ... The ArrayList class has two overloads of the method remove...
Read more >Java Exception Handling - IndexOutOfBoundsException
The IndexOutOfBoundsException is thrown when attempting to access an invalid index within a collection, such as an array , vector , string ,...
Read more >How to prevent IndexOutOfBoundException - Salesforce Help
Ratkaisu, Objective:When trying to retrieve an object from a list/array with a specific index an IndexOutOfBoundException is thrown when the requested index ...
Read more >Try/Catch IndexOutOfBoundsException Tutorial - YouTube
This tutorial builds on concepts from my Exception Handling: Try and Catch Tutorial. One of the things that I emphasized in that tutorial...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hi, I am perfectly aware of that.
I am just saying that if you use by accident an
Objectyou get the above stack trace due to a bug in theDefaultAttributeConverterProvider. Where its code on a few places says:While it should be:
Or even:
So the code does not give that strange stacktrace, but hits the correct error message:
I just ran across this problem myself. If
Objectis not supported (annoying but something I can deal with), then trying to map anObjectfield should produce an error message of “Object is not allowed” rather than a spurious unrelated exception (which, as noted above, results from using an objectively incorrect type conditional in theDefaultAttributeConverterProvider).