{"record":{"id":"f7a2707f07dad27d","repo":"apache/incubator-seata","slug":"deflater-compress-error","errorCode":null,"errorMessage":"Deflater compress error","messagePattern":"Deflater compress error","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"compressor/seata-compressor-deflater/src/main/java/org/apache/seata/compressor/deflater/DeflaterUtil.java","lineNumber":47,"sourceCode":"\n    public static byte[] compress(byte[] bytes) {\n        if (bytes == null) {\n            throw new NullPointerException(\"bytes is null\");\n        }\n        int length = 0;\n        Deflater deflater = new Deflater();\n        deflater.setInput(bytes);\n        deflater.finish();\n        byte[] outputBytes = new byte[BUFFER_SIZE];\n        try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {\n            while (!deflater.finished()) {\n                length = deflater.deflate(outputBytes);\n                bos.write(outputBytes, 0, length);\n            }\n            deflater.end();\n            return bos.toByteArray();\n        } catch (IOException e) {\n            throw new RuntimeException(\"Deflater 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        int length = 0;\n        Inflater inflater = new Inflater();\n        inflater.setInput(bytes);\n        byte[] outputBytes = new byte[BUFFER_SIZE];\n        try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {\n            while (!inflater.finished()) {\n                length = inflater.inflate(outputBytes);\n                if (length == 0) {\n                    break;\n                }\n                bos.write(outputBytes, 0, length);","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/apache/incubator-seata/blob/e01f97c6db397165050caa6764020410c2c8199a/compressor/seata-compressor-deflater/src/main/java/org/apache/seata/compressor/deflater/DeflaterUtil.java#L29-L65","documentation":"DeflaterUtil.compress wraps IOException from the in-memory deflation loop into RuntimeException('Deflater compress error'). Since output goes to a ByteArrayOutputStream, an IOException is unexpected and usually masks a deeper failure (native zlib error from malformed input state, or memory pressure) surfacing through the loop that calls Deflater.deflate().","triggerScenarios":"DeflaterUtil.compress(bytes) where the ByteArrayOutputStream write or deflater loop throws — extremely large inputs causing allocation failures inside the loop, or a corrupted JDK/native zlib environment; direct invocation with adversarial byte arrays.","commonSituations":"Enabling deflater compression for oversized undo logs or batch RPC messages in memory-constrained containers; broken zlib natives on exotic base images; rarely, JVM bugs around Deflater after native memory exhaustion.","solutions":["Read the attached cause; if it is memory-related, increase heap or reduce payload size (page the batch).","Cap the size of payloads you compress, or choose compressor: none for oversized messages if your protocol allows.","Run on a standard JDK image to rule out broken zlib natives.","Catch RuntimeException at the boundary and fall back to uncompressed/alternate compressor."],"exampleFix":"// before\n byte[] packed = DeflaterUtil.compress(raw);\n\n// after\n byte[] packed;\ntry {\n    packed = DeflaterUtil.compress(raw);\n} catch (RuntimeException e) {\n    log.error(\"deflater compress failed, sending uncompressed\", e);\n    packed = raw;\n }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    return DeflaterUtil.compress(bytes);\n} catch (RuntimeException e) {\n    log.error(\"deflater compress failed\", e.getCause());\n    return bytes; // or rethrow if compression is mandatory\n}","preventionTips":["Size-limit payloads entering compression; paginate large batches.","Provision adequate heap/native memory when deflater compression is enabled.","Read the wrapped cause before assuming a Seata bug — it usually encodes the real failure."],"tags":["compressor","deflater","io","memory"],"backgroundTag":null,"analyzedSha":"e01f97c6db397165050caa6764020410c2c8199a","analyzedAt":"2026-08-14T10:23:53.097Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}