Skip to content

[Bug]: DynamoDB AttributeValueCoder cannot encode an empty list or empty map attribute #39730

Description

@PDGGK

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:

} 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:

Map<String, AttributeValue> 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

  • Component: Java SDK
  • Component: IO connector

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions