{"record":{"id":"36edc43a925cec45","repo":"apache/beam","slug":"could-not-read-value-error-s","errorCode":null,"errorMessage":"Could not read value. Error: %s","messagePattern":"Could not read value\\. Error: (.+?)","errorType":"exception","errorClass":"CoderException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/thrift/src/main/java/org/apache/beam/sdk/io/thrift/ThriftCoder.java","lineNumber":102,"sourceCode":"\n  /**\n   * Decodes a value of type {@code T} from the given input stream using provided {@link\n   * ThriftCoder#protocolFactory}. Returns the decoded value.\n   *\n   * @param inStream stream of input values to be decoded\n   * @throws IOException if reading from the {@code InputStream} fails for some reason\n   * @throws CoderException if the value could not be decoded for some reason\n   * @return {@link TBase} decoded object\n   */\n  @Override\n  public T decode(InputStream inStream) throws CoderException, IOException {\n    try {\n      TProtocol protocol = protocolFactory.getProtocol(new TIOStreamTransport(inStream));\n      TBase<?, ?> value = (TBase<?, ?>) type.getDeclaredConstructor().newInstance();\n      value.read(protocol);\n      return (T) value;\n    } catch (Exception te) {\n      throw new CoderException(\"Could not read value. Error: \" + te.getMessage());\n    }\n  }\n}\n","sourceCodeStart":84,"sourceCodeEnd":106,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/thrift/src/main/java/org/apache/beam/sdk/io/thrift/ThriftCoder.java#L84-L106","documentation":"ThriftCoder.decode instantiates the thrift class reflectively and reads the value from the input stream via the configured protocol. Any exception during read (protocol corruption, instantiation failure, ClassCastException on the cast) is wrapped in a CoderException with this message.","triggerScenarios":"Calling decode on bytes that were not written by the matching protocol factory, truncated/corrupted input streams, or a thrift type whose declared constructor throws or whose read() hits a protocol type mismatch.","commonSituations":"Reading Kafka topics written by producers using a different Thrift protocol (e.g. compact vs binary); schema/IDL drift between writer and reader; deserializing non-Thrift bytes accidentally sent to the same topic.","solutions":["Check the cause message after 'Error:' — 'unrecognized protocol' or field-mismatch hints point to writer/reader protocol or IDL mismatch","Ensure the same TProtocolFactory is used on encode and decode sides","Regenerate thrift classes from the current .thrift file and redeploy so reader and writer agree","Verify the input stream is complete and not truncated before decoding"],"exampleFix":"// before\nThriftCoder<ThriftRecord> coder = ThriftCoder.of(); // default protocol\nThriftRecord r = coder.decode(inputStream);\n// after\nThriftCoder<ThriftRecord> coder =\n    ThriftCoder.of(new TCompactProtocol.Factory()); // match writer's protocol\nThriftRecord r = coder.decode(new ByteArrayInputStream(fullPayload));","handlingStrategy":"try-catch","validationCode":"if (payload == null || payload.length == 0) { throw new IllegalArgumentException(\"empty payload for thrift decode\"); }","typeGuard":null,"tryCatchPattern":"try { return coder.decode(stream); } catch (CoderException e) { LOG.error(\"thrift decode failed: {}\", e.getMessage(), e); return null; /* or dead-letter */ }","preventionTips":["Use the identical TProtocolFactory on encode and decode","Dead-letter undecodable messages instead of failing the pipeline","Pin thrift generator/runtime versions across services"],"tags":["java","thrift","deserialization","beam-coder"],"backgroundTag":"json-unmarshal-failed","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"}