{"record":{"id":"98e85deaf0605b19","repo":"apache/incubator-seata","slug":"bytes-is-null","errorCode":null,"errorMessage":"bytes is null","messagePattern":"bytes is null","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"compressor/seata-compressor-bzip2/src/main/java/org/apache/seata/compressor/bzip2/BZip2Util.java","lineNumber":36,"sourceCode":"\nimport org.apache.tools.bzip2.CBZip2InputStream;\nimport org.apache.tools.bzip2.CBZip2OutputStream;\n\nimport java.io.ByteArrayInputStream;\nimport java.io.ByteArrayOutputStream;\nimport java.io.IOException;\n\n/**\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)) {","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/apache/incubator-seata/blob/e01f97c6db397165050caa6764020410c2c8199a/compressor/seata-compressor-bzip2/src/main/java/org/apache/seata/compressor/bzip2/BZip2Util.java#L18-L54","documentation":"BZip2Util.compress(byte[]) throws NullPointerException('bytes is null') as an explicit pre-condition check when the caller passes a null payload. Seata compressor implementations guard uniformly: null is not treated as empty input, it is rejected so that serialization bugs surface at the call site rather than inside the bzip2 native-ish loop.","triggerScenarios":"Configuring compressor: bzip2 on rpc/undo/log compression and the message body (RPC message, undo log content, or serialized bytes) is null — e.g. a heartbeat/empty response routed through compression, or a caller invoking BZip2Util.compress(null) directly.","commonSituations":"Empty-body protocol messages when compression is enabled globally; code paths that map 'no payload' to null instead of an empty array; testing compression with mock nulls; a custom Compressor SPI implementation delegating before null-checking.","solutions":["Ensure callers pass byte[0] (empty array) instead of null for empty payloads — the util accepts empty arrays fine.","Trace which layer hands null to the compressor (enable seata rpc/serialization debug logs) and fix that layer to short-circuit null before compression.","If nulls are legitimate in your pipeline, branch on null before calling compress and skip compression entirely."],"exampleFix":"// before\n byte[] out = BZip2Util.compress(body); // body == null -> NPE\n\n// after\n byte[] out = (body == null) ? new byte[0] : BZip2Util.compress(body);","handlingStrategy":"validation","validationCode":"if (bytes == null) {\n    // decide your protocol's null semantics; empty-array is the usual choice\n    bytes = new byte[0];\n}\nbyte[] compressed = BZip2Util.compress(bytes);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass null to Seata compressor APIs — use byte[0] for empty payloads.","In custom Compressor implementations, null-check before delegating to BZip2Util.","Add unit tests with null and empty arrays around your compression wrapper."],"tags":["compressor","bzip2","null-check","rpc"],"backgroundTag":null,"analyzedSha":"e01f97c6db397165050caa6764020410c2c8199a","analyzedAt":"2026-08-14T10:23:53.097Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}