{"id":"aa04ab99c6640795","repo":"apache/kafka","slug":"unknown-compression-name","errorCode":null,"errorMessage":"Unknown compression name: {}","messagePattern":"Unknown compression name: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/common/record/internal/CompressionType.java","lineNumber":173,"sourceCode":"                return ZSTD;\n            default:\n                throw new IllegalArgumentException(\"Unknown compression type id: \" + id);\n        }\n    }\n\n    public static CompressionType forName(String name) {\n        if (NONE.name.equals(name))\n            return NONE;\n        else if (GZIP.name.equals(name))\n            return GZIP;\n        else if (SNAPPY.name.equals(name))\n            return SNAPPY;\n        else if (LZ4.name.equals(name))\n            return LZ4;\n        else if (ZSTD.name.equals(name))\n            return ZSTD;\n        else\n            throw new IllegalArgumentException(\"Unknown compression name: \" + name);\n    }\n\n    public int defaultLevel() {\n        throw new UnsupportedOperationException(\"Compression levels are not defined for this compression type: \" + name);\n    }\n\n    public int maxLevel() {\n        throw new UnsupportedOperationException(\"Compression levels are not defined for this compression type: \" + name);\n    }\n\n    public int minLevel() {\n        throw new UnsupportedOperationException(\"Compression levels are not defined for this compression type: \" + name);\n    }\n\n    public ConfigDef.Validator levelValidator() {\n        throw new UnsupportedOperationException(\"Compression levels are not defined for this compression type: \" + name);\n    }\n","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/common/record/internal/CompressionType.java#L155-L191","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use the exact lowercase canonical name: none, gzip, snappy, lz4, or zstd.","Trim whitespace and strip quotes from environment-variable-sourced config values before parsing.","If you need a codec Kafka does not support, switch to a supported type — bzip2/deflate/brotli are not implemented."],"exampleFix":"# before\ncompression.type=GZIP\n\n# after\ncompression.type=gzip","handlingStrategy":"validation","validationCode":"// CompressionType.forName is case-sensitive and matches exactly: none|gzip|snappy|lz4|zstd\nstatic final Set<String> KNOWN = Set.of(\"none\", \"gzip\", \"snappy\", \"lz4\", \"zstd\");\nString normalized = (name == null) ? null : name.trim().toLowerCase(Locale.ROOT);\nif (name == null || !KNOWN.contains(normalized)) {\n    throw new IllegalArgumentException(\"Unknown compression name: \" + name);\n}","typeGuard":"// Narrow an arbitrary string to a known compression name\nstatic Optional<CompressionType> safeForName(String name) {\n    if (name == null) return Optional.empty();\n    return Arrays.stream(CompressionType.values())\n        .filter(t -> t.name.equalsIgnoreCase(name.trim()))\n        .findFirst();\n}","tryCatchPattern":"try {\n    CompressionType t = CompressionType.forName(configValue);\n} catch (IllegalArgumentException e) {\n    // typo in config; log the valid set and fall back to a safe default\n    t = CompressionType.NONE;\n}","preventionTips":["Valid names are exactly: none, gzip, snappy, lz4, zstd (case-sensitive).","Normalize user input (trim + lowercase) before matching, or use ConfigDef's CompressionType validator.","Surface the list of accepted names in your config UI/docs to prevent typos."],"tags":["compression","configuration","illegal-argument","config-exception"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}