{"record":{"id":"5710dcc379b77c17","repo":"apache/incubator-seata","slug":"bytes-is-null-5710dc","errorCode":null,"errorMessage":"bytes is null","messagePattern":"bytes is null","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"compressor/seata-compressor-deflater/src/main/java/org/apache/seata/compressor/deflater/DeflaterUtil.java","lineNumber":32,"sourceCode":" * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage org.apache.seata.compressor.deflater;\n\nimport java.io.ByteArrayOutputStream;\nimport java.io.IOException;\nimport java.util.zip.Deflater;\nimport java.util.zip.Inflater;\n\npublic class DeflaterUtil {\n\n    private DeflaterUtil() {}\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        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","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/apache/incubator-seata/blob/e01f97c6db397165050caa6764020410c2c8199a/compressor/seata-compressor-deflater/src/main/java/org/apache/seata/compressor/deflater/DeflaterUtil.java#L14-L50","documentation":"DeflaterUtil.compress(byte[]) throws NullPointerException('bytes is null') as an explicit guard — the JDK Deflater would otherwise fail later with a less helpful error. In Seata's deflater compressor this means the byte payload handed to the compression layer (RPC frame, undo log) was null, pointing at an upstream serialization/protocol issue.","triggerScenarios":"compressor: deflater configured and a null body reaches Compressor.compress — e.g. an empty request/response object serialized to null, or direct calls DeflaterUtil.compress(null) from custom code/tests.","commonSituations":"Enabling transport compression globally so previously-ignored null payloads now hit the compressor; hand-written Compressor SPI wrappers that pass through null; unit tests feeding null fixtures.","solutions":["Replace null payloads with empty arrays at the producer side, or short-circuit null before compressing.","Add a null/empty guard in any custom compressor wrapper you wrote around DeflaterUtil.","Enable seata rpc debug logging to identify which message type carries the null body."],"exampleFix":"// before\n byte[] out = DeflaterUtil.compress(body); // body == null -> NPE\n\n// after\n byte[] out = (body == null || body.length == 0) ? new byte[0] : DeflaterUtil.compress(body);","handlingStrategy":"validation","validationCode":"if (bytes == null) {\n    bytes = new byte[0];\n}\nbyte[] compressed = DeflaterUtil.compress(bytes);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Substitute empty arrays for null at serializer boundaries.","Guard custom compressor wrappers for null/empty before delegating.","Cover null/empty cases in compressor unit tests."],"tags":["compressor","deflater","null-check","rpc"],"backgroundTag":null,"analyzedSha":"e01f97c6db397165050caa6764020410c2c8199a","analyzedAt":"2026-08-14T10:23:53.097Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}