[Bug]: DynamoDB AttributeValueCoder cannot encode an empty list or empty map attribute
- Dominant language
- Java
- Stars
- 8.7k
- Forks
- 4.7k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 196
Description
### What happened?
`AttributeValueCoder.encode` cannot encode a DynamoDB attribute whose value is an **empty list** or an **empty map** — it throws `CoderException("Unknown Type")`.
The L and M branches are selected with a size check:
```java
} else if (value.ss() != null && value.ss().size() > 0) { // correct: DynamoDB rejects empty sets
...
} else if (value.l() != null && value.l().size() > 0) { // wrong: DynamoDB allows an empty L
} else if (value.m() != null && value.m().size() > 0) { // wrong: DynamoDB allows an empty M
} else if (value.nul() != null) {
...
} else {
throw new CoderException("Unknown Type");
}
```
For an empty `L`, `l()` is non-null and `size()` is 0, so the guard fails; `m()` and `nul()` do not match either, and it falls through to the terminal `else`.
**The blast radius is the whole item, not one attribute.** `MAP_ATTRIBUTE_CODER` re-enters this coder for every child, so a single empty list nested anywhere inside an item makes that item unencodable:
```java
Map item = new HashMap<>();
item.put("name", AttributeValue.builder().s("widget").build());
item.put("tags", AttributeValue.builder().l(new ArrayList<>()).build());
AttributeValueCoder.of().encode(AttributeValue.builder().m(item).build(), out);
// CoderException: Unknown Type
```
Empty `L` and `M` are valid DynamoDB attribute values and the service returns them, unlike the `SS`/`NS`/`BS` set types where the `size() > 0` guard is legitimate — DynamoDB rejects empty sets.
The `decode` side already copes: `case l:` and `case m:` delegate to `ListCoder`/`MapCoder`, which round-trip empties fine. Only `encode` rejects them.
### Issue Priority
Priority: 2 (default / most bugs should be filed as P2)
### Issue Components
- [x] Component: Java SDK
- [x] Component: IO connector
Contributor guide
Research direction
Start at the AttributeValueCoder.encode entry point and inspect the L and M branches, along with MAP_ATTRIBUTE_CODER and the existing ListCoder/MapCoder behavior used by decode. Verify that empty lists and maps, including nested values, encode successfully while empty set handling remains unchanged, and run the relevant Java SDK IO connector tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100