apache/incubator-seata · error · NullPointerException

bytes is null

Error message

bytes is null

What it means

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.

Source

Thrown at compressor/seata-compressor-bzip2/src/main/java/org/apache/seata/compressor/bzip2/BZip2Util.java:36

import org.apache.tools.bzip2.CBZip2InputStream;
import org.apache.tools.bzip2.CBZip2OutputStream;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
 * the BZip2 Util
 *
 */
public class BZip2Util {

    private static final int BUFFER_SIZE = 8192;

    public static byte[] compress(byte[] bytes) {
        if (bytes == null) {
            throw new NullPointerException("bytes is null");
        }
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        try (CBZip2OutputStream bzip2 = new CBZip2OutputStream(bos)) {
            bzip2.write(bytes);
            bzip2.finish();
            return bos.toByteArray();
        } catch (IOException e) {
            throw new RuntimeException("BZip2 compress error", e);
        }
    }

    public static byte[] decompress(byte[] bytes) {
        if (bytes == null) {
            throw new NullPointerException("bytes is null");
        }
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        try (CBZip2InputStream bzip2 = new CBZip2InputStream(bis)) {

View on GitHub (pinned to e01f97c6db)

Solutions

  1. Ensure callers pass byte[0] (empty array) instead of null for empty payloads — the util accepts empty arrays fine.
  2. Trace which layer hands null to the compressor (enable seata rpc/serialization debug logs) and fix that layer to short-circuit null before compression.
  3. If nulls are legitimate in your pipeline, branch on null before calling compress and skip compression entirely.

Example fix

// before
 byte[] out = BZip2Util.compress(body); // body == null -> NPE

// after
 byte[] out = (body == null) ? new byte[0] : BZip2Util.compress(body);
Defensive patterns

Strategy: validation

Validate before calling

if (bytes == null) {
    // decide your protocol's null semantics; empty-array is the usual choice
    bytes = new byte[0];
}
byte[] compressed = BZip2Util.compress(bytes);

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/incubator-seata@e01f97c6db (2026-08-14). Data as JSON: /api/errors/98e85deaf0605b19. Report an issue: GitHub.