apache/kafka · error · IllegalArgumentException

Unknown compression name: {}

Error message

Unknown compression name: {}

What it means

Thrown by CompressionType.forName(String) when the supplied name does not equal any of the lowercase canonical names: "none", "gzip", "snappy", "lz4", "zstd". forName is the string-to-enum entry point used by every producer/broker config that accepts compression.type; an unrecognized name cannot be mapped to a compressor, so it fails fast with IllegalArgumentException during ConfigDef parsing.

Source

Thrown at clients/src/main/java/org/apache/kafka/common/record/internal/CompressionType.java:173

                return ZSTD;
            default:
                throw new IllegalArgumentException("Unknown compression type id: " + id);
        }
    }

    public static CompressionType forName(String name) {
        if (NONE.name.equals(name))
            return NONE;
        else if (GZIP.name.equals(name))
            return GZIP;
        else if (SNAPPY.name.equals(name))
            return SNAPPY;
        else if (LZ4.name.equals(name))
            return LZ4;
        else if (ZSTD.name.equals(name))
            return ZSTD;
        else
            throw new IllegalArgumentException("Unknown compression name: " + name);
    }

    public int defaultLevel() {
        throw new UnsupportedOperationException("Compression levels are not defined for this compression type: " + name);
    }

    public int maxLevel() {
        throw new UnsupportedOperationException("Compression levels are not defined for this compression type: " + name);
    }

    public int minLevel() {
        throw new UnsupportedOperationException("Compression levels are not defined for this compression type: " + name);
    }

    public ConfigDef.Validator levelValidator() {
        throw new UnsupportedOperationException("Compression levels are not defined for this compression type: " + name);
    }

View on GitHub (pinned to c31c9215e1)

Solutions

  1. Use the exact lowercase canonical name: none, gzip, snappy, lz4, or zstd.
  2. Trim whitespace and strip quotes from environment-variable-sourced config values before parsing.
  3. If you need a codec Kafka does not support, switch to a supported type — bzip2/deflate/brotli are not implemented.

Example fix

# before
compression.type=GZIP

# after
compression.type=gzip
Defensive patterns

Strategy: validation

Validate before calling

// CompressionType.forName is case-sensitive and matches exactly: none|gzip|snappy|lz4|zstd
static final Set<String> KNOWN = Set.of("none", "gzip", "snappy", "lz4", "zstd");
String normalized = (name == null) ? null : name.trim().toLowerCase(Locale.ROOT);
if (name == null || !KNOWN.contains(normalized)) {
    throw new IllegalArgumentException("Unknown compression name: " + name);
}

Type guard

// Narrow an arbitrary string to a known compression name
static Optional<CompressionType> safeForName(String name) {
    if (name == null) return Optional.empty();
    return Arrays.stream(CompressionType.values())
        .filter(t -> t.name.equalsIgnoreCase(name.trim()))
        .findFirst();
}

Try / catch

try {
    CompressionType t = CompressionType.forName(configValue);
} catch (IllegalArgumentException e) {
    // typo in config; log the valid set and fall back to a safe default
    t = CompressionType.NONE;
}

Prevention

When it happens

Trigger: Configuring compression.type (or any config key validated via CompressionType.forName) to a string other than none/gzip/snappy/lz4/zstd — e.g., "GZIP", "ZSTD", "Snappy", "bzip2", "lz4j", or a typo like "sappy". Case-sensitive exact match is required.

Common situations: Upper/camel-case values in YAML/properties files; operators used to other tools' compression names ("deflate", "brotli"); copy-paste typos; trailing whitespace or quotes in env vars.

Related errors


AI-assisted analysis of apache/kafka@c31c9215e1 (2026-08-03). Data as JSON: /data/errors/aa04ab99c6640795.json. Report an issue: GitHub.