apache/incubator-seata · error · RuntimeException

BZip2 compress error

Error message

BZip2 compress error

What it means

BZip2Util.compress wraps any IOException raised while streaming bytes through CBZip2OutputStream into RuntimeException('BZip2 compress error'). Because the output is an in-memory ByteArrayOutputStream, ordinary disk/network failures cannot occur — an IOException here almost always means the input bytes are malformed for the bzip2 stream writer or the JVM is out of memory/resource-exhausted.

Source

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

/**
 * 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)) {
            byte[] buffer = new byte[BUFFER_SIZE];
            int n;
            while ((n = bzip2.read(buffer)) > -1) {
                out.write(buffer, 0, n);
            }
            return out.toByteArray();
        } catch (IOException e) {
            throw new RuntimeException("BZip2 decompress error", e);

View on GitHub (pinned to e01f97c6db)

Solutions

  1. Inspect the cause chain (the original IOException is attached) to identify whether it is data, memory, or library related.
  2. For large payloads, switch to a streaming/lower-overhead compressor (e.g. compressor: none or gzip/deflater with smaller chunks) or raise container heap.
  3. Align commons-compress with the version Seata was built against (check the seata-compressor-bzip2 pom).
  4. Catch RuntimeException at the compression boundary and fall back to uncompressed transfer or another compressor id if your protocol allows.

Example fix

// before
 byte[] packed = BZip2Util.compress(raw);

// after
 byte[] packed;
try {
    packed = BZip2Util.compress(raw);
} catch (RuntimeException e) {
    log.error("bzip2 compress failed, falling back to identity", e);
    packed = raw; // or route to another configured Compressor
 }
Defensive patterns

Strategy: try-catch

Try / catch

try {
    return BZip2Util.compress(bytes);
} catch (RuntimeException e) {
    Throwable cause = e.getCause();
    log.error("bzip2 compress failed", cause);
    // optional fallback per protocol capability:
    return bytes; // or rethrow if compression is mandatory
}

Prevention

When it happens

Trigger: BZip2Util.compress(bytes) where CBZip2OutputStream.write/finish throws — most commonly very large payloads triggering OutOfMemoryError-adjacent failures (surfacing as IOException from the stream), corrupted byte sources, or an Apache commons-compress version incompatibility on the classpath.

Common situations: Enabling bzip2 compression for large undo logs or big RPC messages; upgrading commons-compress independently of Seata so CBZip2OutputStream behavior changes; running in containers with tight memory limits where 8KB-buffer streaming of huge payloads fails.

Related errors


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