{"record":{"id":"d698962de372c888","repo":"apache/cassandra","slug":"threshold-must-be-less-than-integer-max-value","errorCode":null,"errorMessage":"Threshold must be less than Integer.MAX_VALUE","messagePattern":"Threshold must be less than Integer\\.MAX_VALUE","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/config/DatabaseDescriptor.java","lineNumber":5044,"sourceCode":"\n    public static EncryptionContext getEncryptionContext()\n    {\n        return encryptionContext;\n\n    }\n\n    public static long getGCWarnThreshold()\n    {\n        return conf.gc_warn_threshold.toMilliseconds();\n    }\n\n    public static void setGCWarnThreshold(long threshold)\n    {\n        if (threshold < 0)\n            throw new IllegalArgumentException(\"Threshold value for gc_warn_threshold must be greater than or equal to 0\");\n\n        if (threshold > Integer.MAX_VALUE)\n            throw new IllegalArgumentException(\"Threshold must be less than Integer.MAX_VALUE\");\n\n        long gcLogThresholdInMs = getGCLogThreshold();\n        if (threshold != 0 && threshold <= gcLogThresholdInMs)\n            throw new IllegalArgumentException(\"Threshold value for gc_warn_threshold (\" + threshold + \") must be greater than gc_log_threshold which is currently \"\n                                               + gcLogThresholdInMs);\n\n        conf.gc_warn_threshold = new DurationSpec.IntMillisecondsBound(threshold);\n    }\n\n    public static int getGCConcurrentPhaseLogThreshold()\n    {\n        return conf.gc_concurrent_phase_log_threshold.toMilliseconds();\n    }\n\n    public static void setGCConcurrentPhaseLogThreshold(int threshold)\n    {\n        if (threshold <= 0)\n            throw new IllegalArgumentException(\"Threshold must be greater than 0\");","sourceCodeStart":5026,"sourceCodeEnd":5062,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/config/DatabaseDescriptor.java#L5026-L5062","documentation":"DatabaseDescriptor.setGCWarnThreshold validates the gc_warn_threshold value. Any value above Integer.MAX_VALUE is rejected because the threshold is internally stored/compared against millisecond bounds that must fit an int-sized range. The caller passed a long that exceeds the allowed maximum.","triggerScenarios":"Calling setGCWarnThreshold(threshold) with a threshold > Integer.MAX_VALUE (2147483647 ms), e.g. passing a value in nanoseconds/microseconds by mistake, or a Long.MAX_VALUE sentinel.","commonSituations":"Unit conversion mistakes (seconds vs ms vs ns) when setting GC warn thresholds programmatically or via a config loader that does not pre-clamp values.","solutions":["Pass a threshold <= Integer.MAX_VALUE milliseconds (about 24.8 days)","Use 0 to disable the warn threshold","Fix the unit conversion so the value is expressed in milliseconds","Clamp the value before calling: Math.min(threshold, Integer.MAX_VALUE)"],"exampleFix":"// before\nDatabaseDescriptor.setGCWarnThreshold(60_000_000_000L); // ns for 60s\n// after\nDatabaseDescriptor.setGCWarnThreshold(60_000L); // ms for 60s","handlingStrategy":"validation","validationCode":"if (thresholdMs < 0 || thresholdMs > Integer.MAX_VALUE) throw new IllegalArgumentException(\"gc_warn_threshold must be in [0, Integer.MAX_VALUE] ms\");","typeGuard":null,"tryCatchPattern":"try { DatabaseDescriptor.setGCWarnThreshold(v); } catch (IllegalArgumentException e) { logger.error(\"invalid gc_warn_threshold: {}\", e.getMessage()); }","preventionTips":["Express all GC thresholds in milliseconds before calling setters","Clamp to Integer.MAX_VALUE when converting from other units","Test config parsing with boundary values"],"tags":["config","validation","gc","argument-out-of-range"],"backgroundTag":"value-out-of-range","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}