Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "Amazon DynamoDB Enhanced Client",
"contributor": "",
"description": "Fix NullPointerException in `DoubleAttributeConverter` and `FloatAttributeConverter` when input is null. Fixes [#6639](https://github.com/aws/aws-sdk-java-v2/issues/6639)."
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ private ConverterUtils() {
* @param input
*/
public static void validateDouble(Double input) {
Validate.paramNotNull(input, "input");
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.");
}
Expand All @@ -48,6 +49,7 @@ public static void validateDouble(Double input) {
* @param input
*/
public static void validateFloat(Float input) {
Validate.paramNotNull(input, "input");
Validate.isTrue(!Float.isNaN(input), "NaN is not supported by the default converters.");
Validate.isTrue(Float.isFinite(input), "Infinite numbers are not supported by the default converters.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package software.amazon.awssdk.enhanced.dynamodb.converters.attribute;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.data.Offset.offset;
import static software.amazon.awssdk.enhanced.dynamodb.converters.attribute.ConverterTestUtils.assertFails;
import static software.amazon.awssdk.enhanced.dynamodb.converters.attribute.ConverterTestUtils.transformFrom;
Expand Down Expand Up @@ -150,6 +151,9 @@ public void floatAttributeConverterBehaves() {
assertFails(() -> transformFrom(converter, Float.NEGATIVE_INFINITY));
assertFails(() -> transformFrom(converter, Float.POSITIVE_INFINITY));
assertFails(() -> transformFrom(converter, Float.NaN));
assertThatThrownBy(() -> transformFrom(converter, null))
.isInstanceOf(NullPointerException.class)
.hasMessageContaining("input must not be null");

assertThat(transformFrom(converter, -Float.MAX_VALUE).n()).isEqualTo("-3.4028235E38");
assertThat(Float.parseFloat(transformFrom(converter, -42.42f).n())).isCloseTo(-42.42f, offset(1E-10f));
Expand Down Expand Up @@ -179,6 +183,9 @@ public void doubleAttributeConverterBehaves() {
assertFails(() -> transformFrom(converter, Double.NEGATIVE_INFINITY));
assertFails(() -> transformFrom(converter, Double.POSITIVE_INFINITY));
assertFails(() -> transformFrom(converter, Double.NaN));
assertThatThrownBy(() -> transformFrom(converter, null))
.isInstanceOf(NullPointerException.class)
.hasMessageContaining("input must not be null");

assertThat(transformFrom(converter, -Double.MAX_VALUE).n()).isEqualTo("-1.7976931348623157E308");
assertThat(Double.parseDouble(transformFrom(converter, -42.42d).n())).isCloseTo(-42.42d, offset(1E-10));
Expand Down
Loading