apache/pulsar · error · RuntimeException
Invalid compression type
Error message
Invalid compression type
What it means
CompressionCodecProvider.convertToWireProtocol maps the public client CompressionType enum onto the wire-protocol CompressionType. Every known codec (NONE, LZ4, ZLIB, ZSTD, SNAPPY) is handled by the switch; reaching the default branch means an unknown/unsupported enum value, and it throws RuntimeException 'Invalid compression type'.
Source
Thrown at pulsar-common/src/main/java/org/apache/pulsar/common/compression/CompressionCodecProvider.java:70
return codecs.get(convertToWireProtocol(type));
}
public static org.apache.pulsar.common.api.proto.CompressionType convertToWireProtocol(
CompressionType compressionType) {
switch (compressionType) {
case NONE:
return org.apache.pulsar.common.api.proto.CompressionType.NONE;
case LZ4:
return org.apache.pulsar.common.api.proto.CompressionType.LZ4;
case ZLIB:
return org.apache.pulsar.common.api.proto.CompressionType.ZLIB;
case ZSTD:
return org.apache.pulsar.common.api.proto.CompressionType.ZSTD;
case SNAPPY:
return org.apache.pulsar.common.api.proto.CompressionType.SNAPPY;
default:
throw new RuntimeException("Invalid compression type");
}
}
public static CompressionType convertFromWireProtocol(
org.apache.pulsar.common.api.proto.CompressionType compressionType) {
switch (compressionType) {
case NONE:
return CompressionType.NONE;
case LZ4:
return CompressionType.LZ4;
case ZLIB:
return CompressionType.ZLIB;
case ZSTD:
return CompressionType.ZSTD;
case SNAPPY:
return CompressionType.SNAPPY;
default:View on GitHub (pinned to 820761864e)
Solutions
- Verify the CompressionType passed is one of NONE, LZ4, ZLIB, ZSTD, or SNAPPY; validate or default to NONE before conversion.
- Align client and broker library versions so both sides support the same codec set.
- Null-check / whitelist-check the configured codec name at startup and fail fast with a clear configuration error.
- Catch the RuntimeException where conversion happens and log the offending enum value to identify the source.
Example fix
// before
CompressionType type = CompressionType.valueOf(config.getCompression()); // may yield unknown/null
send(convertToWireProtocol(type));
// after
CompressionType type = SUPPORTED.contains(config.getCompression())
? CompressionType.valueOf(config.getCompression())
: CompressionType.NONE; // whitelist: NONE, LZ4, ZLIB, ZSTD, SNAPPY Defensive patterns
Strategy: validation
Validate before calling
private static final Set<CompressionType> SUPPORTED = EnumSet.of(
CompressionType.NONE, CompressionType.LZ4, CompressionType.ZLIB,
CompressionType.ZSTD, CompressionType.SNAPPY);
if (type == null || !SUPPORTED.contains(type)) {
throw new IllegalArgumentException("unsupported compression type: " + type);
} Try / catch
try {
wire = CompressionCodecProvider.convertToWireProtocol(type);
} catch (RuntimeException e) {
log.warn("Invalid compression type {}, falling back to NONE", type);
wire = org.apache.pulsar.common.api.proto.CompressionType.NONE;
} Prevention
- Whitelist compression settings at configuration load time.
- Null-check configured compression values before conversion.
- Keep client and broker versions aligned on supported codecs.
When it happens
Trigger: Passing a CompressionType value not covered by the switch — typically null, a custom/exotic enum constant, or an enum from a different library version with a codec this provider doesn't recognize.
Common situations: Client/server version skew where a newer codec enum isn't handled; configuration loading a compression name that maps to an unexpected enum; passing null compression type into conversion paths; reflective/dynamic codec selection picking an unsupported value.
Related errors
- Unsupported token endpoint auth method: ${value}
- --offloadedReadPriority parameter must be one of ${allowed}
- Unrecognized auto_failover_policy: ${policyType}
- --offloadedReadPriority parameter must be one of %s but got:
- Unknown RegexImplementation:
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/51dab3ffd5d04d38.
Report an issue: GitHub.