DynamoDB enhanced client: TableSchema<T>.attributeValue method throws NullPointerException when retrieving value of an attribute of a flattened model
- Dominant language
- Java
- Stars
- 2.6k
- Forks
- 1k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 51
Description
### Describe the bug
When calling `TableSchema.attributeValue` on an attribute of a flattened model, method throws a `NullPointerException` if the value of the attribute is currently set to null. If attribute's value is not null or the whole flattened model is null, method behaves as expected.
### Expected Behavior
Expected behavior for `TableSchema.attributeValue` would be to return `null` or `AttributeValue` wrapped `null`.
### Current Behavior
Currently `TableSchema.attributeValue` throws a `NullPointerException`
### Reproduction Steps
```java
@DynamoDbBean
public class FlattenedModel {
private String attribute;
public FlattenedModel() {
}
public FlattenedModel(String attribute) {
this.attribute = attribute;
}
public String getAttribute() {
return attribute;
}
public void setAttribute(String attribute) {
this.attribute = attribute;
}
}
@DynamoDbBean
public class Model {
private FlattenedModel flattenedModel;
public Model() {
}
public Model(FlattenedModel flattenedModel) {
this.flattenedModel = flattenedModel;
}
@DynamoDbFlatten
public FlattenedModel getFlattenedModel() {
return flattenedModel;
}
public void setFlattenedModel(FlattenedModel flattenedModel) {
this.flattenedModel = flattenedModel;
}
}
public class Main {
public static void main(String[] args) {
TableSchema schema = TableSchema.fromClass(Model.class);
var model = new Model();
model.setFlattenedModel(new FlattenedModel(null));
var value = schema.attributeValue(model, "attribute");
}
}
```
### Possible Solution
_No response_
### Additional Information/Context
```
Exception in thread "main" java.lang.NullPointerException
at software.amazon.awssdk.enhanced.dynamodb.internal.EnhancedClientUtils.isNullAttributeValue(EnhancedClientUtils.java:187)
at software.amazon.awssdk.enhanced.dynamodb.mapper.StaticImmutableTableSchema$FlattenedMapper.attributeValue(StaticImmutableTableSchema.java:144)
at software.amazon.awssdk.enhanced.dynamodb.mapper.StaticImmutableTableSchema$FlattenedMapper.access$1300(StaticImmutableTableSchema.java:91)
at software.amazon.awssdk.enhanced.dynamodb.mapper.StaticImmutableTableSchema.attributeValue(StaticImmutableTableSchema.java:559)
at software.amazon.awssdk.enhanced.dynamodb.mapper.WrappedTableSchema.attributeValue(WrappedTableSchema.java:77)
at software.amazon.awssdk.enhanced.dynamodb.mapper.WrappedTableSchema.attributeValue(WrappedTableSchema.java:77)
at org.example.Main.main(Main.java:22)
```
### AWS Java SDK version used
2.20.105
### JDK version used
openjdk version "11.0.18" 2023-01-17 LTS OpenJDK Runtime Environment Corretto-11.0.18.10.1 (build 11.0.18+10-LTS) OpenJDK 64-Bit Server VM Corretto-11.0.18.10.1 (build 11.0.18+10-LTS, mixed mode)
### Operating System and version
Linux pc 6.3.8-arch1-1 #1 SMP PREEMPT_DYNAMIC Wed, 14 Jun 2023 20:10:31 +0000 x86_64 GNU/Linux
Contributor guide
Assessment
This issue has not been assessed yet.