Skip to content

Revert "Fixed DynamoDbEnhancedClient TableSchema::itemToMap to handle flattened members when ignoreNulls is false (#5832) #6037

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

Closed
wants to merge 2 commits into from

Conversation

joviegas
Copy link
Contributor

@joviegas joviegas commented Apr 16, 2025

This reverts commit cd04b47.

Reverting PR#5832
because of following concerns

  1. For Nested Flatten Beans if any one is set to null explicitly then it ends in NPE
    Example
 
@DynamoDbBean
public class FlattenedImmutableBean {
    private String id;
    private LevelOneNestedClass levelOneNestedClass;
 
    @DynamoDbFlatten
    public LevelOneNestedClass getLevelOneNestedClass() {
        return levelOneNestedClass;
    }
 
    public void setLevelOneNestedClass(LevelOneNestedClass levelOneNestedClass) {
        this.levelOneNestedClass = levelOneNestedClass;
    }
 
    @DynamoDbPartitionKey
    public String getId() {
        return this.id;
    }
    public void setId(String id) {
        this.id = id;
    }
 
    @DynamoDbBean
    public static class LevelOneNestedClass {
        private LevelTwoNestedClass levelTwoNestedClass = null;
        private String idType;
 
        @DynamoDbFlatten
        public LevelTwoNestedClass getConversationState() {
            return levelTwoNestedClass;
        }
 
        public void setConversationState(LevelTwoNestedClass levelTwoNestedClass) {
            this.levelTwoNestedClass = levelTwoNestedClass;
        }
 
        public String getIdType() {
            return idType;
        }
 
        public void setIdType(String idType) {
            this.idType = idType;
        }
    }
 
    enum  LevelThreeBean {
        SUCCESS,
        FAILED
    }
 
    @DynamoDbBean
    public static class LevelTwoNestedClass {
        private LevelThreeBean levelThreeBean;
 
        public LevelTwoNestedClass() {
            this.levelThreeBean = LevelThreeBean.SUCCESS;
        }
 
        public LevelThreeBean getLevelThreeBean() {
            return levelThreeBean;
        }
 
        public void setLevelThreeBean(LevelThreeBean levelThreeBean) {
            this.levelThreeBean = levelThreeBean;
        }
    }
 
}
java.lang.NullPointerException
at software.amazon.awssdk.enhanced.dynamodb.mapper.StaticImmutableTableSchema$FlattenedMapper.itemToMap(StaticImmutableTableSchema.java:127)
at software.amazon.awssdk.enhanced.dynamodb.mapper.StaticImmutableTableSchema$FlattenedMapper.access$1400(StaticImmutableTableSchema.java:91)
at software.amazon.awssdk.enhanced.dynamodb.mapper.StaticImmutableTableSchema.lambda$itemToMap$6(StaticImmutableTableSchema.java:528)
at java.base/java.util.HashMap.forEach(HashMap.java:1421)
at java.base/java.util.Collections$UnmodifiableMap.forEach(Collections.java:1553)
at software.amazon.awssdk.enhanced.dynamodb.mapper.StaticImmutableTableSchema.itemToMap(StaticImmutableTableSchema.java:527)
at software.amazon.awssdk.enhanced.dynamodb.mapper.WrappedTableSchema.itemToMap(WrappedTableSchema.java:67)
at software.amazon.awssdk.enhanced.dynamodb.mapper.WrappedTableSchema.itemToMap(WrappedTableSchema.java:67)
at software.amazon.awssdk.enhanced.dynamodb.mapper.StaticImmutableTableSchema$FlattenedMapper.itemToMap(StaticImmutableTableSchema.java:133)
at software.amazon.awssdk.enhanced.dynamodb.mapper.StaticImmutableTableSchema$FlattenedMapper.access$1400(StaticImmutableTableSchema.java:91)
at software.amazon.awssdk.enhanced.dynamodb.mapper.StaticImmutableTableSchema.lambda$itemToMap$6(StaticImmutableTableSchema.java:528)
at java.base/java.util.HashMap.forEach(HashMap.java:1421)
at java.base/java.util.Collections$UnmodifiableMap.forEach(Collections.java:1553)
at software.amazon.awssdk.enhanced.dynamodb.mapper.StaticImmutableTableSchema.itemToMap(StaticImmutableTableSchema.java:527)
at software.amazon.awssdk.enhanced.dynamodb.mapper.WrappedTableSchema.itemToMap(WrappedTableSchema.java:67)
at software.amazon.awssdk.enhanced.dynamodb.mapper.WrappedTableSchema.itemToMap(WrappedTableSchema.java:67)

Future FIx

  • Tried fixing it quickly by returning empty map if otherItem is null but that makes ignoreNull = false not work for Second level Nesting. I think problem relates to how FlattenedMapper objects are created and indexed in the StaticImmutableTableSchema class. So this will take more time to fix

Motivation and Context

Modifications

Testing

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

License

  • I confirm that this pull request can be released under the Apache 2 license

… flattened members when ignoreNulls is false (#5832)"

This reverts commit cd04b47.
@joviegas joviegas requested a review from a team as a code owner April 16, 2025 04:23
@joviegas joviegas enabled auto-merge April 16, 2025 15:05
@joviegas joviegas added this pull request to the merge queue Apr 16, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 16, 2025
@joviegas joviegas added this pull request to the merge queue Apr 16, 2025
@joviegas joviegas removed this pull request from the merge queue due to a manual request Apr 16, 2025
@joviegas
Copy link
Contributor Author

Merged to stagging

@joviegas joviegas closed this Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants