{"record":{"id":"c110dbfad742233a","repo":"apache/cassandra","slug":"s-must-not-be-negative-but-was-d","errorCode":null,"errorMessage":"%s must not be negative, but was %d","messagePattern":"(.+?) must not be negative, but was (.+?)","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/compaction/TimeWindowCompactionStrategyOptions.java","lineNumber":142,"sourceCode":"        {\n            int sstableWindowSize = optionValue == null ? DEFAULT_COMPACTION_WINDOW_SIZE : Integer.parseInt(optionValue);\n            if (sstableWindowSize < 1)\n            {\n                throw new ConfigurationException(String.format(\"%d must be greater than 1 for %s\", sstableWindowSize, COMPACTION_WINDOW_SIZE_KEY));\n            }\n        }\n        catch (NumberFormatException e)\n        {\n            throw new ConfigurationException(String.format(\"%s is not a parsable int (base10) for %s\", optionValue, COMPACTION_WINDOW_SIZE_KEY), e);\n        }\n\n        optionValue = options.get(EXPIRED_SSTABLE_CHECK_FREQUENCY_SECONDS_KEY);\n        try\n        {\n            long expiredCheckFrequency = optionValue == null ? DEFAULT_EXPIRED_SSTABLE_CHECK_FREQUENCY_SECONDS : Long.parseLong(optionValue);\n            if (expiredCheckFrequency < 0)\n            {\n                throw new ConfigurationException(String.format(\"%s must not be negative, but was %d\", EXPIRED_SSTABLE_CHECK_FREQUENCY_SECONDS_KEY, expiredCheckFrequency));\n             }\n        }\n        catch (NumberFormatException e)\n        {\n            throw new ConfigurationException(String.format(\"%s is not a parsable int (base10) for %s\", optionValue, EXPIRED_SSTABLE_CHECK_FREQUENCY_SECONDS_KEY), e);\n        }\n\n\n        optionValue = options.get(UNSAFE_AGGRESSIVE_SSTABLE_EXPIRATION_KEY);\n        if (optionValue != null)\n        {\n            if (!(optionValue.equalsIgnoreCase(\"true\") || optionValue.equalsIgnoreCase(\"false\")))\n                throw new ConfigurationException(String.format(\"%s is not 'true' or 'false' (%s)\", UNSAFE_AGGRESSIVE_SSTABLE_EXPIRATION_KEY, optionValue));\n\n            if (optionValue.equalsIgnoreCase(\"true\") && !UNSAFE_AGGRESSIVE_SSTABLE_EXPIRATION_ENABLED)\n                throw new ConfigurationException(String.format(\"%s is requested but not allowed, restart cassandra with -D%s=true to allow it\",\n                                                               UNSAFE_AGGRESSIVE_SSTABLE_EXPIRATION_KEY, ALLOW_UNSAFE_AGGRESSIVE_SSTABLE_EXPIRATION.getKey()));\n        }","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/compaction/TimeWindowCompactionStrategyOptions.java#L124-L160","documentation":"TWCS rejects a negative expired_sstable_check_frequency_seconds option. This option controls how often (in seconds) the strategy checks for fully expired sstables; a negative interval is meaningless, so validateOptions throws ConfigurationException with the offending key and parsed value.","triggerScenarios":"validateOptions invoked with expired_sstable_check_frequency_seconds set to a negative long, e.g. '-60' (a non-numeric value triggers error 882 instead).","commonSituations":"Signing a value meant to be a timestamp offset; blindly templating '-1' as a sentinel for 'disabled' (wrong option — 0 disables it); typos like an accidental minus sign.","solutions":["Change the value to a non-negative integer, e.g. '600' (seconds)","Use 0 to disable expired sstable checks entirely","Remove the option to fall back to the default (600 seconds)","Catch ConfigurationException when validating user-supplied table options"],"exampleFix":"// before\n{'class':'TimeWindowCompactionStrategy','expired_sstable_check_frequency_seconds':'-60'}\n// after\n{'class':'TimeWindowCompactionStrategy','expired_sstable_check_frequency_seconds':'600'}","handlingStrategy":"validation","validationCode":"if (opts.containsKey(\"expired_sstable_check_frequency_seconds\") && Long.parseLong(opts.get(\"expired_sstable_check_frequency_seconds\")) < 0)\n    throw new IllegalArgumentException(\"expired_sstable_check_frequency_seconds must be >= 0\");","typeGuard":"static boolean isNonNegativeLong(String s) { if (s == null) return false; try { return Long.parseLong(s.trim()) >= 0; } catch (NumberFormatException e) { return false; } }","tryCatchPattern":"try {\n    session.execute(alterStmt);\n} catch (RuntimeException e) {\n    if (e.getMessage().contains(\"must not be negative\")) { /* fix value and retry */ }\n    throw e;\n}","preventionTips":["Use 0 (not -1) to disable expired sstable checks","Keep a validated defaults map for TWCS options","Add schema-option linters to config pipelines","Document that the unit is seconds"],"tags":["cassandra","configuration","compaction","negative-value"],"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"}