{"record":{"id":"ecc5f8882f04de04","repo":"apache/incubator-seata","slug":"gzip-compress-error","errorCode":null,"errorMessage":"gzip compress error","messagePattern":"gzip compress error","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"compressor/seata-compressor-gzip/src/main/java/org/apache/seata/compressor/gzip/GzipUtil.java","lineNumber":42,"sourceCode":"\npublic class GzipUtil {\n\n    private GzipUtil() {}\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 out = new ByteArrayOutputStream();\n        try (GZIPOutputStream gzip = new GZIPOutputStream(out)) {\n            gzip.write(bytes);\n            gzip.flush();\n            gzip.finish();\n            return out.toByteArray();\n        } catch (IOException e) {\n            throw new RuntimeException(\"gzip 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\n        ByteArrayOutputStream out = new ByteArrayOutputStream();\n        try (GZIPInputStream gunzip = new GZIPInputStream(new ByteArrayInputStream(bytes))) {\n            byte[] buffer = new byte[BUFFER_SIZE];\n            int n;\n            while ((n = gunzip.read(buffer)) > -1) {\n                out.write(buffer, 0, n);\n            }\n            return out.toByteArray();\n        } catch (IOException e) {\n            throw new RuntimeException(\"gzip decompress error\", e);","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/apache/incubator-seata/blob/e01f97c6db397165050caa6764020410c2c8199a/compressor/seata-compressor-gzip/src/main/java/org/apache/seata/compressor/gzip/GzipUtil.java#L24-L60","documentation":"GzipUtil.compress wraps IOException from GZIPOutputStream into RuntimeException('gzip compress error'). The stream writes to an in-memory ByteArrayOutputStream, so normal IO failures are impossible; the exception indicates broken gzip state — most often the JDK's deflater failed (native zlib issue, input too large for available memory) or the stream was used inconsistently (finish/flush after close).","triggerScenarios":"GzipUtil.compress(bytes) where gzip.write/flush/finish throws — huge payloads exhausting native/memory limits, or a damaged JDK/zlib environment; direct calls with pathological inputs.","commonSituations":"gzip chosen as undo-log/transport compressor for very large transactions; containers with low memory limits; base images with a broken zlib; rarely, classpath-shipped JDK internals conflicting with the runtime JDK.","solutions":["Inspect the cause; for memory pressure, increase heap/native memory or reduce payload size (batch/paginate).","Switch to compressor: none for messages above a size threshold, or pick a cheaper compressor (identity/deflater) for huge payloads.","Verify on a stock JDK image to rule out native zlib problems.","Catch RuntimeException at the boundary and degrade to uncompressed transfer if the protocol permits."],"exampleFix":"// before\n byte[] packed = GzipUtil.compress(raw);\n\n// after\n byte[] packed;\ntry {\n    packed = GzipUtil.compress(raw);\n} catch (RuntimeException e) {\n    log.error(\"gzip compress failed, sending uncompressed\", e);\n    packed = raw;\n }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    return GzipUtil.compress(bytes);\n} catch (RuntimeException e) {\n    log.error(\"gzip compress failed\", e.getCause());\n    return bytes; // or rethrow if compression is mandatory\n}","preventionTips":["Cap payload sizes or skip compression for oversized messages.","Ensure sufficient heap/native memory when gzip is the active compressor.","Run on a standard JDK image to avoid broken zlib natives."],"tags":["compressor","gzip","io","memory"],"backgroundTag":null,"analyzedSha":"e01f97c6db397165050caa6764020410c2c8199a","analyzedAt":"2026-08-14T10:23:53.097Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}