apache/incubator-seata · error · NullPointerException
bytes is null
Error message
bytes is null
What it means
Thrown by Lz4Util.compress when the input byte array is null. The lz4 compressor is used to shrink seata RPC message bodies before transport; compress requires a non-null input and signals null as a caller bug via NullPointerException('bytes is null'). Note that unlike gzip, the IOException path in lz4 compress only logs the error and returns whatever partial bytes exist — but this error is the null guard.
Source
Thrown at compressor/seata-compressor-lz4/src/main/java/org/apache/seata/compressor/lz4/Lz4Util.java:38
import net.jpountz.lz4.LZ4FrameOutputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
/**
* the Lz4 Util
*
*/
public class Lz4Util {
private static final Logger LOGGER = LoggerFactory.getLogger(Lz4Util.class);
private static final int ARRAY_SIZE = 1024;
public static byte[] compress(byte[] bytes) {
if (bytes == null) {
throw new NullPointerException("bytes is null");
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try (LZ4FrameOutputStream lz4OutputStream = new LZ4FrameOutputStream(outputStream)) {
lz4OutputStream.write(bytes);
} catch (IOException e) {
LOGGER.error("compress bytes error", e);
}
return outputStream.toByteArray();
}
public static byte[] decompress(byte[] bytes) {
if (bytes == null) {
throw new NullPointerException("bytes is null");
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(ARRAY_SIZE);
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
try (LZ4FrameInputStream decompressedInputStream = new LZ4FrameInputStream(inputStream)) {View on GitHub (pinned to e01f97c6db)
Solutions
- Find why the body is null — log the message construction site that passed the null field.
- Send an empty array instead of null when 'no payload' is intended.
- Null-check before compress and fail with a descriptive error naming the message type.
Example fix
// before byte[] out = Lz4Util.compress(bytes); // after byte[] out = Lz4Util.compress(bytes == null ? new byte[0] : bytes);
Defensive patterns
Strategy: validation
Validate before calling
if (bytes == null) {
throw new IllegalArgumentException("payload to lz4-compress is null");
} Prevention
- Use empty arrays, not null, for intentionally empty payloads
- Validate message bodies at construction time, not at compression time
When it happens
Trigger: Calling Lz4Util.compress(null), or a seata transport/serializer handing a null body to the lz4 Compressor because the message field was never set.
Common situations: Building seata RPC messages manually in tests or SDK extensions without a body; a codec path where an optional payload field is absent; switching message types where one type has no body.
Related errors
AI-assisted analysis of apache/incubator-seata@e01f97c6db (2026-08-14).
Data as JSON: /api/errors/eab3c8bcb4d45ab6.
Report an issue: GitHub.