Skip to content

NullPointerException in DefaultAttributeConverterProvider when validating null Double values #6639

@kelvin-cheng-git

Description

@kelvin-cheng-git

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

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.needs-reviewThis issue or PR needs review from the team.p2This is a standard priority issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions