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.

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

See original GitHub issue

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

github_iconTop GitHub Comments

2reactions
steven-aertscommented, Feb 27, 2021

Hi, I am perfectly aware of that.

I am just saying that if you use by accident an Object you get the above stack trace due to a bug in the DefaultAttributeConverterProvider. Where its code on a few places says:

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

While it should be:

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

Or even:

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

So the code does not give that strange stacktrace, but hits the correct error message:

.orElseThrow(() -> new IllegalStateException("Converter not found for " + type))
0reactions
chryliscommented, Aug 29, 2022

I just ran across this problem myself. If Object is not supported (annoying but something I can deal with), then trying to map an Object field 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 the DefaultAttributeConverterProvider).

Read more comments on GitHub >

github_iconTop 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 >

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