{"record":{"id":"6f29a0e010d490e5","repo":"apache/incubator-seata","slug":"bytes-is-null-6f29a0","errorCode":null,"errorMessage":"bytes is null","messagePattern":"bytes is null","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"compressor/seata-compressor-gzip/src/main/java/org/apache/seata/compressor/gzip/GzipUtil.java","lineNumber":33,"sourceCode":" * limitations under the License.\n */\npackage org.apache.seata.compressor.gzip;\n\nimport java.io.ByteArrayInputStream;\nimport java.io.ByteArrayOutputStream;\nimport java.io.IOException;\nimport java.util.zip.GZIPInputStream;\nimport java.util.zip.GZIPOutputStream;\n\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();","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/apache/incubator-seata/blob/e01f97c6db397165050caa6764020410c2c8199a/compressor/seata-compressor-gzip/src/main/java/org/apache/seata/compressor/gzip/GzipUtil.java#L15-L51","documentation":"GzipUtil.compress(byte[]) throws NullPointerException('bytes is null') as an explicit pre-condition: Seata's gzip compressor rejects null rather than treating it as empty input. Hitting it means a null payload reached the compression layer — an upstream protocol/serialization defect, since valid RPC bodies are never null at this point.","triggerScenarios":"compressor: gzip configured and a null body is handed to compress — e.g. an empty response message mapped to null by a custom serializer, or direct calls GzipUtil.compress(null) from custom SPI code or tests.","commonSituations":"Enabling transport compression globally after code that tolerated null bodies; custom Compressor implementations delegating without guards; test fixtures using null where empty array was intended.","solutions":["Normalize null to byte[0] at the producer/serializer layer before compression.","Add an explicit null/empty check in custom code that wraps GzipUtil.","Log the message type at the rpc layer to find which frame carries null."],"exampleFix":"// before\n byte[] out = GzipUtil.compress(body); // body == null -> NPE\n\n// after\n byte[] out = (body == null) ? new byte[0] : GzipUtil.compress(body);","handlingStrategy":"validation","validationCode":"if (bytes == null) {\n    bytes = new byte[0];\n}\nbyte[] compressed = GzipUtil.compress(bytes);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Map 'no payload' to byte[0], not null, at every serialization boundary.","Null-guard any custom compressor wrapper around GzipUtil.","Test compression paths with empty and null inputs."],"tags":["compressor","gzip","null-check","rpc"],"backgroundTag":null,"analyzedSha":"e01f97c6db397165050caa6764020410c2c8199a","analyzedAt":"2026-08-14T10:23:53.097Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}