{"record":{"id":"b453bcc1839c7aaf","repo":"apache/incubator-seata","slug":"bzip2-decompress-error","errorCode":null,"errorMessage":"BZip2 decompress error","messagePattern":"BZip2 decompress error","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"compressor/seata-compressor-bzip2/src/main/java/org/apache/seata/compressor/bzip2/BZip2Util.java","lineNumber":62,"sourceCode":"            throw new RuntimeException(\"BZip2 compress error\", e);\n        }\n    }\n\n    public static byte[] decompress(byte[] bytes) {\n        if (bytes == null) {\n            throw new NullPointerException(\"bytes is null\");\n        }\n        ByteArrayOutputStream out = new ByteArrayOutputStream();\n        ByteArrayInputStream bis = new ByteArrayInputStream(bytes);\n        try (CBZip2InputStream bzip2 = new CBZip2InputStream(bis)) {\n            byte[] buffer = new byte[BUFFER_SIZE];\n            int n;\n            while ((n = bzip2.read(buffer)) > -1) {\n                out.write(buffer, 0, n);\n            }\n            return out.toByteArray();\n        } catch (IOException e) {\n            throw new RuntimeException(\"BZip2 decompress error\", e);\n        }\n    }\n}\n","sourceCodeStart":44,"sourceCodeEnd":66,"githubUrl":"https://github.com/apache/incubator-seata/blob/e01f97c6db397165050caa6764020410c2c8199a/compressor/seata-compressor-bzip2/src/main/java/org/apache/seata/compressor/bzip2/BZip2Util.java#L44-L66","documentation":"BZip2Util.decompress wraps IOException from CBZip2InputStream in RuntimeException('BZip2 decompress error'). commons-compress throws IOException for invalid stream headers, truncated data, or CRC mismatches, so this exception in Seata almost always means the bytes given are not a complete/valid bzip2 stream — commonly because they were compressed by a different algorithm or corrupted in transit.","triggerScenarios":"decompress(bytes) where bytes was produced by gzip/deflater/zstd (compressor id mismatch between endpoints), by bzip2 without the leading 'BZ' magic (some CLI bzip2 variants differ), truncated by a size-limited channel, or double-encoded; also raw data passed where compressed data was expected.","commonSituations":"Client configured compressor: gzip while server expects bzip2 (or vice versa) after a config change rolled out partially; messages routed through proxies that mangle binary payloads; undo logs written uncompressed then read with bzip2 enabled; version drift in commons-compress changing stream validation strictness.","solutions":["Make compressor configuration symmetric on both peers (same seata transport/undo compressor id) and restart both sides after changing it.","Check the first two bytes of the payload — a valid bzip2 stream starts with 'B' 'Z' (0x42 0x5A); if not, the data was not bzip2-compressed.","Verify the payload length matches what the sender logged (detect truncation).","Catch RuntimeException around decompress and surface the IOException cause for precise diagnosis."],"exampleFix":"// before\n byte[] raw = BZip2Util.decompress(body);\n\n// after\n if (body.length < 2 || body[0] != 'B' || body[1] != 'Z') {\n     throw new IOException(\"payload is not bzip2 (bad magic) — check compressor config on both peers\");\n }\n try {\n     byte[] raw = BZip2Util.decompress(body);\n } catch (RuntimeException e) {\n     throw new IOException(\"bzip2 decompress failed\", e.getCause());\n }","handlingStrategy":"try-catch","validationCode":"// bzip2 streams start with magic 'BZ'\npublic static boolean looksLikeBzip2(byte[] data) {\n    return data != null && data.length >= 2\n        && data[0] == 'B' && data[1] == 'Z';\n}","typeGuard":null,"tryCatchPattern":"try {\n    return BZip2Util.decompress(bytes);\n} catch (RuntimeException e) {\n    Throwable cause = e.getCause(); // original IOException\n    throw new IOException(\"bzip2 decompress failed (corrupt or wrong-compressor payload)\", cause);\n}","preventionTips":["Change compressor configuration on all peers in the same rollout window.","Verify binary integrity end to end (no text-charset conversion in between).","Keep a magic-byte sanity check in front of decompression in custom integrations."],"tags":["compressor","bzip2","data-corruption","configuration-mismatch"],"backgroundTag":null,"analyzedSha":"e01f97c6db397165050caa6764020410c2c8199a","analyzedAt":"2026-08-14T10:23:53.097Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}