Fix NPE in DoubleAttributeConverter and FloatAttributeConverter for null input#6782
Fix NPE in DoubleAttributeConverter and FloatAttributeConverter for null input#6782S-Saranya1 wants to merge 3 commits intomasterfrom
Conversation
… replace auto-unboxing NPE
|
|
I think one more option is to fix in the Map and list AttributeConverter to handle the null values and keys and null list objects and |
Considered fixing at the Map/List converter level, but it would introduce a behavioral change for |
No I think it will not introduce behavioural change if we do as below public EnhancedAttributeValue toAttributeValue(T input) {
Map<String, AttributeValue> result = new LinkedHashMap<>();
input.forEach((k, v) -> result.put(keyConverter.toString(k),
v == null ? AttributeValue.fromNul(true)
: valueConverter.transformFrom(v)));
return EnhancedAttributeValue.fromMap(result);
}Here if its a null then we set to We can write paramaterized test to make sure this is backward compatible with all types. |


DoubleAttributeConverter.transformFrom() and FloatAttributeConverter.transformFrom() throw a cryptic NullPointerException (no message) when called with a null input due to
auto-unboxing in ConverterUtils.validateDouble()/validateFloat(). This occurs when users persist a Map<String, Double> or List containing null values.
Motivation and Context
The AttributeConverter.transformFrom() interface contract states it should raise a RuntimeException if the input is null. The existing code does throw, but accidentally via auto-unboxing — producing a bare NPE with no useful message. This fix replaces the accidental NPE with an explicit Validate.paramNotNull check that throws
NullPointerException with a clear "input must not be null" message.
Modifications
Testing
Screenshots (if appropriate)
Types of changes
Checklist
mvn installsucceedsscripts/new-changescript and following the instructions. Commit the new file created by the script in.changes/next-releasewith your changes.License