{"record":{"id":"cb1e71a82c9ac6ce","repo":"prestodb/presto","slug":"can-not-deserialize-the-data","errorCode":null,"errorMessage":"Can not deserialize the data","messagePattern":"Can not deserialize the data","errorType":"exception","errorClass":"TProtocolException","httpStatus":null,"severity":"error","filePath":"presto-thrift-connector-toolkit/src/main/java/com/facebook/presto/thrift/codec/ThriftCodecUtils.java","lineNumber":36,"sourceCode":"import com.facebook.drift.protocol.TMemoryBuffer;\nimport com.facebook.drift.protocol.TMemoryBufferWriteOnly;\nimport com.facebook.drift.protocol.TProtocolException;\n\npublic class ThriftCodecUtils\n{\n    private ThriftCodecUtils() {}\n\n    public static <T> T fromThrift(byte[] bytes, ThriftCodec<T> thriftCodec)\n            throws TProtocolException\n    {\n        try {\n            TMemoryBuffer transport = new TMemoryBuffer(bytes.length);\n            transport.write(bytes);\n            TBinaryProtocol protocol = new TBinaryProtocol(transport);\n            return thriftCodec.read(protocol);\n        }\n        catch (Exception e) {\n            throw new TProtocolException(\"Can not deserialize the data\", e);\n        }\n    }\n\n    public static <T> byte[] toThrift(T value, ThriftCodec<T> thriftCodec)\n            throws TProtocolException\n    {\n        TMemoryBufferWriteOnly transport = new TMemoryBufferWriteOnly(1024);\n        TBinaryProtocol protocol = new TBinaryProtocol(transport);\n        try {\n            thriftCodec.write(value, protocol);\n            return transport.getBytes();\n        }\n        catch (Exception e) {\n            throw new TProtocolException(\"Can not serialize the data\", e);\n        }\n    }\n}\n","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-thrift-connector-toolkit/src/main/java/com/facebook/presto/thrift/codec/ThriftCodecUtils.java#L18-L54","documentation":"ThriftCodecUtils.fromThrift() reads an object of type T from bytes using the given ThriftCodec over a TBinaryProtocol. Any exception during transport write or protocol read is rethrown uniformly as TProtocolException with this message. It is the generic low-level deserialization failure behind higher-level wrappers like GenericThriftCodec.deserialize.","triggerScenarios":"Calling ThriftCodecUtils.fromThrift(bytes, codec) where bytes are empty/corrupt/truncated, not written with TBinaryProtocol, or structurally incompatible with the codec's Thrift type (missing required fields, wrong field types).","commonSituations":"Version mismatch between services sharing serialized Thrift payloads; hand-crafted or debug-modified byte buffers; network/storage corruption; using the wrong codec class for the bytes.","solutions":["Ensure the bytes were written by ThriftCodecUtils.toThrift() with the same ThriftCodec and TBinaryProtocol","Align Thrift IDL/struct versions between producer and consumer","Validate byte array non-empty and well-formed before the call","Catch TProtocolException and either regenerate the payload or fail with a clear error"],"exampleFix":"// before\nT value = ThriftCodecUtils.fromThrift(bytes, codec); // TProtocolException on corrupt data\n// after\nif (bytes == null || bytes.length == 0) {\n    throw new IllegalArgumentException(\"empty payload\");\n}\ntry {\n    T value = ThriftCodecUtils.fromThrift(bytes, codec);\n} catch (TProtocolException e) {\n    throw new IOException(\"incompatible or corrupt Thrift payload\", e);\n}","handlingStrategy":"try-catch","validationCode":"if (bytes == null || bytes.length == 0) {\n    throw new IllegalArgumentException(\"empty Thrift payload\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    T value = ThriftCodecUtils.fromThrift(bytes, codec);\n} catch (TProtocolException e) {\n    throw new IOException(\"failed to decode Thrift payload (size=\" + bytes.length + \")\", e);\n}","preventionTips":["Keep Thrift IDL definitions in sync across services","Round-trip test (toThrift then fromThrift) in CI for each codec","Never hand-assemble Thrift byte buffers","Log producer version when payloads cross service boundaries"],"tags":["thrift","deserialization"],"backgroundTag":"thrift-deserialization-failed","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}