Fix NPE for null values in Map and List collection attribute converters#6782
Fix NPE for null values in Map and List collection attribute converters#6782S-Saranya1 wants to merge 1 commit intomasterfrom
Conversation
|
|
I think one more option is to fix in the Map and list AttributeConverter to handle the null values and keys and null list objects and |
Considered fixing at the Map/List converter level, but it would introduce a behavioral change for |
No I think it will not introduce behavioural change if we do as below public EnhancedAttributeValue toAttributeValue(T input) {
Map<String, AttributeValue> result = new LinkedHashMap<>();
input.forEach((k, v) -> result.put(keyConverter.toString(k),
v == null ? AttributeValue.fromNul(true)
: valueConverter.transformFrom(v)));
return EnhancedAttributeValue.fromMap(result);
}Here if its a null then we set to We can write paramaterized test to make sure this is backward compatible with all types. |
20eed83 to
cf36aa0
Compare


MapAttributeConverter and ListAttributeConverter pass null collection values/elements directly to element converters without null-checking. For converters like DoubleAttributeConverter and FloatAttributeConverter, this causes a NullPointerException due to auto-unboxing in ConverterUtils.validateDouble()/validateFloat(). This occurs when users persist a Map<String, Double> or List containing null values.
Motivation and Context
DynamoDB has a first-class NULL type for representing absent values. When a Java collection contains null elements, the SDK should convert them to DynamoDB NULL(nul(true)) rather than passing them to element converters that aren't designed to handle null. The existing pattern in ResolvedImmutableAttribute already does this for top-level attributes — this fix applies the same approach to collection converters.
Modifications
Testing
Screenshots (if appropriate)
Types of changes
Checklist
mvn installsucceedsscripts/new-changescript and following the instructions. Commit the new file created by the script in.changes/next-releasewith your changes.License