{"record":{"id":"fb23e0af04e35210","repo":"apache/beam","slug":"value-cannot-be-null-or-have-0-elements","errorCode":null,"errorMessage":"Value cannot be null or have 0 elements","messagePattern":"Value cannot be null or have 0 elements","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/OrderedCode.java","lineNumber":361,"sourceCode":"   *\n   * @see #readInfinityDecreasing()\n   */\n  public void writeInfinityDecreasing() {\n    writeTrailingBytes(INFINITY_ENCODED_DECREASING);\n  }\n\n  /**\n   * Appends the byte array item to its internal encoded byte array store. This is used for the last\n   * item and is not encoded.\n   *\n   * <p>It stores the input array in the store, so the input array 'value' should not be modified.\n   *\n   * @param value bytes to be written.\n   * @see #readTrailingBytes()\n   */\n  public void writeTrailingBytes(byte[] value) {\n    if ((value == null) || (value.length == 0)) {\n      throw new IllegalArgumentException(\"Value cannot be null or have 0 elements\");\n    }\n\n    encodedArrays.add(value);\n  }\n\n  /**\n   * Returns the next byte array item from its encoded byte array store and removes the item from\n   * the store.\n   *\n   * @see #writeBytes(byte[])\n   */\n  public byte[] readBytes() {\n    return readBytes(false);\n  }\n\n  public byte[] readBytesDecreasing() {\n    return readBytes(true);\n  }","sourceCodeStart":343,"sourceCodeEnd":379,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/OrderedCode.java#L343-L379","documentation":"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.","triggerScenarios":"Calling writeTrailingBytes(null) or writeTrailingBytes(new byte[0]) on an OrderedCode instance mid-encoding.","commonSituations":"Encoding a key component derived from a possibly-empty payload (e.g. empty suffix bytes from a parsed key) without checking length first.","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."],"exampleFix":"// before\noc.writeTrailingBytes(suffix);\n// after\nif (suffix != null && suffix.length > 0) {\n  oc.writeTrailingBytes(suffix);\n}","handlingStrategy":"validation","validationCode":"if (value == null || value.length == 0) {\n  // skip write or substitute sentinel\n}","typeGuard":"boolean writableTrailing(byte[] v) { return v != null && v.length > 0; }","tryCatchPattern":"try { oc.writeTrailingBytes(value); } catch (IllegalArgumentException e) { /* skip empty segment */ }","preventionTips":["Null/empty-check every byte payload before encoding","Use a sentinel byte for legitimate empty payloads","Centralize encoding helpers with input validation"],"tags":["java","orderedcode","encoding","empty-value"],"backgroundTag":"empty-required-field","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}