{"record":{"id":"d8b777697593d3c2","repo":"apache/beam","slug":"unknown-valuekind-number","errorCode":null,"errorMessage":"Unknown ValueKind number: {}","messagePattern":"Unknown ValueKind number: (.+?)","errorType":"exception","errorClass":"CoderException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/coders/ValueKindCoder.java","lineNumber":63,"sourceCode":"  private ValueKindCoder() {}\n\n  @Override\n  public void encode(ValueKind value, OutputStream outStream) throws IOException, CoderException {\n    if (value == null) {\n      throw new CoderException(\"cannot encode a null ValueKind\");\n    }\n    outStream.write(ValueKindUtil.toProto(value).getNumber());\n  }\n\n  @Override\n  public ValueKind decode(InputStream inStream) throws IOException, CoderException {\n    int number = inStream.read();\n    if (number == -1) {\n      throw new CoderException(new EOFException(\"EOF encountered decoding a ValueKind\"));\n    }\n    Elements.ValueKind.@Nullable Enum proto = Elements.ValueKind.Enum.forNumber(number);\n    if (proto == null) {\n      throw new CoderException(\"Unknown ValueKind number: \" + number);\n    }\n\n    return ValueKindUtil.fromProto(proto);\n  }\n\n  @Override\n  public boolean consistentWithEquals() {\n    return true;\n  }\n\n  @Override\n  public boolean isRegisterByteSizeObserverCheap(ValueKind value) {\n    return true;\n  }\n\n  @Override\n  protected long getEncodedElementByteSize(ValueKind value) {\n    return 1;","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/ValueKindCoder.java#L45-L81","documentation":"After reading the byte, ValueKindCoder maps it via Elements.ValueKind.Enum.forNumber; if no enum constant has that number, the byte is not a valid ValueKind and the coder throws CoderException naming the unknown number. This prevents silently producing a wrong kind from version skew or corrupt bytes.","triggerScenarios":"Decoding a stream written by a different Beam version whose ValueKind enum numbering changed; corrupted bytes or a wrong-offset read of the single-byte field; hand-crafted test data with out-of-range enum numbers; a misaligned stream where a foreign byte lands at this position.","commonSituations":"Version skew between pipeline submission and runner/harness images; transport corruption; byte-stream misalignment after a prior element decoded the wrong length.","solutions":["Align Beam SDK versions across writer and reader (same release for SDK and harness).","Validate the byte against Elements.ValueKind.Enum before decoding in custom pipelines.","Regenerate corrupted data; add transport checksums if corruption recurs.","Re-serialize data with one consistent version or add a migration decode path if enum numbering changed."],"exampleFix":"// before\nValueKind k = kindCoder.decode(in); // may throw on unknown number\n// after\nint b = in.read();\nif (Elements.ValueKind.Enum.forNumber(b) == null) {\n  throw new IOException(\"Stream not produced by this Beam version; ValueKind byte \" + b);\n}\nValueKind k = kindCoder.decode(new ByteArrayInputStream(new byte[]{(byte) b}));","handlingStrategy":"validation","validationCode":"int b = in.read();\nin.reset(); // where supported\nif (Elements.ValueKind.Enum.forNumber(b) == null) {\n  throw new IllegalArgumentException(\"Byte \" + b + \" is not a valid ValueKind enum number\");\n}","typeGuard":"static boolean isValidValueKindByte(int b) {\n  return Elements.ValueKind.Enum.forNumber(b) != null;\n}","tryCatchPattern":"try {\n  ValueKind k = kindCoder.decode(in);\n} catch (CoderException e) {\n  throw new VersionSkewException(\"Unknown ValueKind byte; check Beam SDK version skew\", e);\n}","preventionTips":["Keep Beam SDK versions aligned between writer and reader/harness.","Add transport checksums to detect corrupt bytes.","Avoid hand-crafted enum byte values in tests; use the coder's encode().","If enum numbering changes across versions, re-serialize or add a migration decode path."],"tags":["java","beam","coder","enum","version-skew","deserialization"],"backgroundTag":"invalid-enum-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}