Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DefaultAttributeConverterProvider throws IndexOutOfBoundException on List class #3626

Closed
eduardo-rdgz opened this issue Dec 14, 2022 · 3 comments
Assignees
Labels
bug This issue is a bug. p2 This is a standard priority issue

Comments

@eduardo-rdgz
Copy link

Describe the bug

Similar to #2296

Class DefaultAttributeConverterProvider throws IndexOutOfBoundException when using the List class. This for the TableSchema builder.

If I have a List<String> field in the class:

private List<String> faceMatchErrors;

Then for the TableSchema.builder():

.addAttribute(List.class, a ->
                    a.name("faceMatchErrors").getter(Transaction::getFaceMatchErrors).setter(Transaction::setFaceMatchErrors))

Expected Behavior

This should return the (AttributeConverter<T>) ListAttributeConverter.create(innerConverter) for the List<String> field.

Current Behavior

This throws:

Caused by: java.lang.IndexOutOfBoundsException: Index: 0
	at java.base/java.util.Collections$EmptyList.get(Collections.java:4483)
	at software.amazon.awssdk.enhanced.dynamodb.DefaultAttributeConverterProvider.findConverterInternal(DefaultAttributeConverterProvider.java:163)
	at software.amazon.awssdk.enhanced.dynamodb.DefaultAttributeConverterProvider.findConverter(DefaultAttributeConverterProvider.java:143)
	at software.amazon.awssdk.enhanced.dynamodb.DefaultAttributeConverterProvider.converterFor(DefaultAttributeConverterProvider.java:135)

This is caused by line 163 in DefaultAttributeConverterProvider

EnhancedType<T> innerType = (EnhancedType<T>) type.rawClassParameters().get(0);

Since rawClassParameters is an Empty List.

Reproduction Steps

Just create a table schema builder with a List.class attribute.

Possible Solution

I had to manually create the AttributeConverter

(AttributeConverter) ListAttributeConverter.create(StringAttributeConverter.create()))
.addAttribute(List.class, a ->
                    a.name("faceMatchErrors").getter(Transaction::getFaceMatchErrors).setter(Transaction::setFaceMatchErrors)
                            .attributeConverter( (AttributeConverter) ListAttributeConverter.create(StringAttributeConverter.create())) )

Based on the default provider code, this has to be done automatically.

Additional Information/Context

I'm not using annotations due to introspection problems and compatibility with Micronaut and GraalVM. Using the TableSchema.fromClass(Transaction.class) gets this field right without problems.

AWS Java SDK version used

2.17.271

JDK version used

openjdk version "11.0.15"

Operating System and version

Linux

@eduardo-rdgz eduardo-rdgz added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 14, 2022
@debora-ito
Copy link
Member

Does it work out of the box if you replace List.class with EnhancedType.listOf(String.class)?

.addAttribute(EnhancedType.listOf(String.class), a -> a.name("faceMatchErrors")
        .getter(Transaction::getFaceMatchErrors)
        .setter(Transaction::setFaceMatchErrors))

@debora-ito debora-ito removed the needs-triage This issue or PR still needs to be triaged. label Mar 29, 2023
@debora-ito debora-ito self-assigned this Mar 29, 2023
@debora-ito debora-ito added the p2 This is a standard priority issue label Mar 29, 2023
@eduardo-rdgz
Copy link
Author

Yes it works like that. I figured it out a day after this ticket.
This is the key part:

EnhancedType.listOf(String.class)

I did not see it in the main documentation, I had to check other repos/answers for this example.
Thanks.

@github-actions
Copy link

github-actions bot commented Apr 1, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

2 participants