quarkusio/quarkus · error · NullPointerException

Compression cannot be null

Error message

Compression cannot be null

What it means

CompressionInterceptor wraps a gRPC server interceptor that applies a specific compression to responses. It validates in its constructor that the compression algorithm name is non-null, throwing NullPointerException otherwise. A null means the compression config was not resolved before constructing the interceptor.

Source

Thrown at extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/supports/CompressionInterceptor.java:14

package io.quarkus.grpc.runtime.supports;

import io.grpc.Metadata;
import io.grpc.ServerCall;
import io.grpc.ServerCallHandler;
import io.grpc.ServerInterceptor;

public class CompressionInterceptor implements ServerInterceptor {

    private final String compression;

    public CompressionInterceptor(String compression) {
        if (compression == null) {
            throw new NullPointerException("Compression cannot be null");
        }
        this.compression = compression;
    }

    @Override
    public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
            ServerCall<ReqT, RespT> call,
            Metadata headers,
            ServerCallHandler<ReqT, RespT> next) {
        call.setCompression(compression);
        return next.startCall(call, headers);
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Pass a valid, non-null compression algorithm name such as "gzip" or "identity"
  2. Check the configuration source that supplies the compression value and add a default
  3. Ensure the compression algorithm is registered (e.g. via Codec) before using it

Example fix

// before
new CompressionInterceptor(config.compression()); // null
// after
String c = config.compression() != null ? config.compression() : "gzip";
new CompressionInterceptor(c);
Defensive patterns

Strategy: validation

Validate before calling

if (compression == null || compression.isBlank()) {
    throw new IllegalArgumentException("compression must be set (e.g. gzip, identity)");
}

Try / catch

try {
    new CompressionInterceptor(cfg.compression());
} catch (NullPointerException e) {
    LOG.warn("Compression unset; falling back to gzip");
}

Prevention

When it happens

Trigger: Constructing new CompressionInterceptor(null) directly, or a server configuration path that passes a null compression value into the interceptor.

Common situations: Custom server interceptor registration with an unresolved config property; reflection-based instantiation bypassing config defaults.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/f57dd074af3fbd12. Report an issue: GitHub.