{"id":"5010f95d4d44f687","repo":"apache/kafka","slug":"value-must-be-non-null-5010f9","errorCode":null,"errorMessage":"Value must be non-null","messagePattern":"Value must be non-null","errorType":"validation","errorClass":"ConfigException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/common/record/internal/CompressionType.java","lineNumber":57,"sourceCode":"        public int defaultLevel() {\n            return DEFAULT_LEVEL;\n        }\n\n        @Override\n        public int maxLevel() {\n            return MAX_LEVEL;\n        }\n\n        @Override\n        public int minLevel() {\n            return MIN_LEVEL;\n        }\n\n        @Override\n        public ConfigDef.Validator levelValidator() {\n            return ConfigDef.LambdaValidator.with((name, value) -> {\n                if (value == null)\n                    throw new ConfigException(name, null, \"Value must be non-null\");\n                int level = ((Number) value).intValue();\n                if (level > MAX_LEVEL || (level < MIN_LEVEL && level != DEFAULT_LEVEL)) {\n                    throw new ConfigException(name, value, \"Value must be between \" + MIN_LEVEL + \" and \" + MAX_LEVEL + \" or equal to \" + DEFAULT_LEVEL);\n                }\n            }, () -> \"[\" + MIN_LEVEL + \",...,\" + MAX_LEVEL + \"] or \" + DEFAULT_LEVEL);\n        }\n    },\n\n    // We should only load classes from a given compression library when we actually use said compression library. This\n    // is because compression libraries include native code for a set of platforms and we want to avoid errors\n    // in case the platform is not supported and the compression library is not actually used.\n    // To ensure this, we only reference compression library code from classes that are only invoked when actual usage\n    // happens.\n    SNAPPY((byte) 2, \"snappy\", 1.0f),\n    LZ4((byte) 3, \"lz4\", 1.0f) {\n        // These values come from net.jpountz.lz4.LZ4Constants\n        // We may need to update them if the lz4 library changes these values.\n        private static final int MIN_LEVEL = 1;","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/common/record/internal/CompressionType.java#L39-L75","documentation":"Thrown by the GZIP compression level validator inside CompressionType when the supplied config value is null. GZIP overrides levelValidator() to enforce the java.util.zip.Deflater level contract; a null level cannot be coerced to an int, so validation fails fast with ConfigException rather than NPE-ing later during compression.","triggerScenarios":"Configuring compression.type=gzip together with a compression-level setting (e.g.,compression.level / producer config) whose value resolves to null — for example, an explicitly null producer property, an unset property dereferenced via ConfigDef.parse, or a config key typo that the validator receives as null.","commonSituations":"A properties file or env var override that sets compression.level to an empty/placeholder value parsed as null; a programmatic ProducerConfig map missing the key while GZIP is selected; misconfigured Connect worker using gzip with a null level.","solutions":["Explicitly set the compression level property to a valid Deflater level (BEST_SPEED=1 .. BEST_COMPRESSION=9) or DEFAULT_COMPRESSION (-1).","Remove the explicit null/empty override so the validator falls back to the default level.","Verify the exact producer/broker config key name spelling against ConfigDef to ensure the value reaches the validator."],"exampleFix":"// before\nprops.put(ProducerConfig.COMPRESSION_TYPE_CONFIG, \"gzip\");\nprops.put(\"compression.level\", null);\n\n// after\nprops.put(ProducerConfig.COMPRESSION_TYPE_CONFIG, \"gzip\");\nprops.put(\"compression.level\", Deflater.DEFAULT_COMPRESSION);","handlingStrategy":"validation","validationCode":"// Before configuring a GZIP compression level:\nif (level == null) {\n    throw new IllegalArgumentException(\"compression.level must not be null\");\n}\n// Then pass a non-null Integer/Number to the validator.","typeGuard":"// Ensure the config value is a non-null Number before validation\nstatic boolean isNonNullNumber(Object v) {\n    return v instanceof Number;\n}","tryCatchPattern":"try {\n    compressionType.levelValidator().ensureValid(name, value);\n} catch (org.apache.kafka.common.config.ConfigException e) {\n    // value was null or invalid; supply a default level via defaultLevel()\n}","preventionTips":["Always supply an explicit compression level (or rely on defaultLevel()) rather than passing null.","Validate config values at load time before constructing producers/consumers.","Prefer CompressionType.forName(...).defaultLevel() over user-supplied nulls."],"tags":["compression","gzip","configuration","config-exception"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}