apache/beam · error · IllegalArgumentException
Value cannot be null or have 0 elements
Error message
Value cannot be null or have 0 elements
What it means
OrderedCode.writeTrailingBytes appends raw trailing bytes to the ordered encoding. It rejects null or zero-length arrays with IllegalArgumentException because a zero-length trailing segment makes the encoding ambiguous/unreadable by readTrailingBytes.
Solutions
- Guard the call site: skip writeTrailingBytes when the byte array is null or empty.
- If a terminator is needed for empty payloads, write a sentinel value (e.g. a single 0x00 byte) instead.
- Catch IllegalArgumentException if empty input is a legitimate condition in your encoding flow.
Example fix
// before
oc.writeTrailingBytes(suffix);
// after
if (suffix != null && suffix.length > 0) {
oc.writeTrailingBytes(suffix);
} Defensive patterns
Strategy: validation
Validate before calling
if (value == null || value.length == 0) {
// skip write or substitute sentinel
} Type guard
boolean writableTrailing(byte[] v) { return v != null && v.length > 0; } Try / catch
try { oc.writeTrailingBytes(value); } catch (IllegalArgumentException e) { /* skip empty segment */ } Prevention
- Null/empty-check every byte payload before encoding
- Use a sentinel byte for legitimate empty payloads
- Centralize encoding helpers with input validation
When it happens
Trigger: Calling writeTrailingBytes(null) or writeTrailingBytes(new byte[0]) on an OrderedCode instance mid-encoding.
Common situations: Encoding a key component derived from a possibly-empty payload (e.g. empty suffix bytes from a parsed key) without checking length first.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- Could not encode provided windows with the provided window…
- Empty argument value is only allowed for String, String…
- Invalid encoded byte array
- 'keyField' property cannot be null.
- Text payload is not valid UTF-8.
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/fb23e0af04e35210.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/OrderedCode.java:361
*
* @see #readInfinityDecreasing()
*/
public void writeInfinityDecreasing() {
writeTrailingBytes(INFINITY_ENCODED_DECREASING);
}
/**
* Appends the byte array item to its internal encoded byte array store. This is used for the last
* item and is not encoded.
*
* <p>It stores the input array in the store, so the input array 'value' should not be modified.
*
* @param value bytes to be written.
* @see #readTrailingBytes()
*/
public void writeTrailingBytes(byte[] value) {
if ((value == null) || (value.length == 0)) {
throw new IllegalArgumentException("Value cannot be null or have 0 elements");
}
encodedArrays.add(value);
}
/**
* Returns the next byte array item from its encoded byte array store and removes the item from
* the store.
*
* @see #writeBytes(byte[])
*/
public byte[] readBytes() {
return readBytes(false);
}
public byte[] readBytesDecreasing() {
return readBytes(true);
}View on GitHub (pinned to 12126d8942)