{"id":"9e76c8261311bd90","repo":"apache/kafka","slug":"gzip-doesn-t-support-given-compression-level-leve","errorCode":null,"errorMessage":"gzip doesn't support given compression level: level","messagePattern":"gzip doesn't support given compression level: level","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/common/compress/GzipCompression.java","lineNumber":103,"sourceCode":"    @Override\n    public boolean equals(Object o) {\n        if (this == o) return true;\n        if (o == null || getClass() != o.getClass()) return false;\n        GzipCompression that = (GzipCompression) o;\n        return level == that.level;\n    }\n\n    @Override\n    public int hashCode() {\n        return Objects.hash(level);\n    }\n\n    public static class Builder implements Compression.Builder<GzipCompression> {\n        private int level = GZIP.defaultLevel();\n\n        public Builder level(int level) {\n            if ((level < GZIP.minLevel() || GZIP.maxLevel() < level) && level != GZIP.defaultLevel()) {\n                throw new IllegalArgumentException(\"gzip doesn't support given compression level: \" + level);\n            }\n\n            this.level = level;\n            return this;\n        }\n\n        @Override\n        public GzipCompression build() {\n            return new GzipCompression(level);\n        }\n    }\n}\n","sourceCodeStart":85,"sourceCodeEnd":116,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/common/compress/GzipCompression.java#L85-L116","documentation":"Thrown by GzipCompression.Builder.level(int) when the requested compression level is outside the bounds returned by CompressionType.GZIP.minLevel()/maxLevel() AND is not the default level. GZIP levels (1-9, JDK Deflater range) are bounded; passing 0, -1 (unless it equals defaultLevel()), 10, or any other out-of-range int is rejected with IllegalArgumentException at builder time rather than later during record compression.","triggerScenarios":"Calling `new GzipCompression.Builder().level(n)` with n < minLevel() (e.g. 0) or n > maxLevel() (e.g. 10 or 100). Typically reached when compression level comes from external config (producer.compression.gzip.level), a typo, or arithmetic that yields an out-of-range int.","commonSituations":"Misreading the gzip level range (assuming 0-9 or 1-12 like zstd); passing -1 expecting 'default' when defaultLevel() is a different value; config files with stale/wrong values copied from another codec's docs; dynamic config without validation.","solutions":["Use a level within [GZIP.minLevel(), GZIP.maxLevel()] (currently 1..9).","Omit the level() call entirely to accept the default, which is always allowed.","If you need 'use the default' explicitly, pass GZIP.defaultLevel() rather than guessing.","Validate external config values before forwarding them to the builder."],"exampleFix":"// before\nnew GzipCompression.Builder().level(0).build();\n\n// after\nnew GzipCompression.Builder().build(); // default level\n// or\nnew GzipCompression.Builder().level(6).build(); // explicit valid level","handlingStrategy":"validation","validationCode":"// GZIP.level accepts [minLevel..maxLevel] or exactly defaultLevel\nint level = /* from config */;\nif (level != GZIP.defaultLevel()\n        && (level < GZIP.minLevel() || level > GZIP.maxLevel())) {\n    // clamp or reject; do NOT forward to GzipCompression.Builder.level(level)\n}","typeGuard":null,"tryCatchPattern":"try {\n    Compression gzip = new GzipCompression.Builder().level(level).build();\n} catch (IllegalArgumentException e) {\n    // \"gzip doesn't support given compression level\"; fall back to defaultLevel()\n}","preventionTips":["Default to GZIP.defaultLevel(); only override when profiling justifies it.","If level comes from config/user input, clamp with min(max(level, minLevel()), maxLevel()) instead of passing it through.","Document the valid range next to the config key so operators do not guess (typically 1..9).","Treat an out-of-range level as a config error that fails deployment, not a runtime exception."],"tags":["compression","gzip","producer","argument","java"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}