apache/cassandra · error · java.lang.IllegalArgumentException

Threshold value for gc_warn_threshold must be greater than o

Error message

Threshold value for gc_warn_threshold must be greater than or equal to 0

What it means

Cassandra throws this IllegalArgumentException from setGCWarnThreshold when the threshold is negative. gc_warn_threshold controls the GC pause duration (ms) above which a warning is logged; 0 disables it, but negative values are invalid.

Source

Thrown at src/java/org/apache/cassandra/config/DatabaseDescriptor.java:5041

            throw new IllegalArgumentException("Threshold value for gc_log*_threshold (" + logThreshold + ") must be less than gc_warn*_threshold which is currently "
                    + warnThreshold);
    }

    public static EncryptionContext getEncryptionContext()
    {
        return encryptionContext;

    }

    public static long getGCWarnThreshold()
    {
        return conf.gc_warn_threshold.toMilliseconds();
    }

    public static void setGCWarnThreshold(long threshold)
    {
        if (threshold < 0)
            throw new IllegalArgumentException("Threshold value for gc_warn_threshold must be greater than or equal to 0");

        if (threshold > Integer.MAX_VALUE)
            throw new IllegalArgumentException("Threshold must be less than Integer.MAX_VALUE");

        long gcLogThresholdInMs = getGCLogThreshold();
        if (threshold != 0 && threshold <= gcLogThresholdInMs)
            throw new IllegalArgumentException("Threshold value for gc_warn_threshold (" + threshold + ") must be greater than gc_log_threshold which is currently "
                                               + gcLogThresholdInMs);

        conf.gc_warn_threshold = new DurationSpec.IntMillisecondsBound(threshold);
    }

    public static int getGCConcurrentPhaseLogThreshold()
    {
        return conf.gc_concurrent_phase_log_threshold.toMilliseconds();
    }

    public static void setGCConcurrentPhaseLogThreshold(int threshold)

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Pass a non-negative value; 0 disables warn-threshold GC logging
  2. Keep the value below Integer.MAX_VALUE (the setter throws next if exceeded)
  3. Keep the value greater than gc_log_threshold to avoid the ordering error

Example fix

// before
DatabaseDescriptor.setGCWarnThreshold(-500);
// after
DatabaseDescriptor.setGCWarnThreshold(1000);
Defensive patterns

Strategy: validation

Validate before calling

if (threshold < 0 || threshold > Integer.MAX_VALUE)
    throw new IllegalArgumentException("gc_warn_threshold must be >= 0 and <= Integer.MAX_VALUE ms");

Try / catch

try {
    DatabaseDescriptor.setGCWarnThreshold(threshold);
} catch (IllegalArgumentException e) {
    logger.warn("Invalid gc_warn_threshold; keeping current value", e);
}

Prevention

When it happens

Trigger: Calling DatabaseDescriptor.setGCWarnThreshold(-1) or any negative long, via JMX runtime config updates or programmatic configuration.

Common situations: Automation passing an unvalidated long (e.g. a parsed config with a stray minus), or scripts intending 0 (= disabled) but computing a negative value.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/61c50528578ed0d7. Report an issue: GitHub.