fix(dynamodb-enhanced): Fix NPE in EnhancedType for null and wildcard types#6745
Conversation
…r null values and wildcard types - Add null checks to ConverterUtils.validateDouble() and validateFloat() to prevent NPE when input is null - Add null check for rawClass in EnhancedType.hashCode() and equals() to support wildcard types (List<?>) - Add comprehensive unit tests for null handling Fixes aws#6639 Fixes aws#5890 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Hi @abhu85 Thanks for the PR! If you don't mind, could you remove the Also on the EnhancedType wildcard issue, we noticed that Thanks again for the contribution! Regards, |
…ils changes - Add null check in innerToString() for wildcard types (rawClass is null) - Add test for toString() with wildcard types - Remove ConverterUtils changes (to be submitted as separate PR per maintainer request) - Update changelog to reflect EnhancedType-only changes
|
Hi @bhoradc, Thanks for the feedback! I've addressed both requests:
Summary of changes in this PR now:
Please let me know if any further changes are needed! |
|
@abhu85 - Thanks for the quick updates. One more thing - could you update the PR description to reflect the current scope? It still references the |
|
It looks like this PR has not been active for more than five days. In the absence of more information, we will be closing this PR soon. Please add a comment to prevent automatic closure, or if the PR is already closed please feel free to open a new one. |
...namodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/EnhancedTypeTest.java
Show resolved
Hide resolved
Addresses review feedback to cover the ternary logic in equals() when comparing a wildcard type (rawClass=null) against a non-wildcard type (rawClass!=null). Tests both comparison directions.
|
Thanks for the feedback @alextwoods! I've added a test case @Test
public void wildcardType_equals_notEqualToNonWildcard() {
// A wildcard type (rawClass=null) should not be equal to a non-wildcard type (rawClass!=null)
EnhancedType<List<?>> listWithWildcard = new EnhancedType<List<?>>(){};
EnhancedType<?> wildcardType = listWithWildcard.rawClassParameters().get(0);
EnhancedType<String> nonWildcardType = EnhancedType.of(String.class);
// Wildcard vs non-wildcard should not be equal (tests both comparison directions)
assertThat(wildcardType).isNotEqualTo(nonWildcardType);
assertThat(nonWildcardType).isNotEqualTo(wildcardType);
}This exercises the ternary logic in |
|
@alextwoods The CI is failing on the API surface area check because this PR modifies public methods in Could you please add one of the following labels after review?
Thanks! |
|
|
@abhu85 - Added the |



Summary
This PR fixes NullPointerException bugs in the DynamoDB Enhanced Client's
EnhancedTypeclass when dealing with wildcard types likeList<?>.Issue #5890:
EnhancedType.hashCode(),equals(), andtoString()throw NPE when dealing with wildcard types whererawClassisnull.Root Cause
For wildcard types (e.g.,
List<?>),EnhancedTypestoresrawClass = null. The following methods called methods onrawClasswithout null checks:hashCode()calledrawClass.hashCode()equals()calledrawClass.equals()innerToString()calledrawClass.getTypeName()Changes
rawClassinhashCode(),equals(), andinnerToString()methodshashCode(),equals(), andtoString()Test Plan
EnhancedTypeTesttests pass (including 3 new tests)Test Commands
```bash
./mvnw test -pl services-custom/dynamodb-enhanced -Dtest=EnhancedTypeTest
Tests run: 26, Failures: 0, Errors: 0, Skipped: 0
```
Fixes #5890
Note: The
ConverterUtilsfix for #6639 has been moved to a separate PR: #6761