{"record":{"id":"8ea58510aacf9c8d","repo":"apache/incubator-seata","slug":"bzip2-compress-error","errorCode":null,"errorMessage":"BZip2 compress error","messagePattern":"BZip2 compress 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":44,"sourceCode":"/**\n * the BZip2 Util\n *\n */\npublic class BZip2Util {\n\n    private static final int BUFFER_SIZE = 8192;\n\n    public static byte[] compress(byte[] bytes) {\n        if (bytes == null) {\n            throw new NullPointerException(\"bytes is null\");\n        }\n        ByteArrayOutputStream bos = new ByteArrayOutputStream();\n        try (CBZip2OutputStream bzip2 = new CBZip2OutputStream(bos)) {\n            bzip2.write(bytes);\n            bzip2.finish();\n            return bos.toByteArray();\n        } catch (IOException e) {\n            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);","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/apache/incubator-seata/blob/e01f97c6db397165050caa6764020410c2c8199a/compressor/seata-compressor-bzip2/src/main/java/org/apache/seata/compressor/bzip2/BZip2Util.java#L26-L62","documentation":"BZip2Util.compress wraps any IOException raised while streaming bytes through CBZip2OutputStream into RuntimeException('BZip2 compress error'). Because the output is an in-memory ByteArrayOutputStream, ordinary disk/network failures cannot occur — an IOException here almost always means the input bytes are malformed for the bzip2 stream writer or the JVM is out of memory/resource-exhausted.","triggerScenarios":"BZip2Util.compress(bytes) where CBZip2OutputStream.write/finish throws — most commonly very large payloads triggering OutOfMemoryError-adjacent failures (surfacing as IOException from the stream), corrupted byte sources, or an Apache commons-compress version incompatibility on the classpath.","commonSituations":"Enabling bzip2 compression for large undo logs or big RPC messages; upgrading commons-compress independently of Seata so CBZip2OutputStream behavior changes; running in containers with tight memory limits where 8KB-buffer streaming of huge payloads fails.","solutions":["Inspect the cause chain (the original IOException is attached) to identify whether it is data, memory, or library related.","For large payloads, switch to a streaming/lower-overhead compressor (e.g. compressor: none or gzip/deflater with smaller chunks) or raise container heap.","Align commons-compress with the version Seata was built against (check the seata-compressor-bzip2 pom).","Catch RuntimeException at the compression boundary and fall back to uncompressed transfer or another compressor id if your protocol allows."],"exampleFix":"// before\n byte[] packed = BZip2Util.compress(raw);\n\n// after\n byte[] packed;\ntry {\n    packed = BZip2Util.compress(raw);\n} catch (RuntimeException e) {\n    log.error(\"bzip2 compress failed, falling back to identity\", e);\n    packed = raw; // or route to another configured Compressor\n }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    return BZip2Util.compress(bytes);\n} catch (RuntimeException e) {\n    Throwable cause = e.getCause();\n    log.error(\"bzip2 compress failed\", cause);\n    // optional fallback per protocol capability:\n    return bytes; // or rethrow if compression is mandatory\n}","preventionTips":["Bound the size of payloads routed through bzip2 compression.","Keep commons-compress version aligned with the one Seata's seata-compressor-bzip2 builds against.","Monitor heap/native memory in containers running with compression enabled."],"tags":["compressor","bzip2","io","rpc"],"backgroundTag":null,"analyzedSha":"e01f97c6db397165050caa6764020410c2c8199a","analyzedAt":"2026-08-14T10:23:53.097Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}