aws / aws/aws-sdk-java-v2

NullPointerException in DefaultAttributeConverterProvider when validating null Double values

Open
#6,639 2 comments 0 reactions 0 assignees View on GitHub
bug p2
Dominant language
Java
Stars
2.6k
Forks
1k
Avg merge
2d 9h
Merged PRs (30d)
51

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` or `List` 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`.

```java
// 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:

```java
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:**
```text
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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.