-
Notifications
You must be signed in to change notification settings - Fork 970
Description
Describe the bug
I have encountered a NullPointerException when using the DynamoDB Enhanced Client. The crash occurs specifically when validateDouble is called with a null value.
The issue stems from the fact that Double.isNaN() and Double.isFinite() accept primitive double arguments. When a Double wrapper object is passed to these methods, Java attempts to auto-unbox it (calling .doubleValue()). If the wrapper object is null, this results in an NPE.
Expected Behavior
The validator should gracefully handle null values, likely by ignoring them (returning early) or checking for nullity before attempting to unbox.
Current Behavior
The application crashes with a NullPointerException when attempting to convert/validate a null Double attribute.
Reproduction Steps
This issue is most commonly triggered when using a Map<String, Double> or List<Double> where one of the values inside the collection is explicitly null or NULL type in DynamoDB.
Code causing the issue:
The problematic code is located in software.amazon.awssdk.enhanced.dynamodb.internal.converter.attribute.DefaultAttributeConverterProvider.
// Current implementation in SDK
public static void validateDouble(Double input) {
// input is auto-unboxed here, causing NPE if input is null
Validate.isTrue(!Double.isNaN(input), "NaN is not supported by the default converters.");
Validate.isTrue(Double.isFinite(input), "Infinite numbers are not supported by the default converters.");
}Possible Solution
Add a null check before the validation logic:
public static void validateDouble(Double input) {
if (input == null) {
return;
}
Validate.isTrue(!Double.isNaN(input), "NaN is not supported by the default converters.");
Validate.isTrue(Double.isFinite(input), "Infinite numbers are not supported by the default converters.");
}Additional Information/Context
Stack Trace:
java.lang.NullPointerException
at software.amazon.awssdk.enhanced.dynamodb.internal.converter.attribute.DefaultAttributeConverterProvider.validateDouble(DefaultAttributeConverterProvider.java:...)
at software.amazon.awssdk.enhanced.dynamodb.internal.converter.attribute.DoubleAttributeConverter.transformFrom(DoubleAttributeConverter.java:...)
...
AWS Java SDK version used
2.38.7
JDK version used
21.0.7.6
Operating System and version
Windows 11 Pro 24H2