apache/incubator-seata · error · NullPointerException

bytes is null

Error message

bytes is null

What it means

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.

Source

Thrown at compressor/seata-compressor-deflater/src/main/java/org/apache/seata/compressor/deflater/DeflaterUtil.java:32

 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.seata.compressor.deflater;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.Deflater;
import java.util.zip.Inflater;

public class DeflaterUtil {

    private DeflaterUtil() {}

    private static final int BUFFER_SIZE = 8192;

    public static byte[] compress(byte[] bytes) {
        if (bytes == null) {
            throw new NullPointerException("bytes is null");
        }
        int length = 0;
        Deflater deflater = new Deflater();
        deflater.setInput(bytes);
        deflater.finish();
        byte[] outputBytes = new byte[BUFFER_SIZE];
        try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
            while (!deflater.finished()) {
                length = deflater.deflate(outputBytes);
                bos.write(outputBytes, 0, length);
            }
            deflater.end();
            return bos.toByteArray();
        } catch (IOException e) {
            throw new RuntimeException("Deflater compress error", e);
        }
    }

View on GitHub (pinned to e01f97c6db)

Solutions

  1. Replace null payloads with empty arrays at the producer side, or short-circuit null before compressing.
  2. Add a null/empty guard in any custom compressor wrapper you wrote around DeflaterUtil.
  3. Enable seata rpc debug logging to identify which message type carries the null body.

Example fix

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

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

Strategy: validation

Validate before calling

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

Prevention

When it happens

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

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

Related errors


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