apache/incubator-seata · error · NullPointerException
bytes is null
Error message
bytes is null
What it means
Thrown by ZstdUtil.compress when the input byte array is null. The zstd compressor delegates to the native Zstd bindings after the null guard; null input is rejected with NullPointerException('bytes is null') because the native call would otherwise crash the JVM.
Source
Thrown at compressor/seata-compressor-zstd/src/main/java/org/apache/seata/compressor/zstd/ZstdUtil.java:34
*/
package org.apache.seata.compressor.zstd;
import com.github.luben.zstd.Zstd;
import com.github.luben.zstd.ZstdInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
/**
* the Zstd Util
*
*/
public class ZstdUtil {
public static byte[] compress(byte[] bytes) {
if (bytes == null) {
throw new NullPointerException("bytes is null");
}
return Zstd.compress(bytes);
}
public static byte[] decompress(byte[] bytes) {
if (bytes == null) {
throw new NullPointerException("bytes is null");
}
try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ZstdInputStream zis = new ZstdInputStream(bais);
ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
byte[] buffer = new byte[8192];
int len;
while ((len = zis.read(buffer)) > 0) {
baos.write(buffer, 0, len);
}
return baos.toByteArray();View on GitHub (pinned to e01f97c6db)
Solutions
- Find the construction site of the null body and log the message type.
- Use an empty array to represent an intentionally empty payload.
- Add a null guard with context-rich error before compress.
Example fix
// before
byte[] out = ZstdUtil.compress(bytes);
// after
if (bytes == null) {
throw new IllegalArgumentException("payload to zstd-compress is null");
}
byte[] out = ZstdUtil.compress(bytes); Defensive patterns
Strategy: validation
Validate before calling
if (bytes == null) {
throw new IllegalArgumentException("payload to zstd-compress is null");
} Prevention
- Never let null bodies reach native-backed compressors (zstd/lz4) — guard in your codec layer
- Prefer empty arrays for empty payloads
When it happens
Trigger: Calling ZstdUtil.compress(null) or the Compressor framework passing a null message body into the zstd path.
Common situations: Missing optional body on deserialized RPC messages; tests passing null; codec extension code that skips body population for some message types.
Related errors
AI-assisted analysis of apache/incubator-seata@e01f97c6db (2026-08-14).
Data as JSON: /api/errors/c5c44da51be6ddec.
Report an issue: GitHub.