{"record":{"id":"c9babdce79c38ac8","repo":"apache/cassandra","slug":"invalid-negative-or-null","errorCode":null,"errorMessage":"Invalid negative or null ","messagePattern":"Invalid negative or null ","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/schema/CompressionParams.java","lineNumber":463,"sourceCode":"     * Removes the {@code enabled} option from the specified options.\n     *\n     * @param options the options\n     * @return the value of the {@code enabled} option\n     */\n    private static boolean removeEnabled(Map<String, String> options)\n    {\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!","sourceCodeStart":445,"sourceCodeEnd":481,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/schema/CompressionParams.java#L445-L481","documentation":"CompressionParams.validate rejects a chunk length that is zero or negative. chunkLength is stored in bytes after parsing; a non-positive value would break chunked reading/writing of compressed sstables.","triggerScenarios":"Calling validate (via setCompressionParameters or fromMap) with chunk_length_in_kb resolving to <= 0 bytes. Note: absent chunk length is fine (default used); only explicitly parsed non-positive values trigger this.","commonSituations":"Passing '0' or a negative number for chunk_length_in_kb in a CREATE/ALTER TABLE compression map, often by templating with a computed default of 0.","solutions":["Set chunk_length_in_kb to a positive value, e.g. 4, 16, 32, or 64","Remove chunk_length_in_kb from the compression map to accept the default","Fix templating code so the default constant is not 0"],"exampleFix":"// before\n{'class': 'LZ4Compressor', 'chunk_length_in_kb': '0'}\n// after\n{'class': 'LZ4Compressor', 'chunk_length_in_kb': '16'}","handlingStrategy":"validation","validationCode":"if (kb <= 0) throw new IllegalArgumentException(\"chunk_length_in_kb must be positive, got: \" + kb);","typeGuard":null,"tryCatchPattern":"try { params.validate(); } catch (ConfigurationException e) { log.error(\"invalid compression params\", e); }","preventionTips":["Never template chunk_length_in_kb with a default of 0","Omit the key to use the default instead of forcing 0","Validate compression maps in CI before applying schema changes"],"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"}