Skip to content

fix: prevent NPE in validateDouble/validateFloat when input is null#6855

Open
anuragg-saxenaa wants to merge 2 commits intoaws:masterfrom
anuragg-saxenaa:fix/issue-6639-validate-double-null-npe
Open

fix: prevent NPE in validateDouble/validateFloat when input is null#6855
anuragg-saxenaa wants to merge 2 commits intoaws:masterfrom
anuragg-saxenaa:fix/issue-6639-validate-double-null-npe

Conversation

@anuragg-saxenaa
Copy link
Copy Markdown

Description

ConverterUtils.validateDouble(Double) and validateDouble(Float) accept boxed wrapper types but pass them directly to Double.isNaN() / Double.isFinite(), which take primitive double. Java auto-unboxes the wrapper before calling the method — if the wrapper is null, this auto-unboxing causes a NullPointerException.

This crash surfaces in practice when using Map<String, Double> or List<Double> DynamoDB attributes where one of the collection values is explicitly null.

Root Cause

// Before fix — crashes if input == null
public static void validateDouble(Double input) {
    Validate.isTrue(!Double.isNaN(input), "NaN is not supported by the default converters.");
    //                              ^^^^^ auto-unboxing: NPE if input == null
    Validate.isTrue(Double.isFinite(input), "Infinite numbers are not supported by the default converters.");
}

Fix

Added a null guard at the top of both validateDouble and validateFloat:

public static void validateDouble(Double input) {
    if (input == null) {
        return;  // null is a valid DynamoDB NULL; handled by converters separately
    }
    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.");
}

Tests

Added ConverterUtilsTest covering:

Fixes #6639

…ws#6639)

Double.isNaN() and Double.isFinite() accept primitive double — Java
auto-unboxes the wrapper Double, which throws NullPointerException if
the wrapper is null. This crash surfaces when a Map<String,Double> or
List<Double> stored in DynamoDB contains an explicit null value.

Add a null guard at the top of both validateDouble() and validateFloat()
that returns early; null is a valid DynamoDB NULL attribute value and the
converters already handle null separately via transformFrom/transformTo.

Also add ConverterUtilsTest covering null, NaN, infinite, and finite
inputs for both methods.

Fixes aws#6639

Signed-off-by: anuragg-saxenaa <anuragg.saxenaa@gmail.com>
@anuragg-saxenaa anuragg-saxenaa requested a review from a team as a code owner April 12, 2026 16:01
…#6578)

RetryableStage caught SdkException and IOException but not
UncheckedIOException (which extends RuntimeException, not IOException).
When the HTTP client throws UncheckedIOException, it bypassed the catch
block entirely and was never offered to the retry strategy predicates,
so retryOnException(UncheckedIOException.class) had no effect.

Add UncheckedIOException to the multi-catch so it is forwarded to
RetryableStageHelper.tryRefreshToken and evaluated against user-supplied
retry predicates like any other retriable exception.

Fixes aws#6578

Signed-off-by: anuragg-saxenaa <anuragg.saxenaa@gmail.com>
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.

NullPointerException in DefaultAttributeConverterProvider when validating null Double values

1 participant