{"id":"6047eea654cb4173","repo":"apache/kafka","slug":"unknown-compression-type-id","errorCode":null,"errorMessage":"Unknown compression type id: {}","messagePattern":"Unknown compression type id: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/common/record/internal/CompressionType.java","lineNumber":157,"sourceCode":"        this.id = id;\n        this.name = name;\n        this.rate = rate;\n    }\n\n    public static CompressionType forId(int id) {\n        switch (id) {\n            case 0:\n                return NONE;\n            case 1:\n                return GZIP;\n            case 2:\n                return SNAPPY;\n            case 3:\n                return LZ4;\n            case 4:\n                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","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/common/record/internal/CompressionType.java#L139-L175","documentation":"Thrown by CompressionType.forId(int) when the supplied id does not match any of the five defined compression ids (0=NONE, 1=GZIP, 2=SNAPPY, 3=LZ4, 4=ZSTD). The id is the two-bit code stored in a record batch's attributes field; an unknown id cannot be decoded to a compressor, so forId raises IllegalArgumentException. Typically surfaces when the attributes byte of a record batch is itself corrupt.","triggerScenarios":"Calling CompressionType.forId(id) with an id outside 0..4. In practice reached by RecordBatch attribute decoding (e.g., DefaultRecordBatch.compressionType() or AbstractLegacyRecordBatch) when the attributes field's compression bits hold a value like 5, 6, or 7.","commonSituations":"Corrupt record-batch attributes byte (bit-flip in the compression bits); reading a non-Kafka or partially-written buffer; a future Kafka version introduces a new compression id that the running older client does not recognize (forward-compatibility break).","solutions":["Inspect the segment with kafka-dump-log to confirm whether the attributes byte is genuinely corrupt or signals an unsupported newer compression type.","If corrupt, restore the segment from a healthy replica or delete it so the log truncates to the last valid offset.","If the value is a legitimate new id from a newer Kafka, upgrade the client/broker to a version that knows that compression type."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// CompressionType.forId only knows ids 0..4\nstatic final Set<Integer> KNOWN_IDS = Set.of(0, 1, 2, 3, 4);\nif (!KNOWN_IDS.contains(id)) {\n    throw new IllegalArgumentException(\"No compression type for id \" + id);\n}\nCompressionType t = CompressionType.forId(id);","typeGuard":"// Narrow a raw id to a valid CompressionType before use\nstatic Optional<CompressionType> safeForId(int id) {\n    return (id >= 0 && id <= 4)\n        ? Optional.of(CompressionType.forId(id))\n        : Optional.empty();\n}","tryCatchPattern":"try {\n    CompressionType t = CompressionType.forId(rawId);\n} catch (IllegalArgumentException e) {\n    // unknown wire id; default to NONE or reject the message\n}","preventionTips":["Only ids 0=none, 1=gzip, 2=snappy, 3=lz4, 4=zstd are valid.","Never hand-encode compression ids; always go through CompressionType.forId / .id.","When reading off the wire, expect and tolerate unknown ids for forward compatibility."],"tags":["compression","record-format","illegal-argument","corrupt-record"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}