{"record":{"id":"ae2849c0a81e3516","repo":"apache/cassandra","slug":"invalid-negative-min-compress-ratio","errorCode":null,"errorMessage":"Invalid negative min_compress_ratio","messagePattern":"Invalid negative min_compress_ratio","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/schema/CompressionParams.java","lineNumber":469,"sourceCode":"    {\n        String enabled = options.remove(ENABLED);\n        return enabled == null || Boolean.parseBoolean(enabled);\n    }\n\n    // chunkLength must be a power of 2 because we assume so when\n    // computing the chunk number from an uncompressed file offset (see\n    // CompressedRandomAccessReader.decompresseChunk())\n    public void validate() throws ConfigurationException\n    {\n        // if chunk length was not set (chunkLength == null), this is fine, default will be used\n        if (chunkLength <= 0)\n            throw new ConfigurationException(\"Invalid negative or null \" + CHUNK_LENGTH_IN_KB);\n\n        if ((chunkLength & (chunkLength - 1)) != 0)\n            throw new ConfigurationException(CHUNK_LENGTH_IN_KB + \" must be a power of 2\");\n\n        if (maxCompressedLength < 0)\n            throw new ConfigurationException(\"Invalid negative \" + MIN_COMPRESS_RATIO);\n\n        if (maxCompressedLength > chunkLength && maxCompressedLength < Integer.MAX_VALUE)\n            throw new ConfigurationException(MIN_COMPRESS_RATIO + \" can either be 0 or greater than or equal to 1\");\n    }\n\n    public Map<String, String> asMap()\n    {\n        if (!isEnabled())\n            return Collections.singletonMap(ENABLED, \"false\");\n\n        Map<String, String> options = new HashMap<>(otherOptions);\n        // Use the one saved in the registry, we don't want to save the name of the service provider compressor here!\n        options.put(CLASS, sstableCompressor.serializedAs().getName());\n        options.put(CHUNK_LENGTH_IN_KB, chunkLengthInKB());\n        if (minCompressRatio != DEFAULT_MIN_COMPRESS_RATIO)\n            options.put(MIN_COMPRESS_RATIO, String.valueOf(minCompressRatio));\n\n        return options;","sourceCodeStart":451,"sourceCodeEnd":487,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/schema/CompressionParams.java#L451-L487","documentation":"Fired in CompressionParams.validate: min_compress_ratio was set to a value < 1 (negative or otherwise invalid; ratio must be >= 1). Validation runs when compression parameters are applied via CREATE/ALTER TABLE (setCompressionParameters, fromMap), throwing ConfigurationException before the schema change commits.","triggerScenarios":"Calling validate (via setCompressionParameters or fromMap) with min_compress_ratio set to a negative number.","commonSituations":"Sign/typo mistakes like '-1' or '-0.5' in a compression map; templating where a ratio was computed as negative.","solutions":["Set min_compress_ratio to 0 (no minimum) or a value >= 1","Remove min_compress_ratio to use the default","Clamp computed ratios with Math.max(0, ratio) in schema-building code"],"exampleFix":"// before\n{'class': 'LZ4Compressor', 'min_compress_ratio': '-0.5'}\n// after\n{'class': 'LZ4Compressor', 'min_compress_ratio': '1.1'}","handlingStrategy":"validation","validationCode":"if (ratio < 0) throw new IllegalArgumentException(\"min_compress_ratio must not be negative, got: \" + ratio);","typeGuard":null,"tryCatchPattern":"try { params.validate(); } catch (ConfigurationException e) { log.error(\"negative min_compress_ratio\", e); }","preventionTips":["Clamp computed ratios with Math.max(0, x) in schema-building code","Check for sign errors when writing ratios by hand","Use 0 to mean 'disabled'"],"tags":["config","compression","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}