apache/incubator-seata · error · NullPointerException

bytes is null

Error message

bytes is null

What it means

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.

Source

Thrown at compressor/seata-compressor-gzip/src/main/java/org/apache/seata/compressor/gzip/GzipUtil.java:33

 * limitations under the License.
 */
package org.apache.seata.compressor.gzip;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

public class GzipUtil {

    private GzipUtil() {}

    private static final int BUFFER_SIZE = 8192;

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

    public static byte[] decompress(byte[] bytes) {
        if (bytes == null) {
            throw new NullPointerException("bytes is null");
        }

        ByteArrayOutputStream out = new ByteArrayOutputStream();

View on GitHub (pinned to e01f97c6db)

Solutions

  1. Normalize null to byte[0] at the producer/serializer layer before compression.
  2. Add an explicit null/empty check in custom code that wraps GzipUtil.
  3. Log the message type at the rpc layer to find which frame carries null.

Example fix

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

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

Strategy: validation

Validate before calling

if (bytes == null) {
    bytes = new byte[0];
}
byte[] compressed = GzipUtil.compress(bytes);

Prevention

When it happens

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

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

Related errors


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