{"record":{"id":"c071eed804c2817b","repo":"apache/cassandra","slug":"illegal-capacity-requestedcapacity","errorCode":null,"errorMessage":"Illegal capacity ${requestedCapacity}","messagePattern":"Illegal capacity (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/utils/streamhist/StreamingTombstoneHistogramBuilder.java","lineNumber":428,"sourceCode":"\n    /**\n     * This class is a specialized open addressing HashMap that uses int as keys and int as values.\n     * This is an optimization to avoid allocating objects.\n     * In order for this class to work correctly it should have a power of 2 capacity.\n     * This last invariant is taken care of during construction.\n     */\n    static class Spool\n    {\n        final long[] points;\n        final int[] values;\n\n        final int capacity;\n        int size;\n\n        Spool(int requestedCapacity)\n        {\n            if (requestedCapacity < 0)\n                throw new IllegalArgumentException(\"Illegal capacity \" + requestedCapacity);\n\n            this.capacity = getPowerOfTwoCapacity(requestedCapacity);\n\n            // x2 because we want no more than two reprobes on average when _capacity_ entries will be written\n            points = new long[capacity * 2];\n            values = new int[capacity * 2];\n            clear();\n        }\n\n        private int getPowerOfTwoCapacity(int requestedCapacity)\n        {\n            //for spool we need power-of-two cells\n            return requestedCapacity == 0 ? 0 : IntMath.pow(2, IntMath.log2(requestedCapacity, RoundingMode.CEILING));\n        }\n\n        void clear()\n        {\n            Arrays.fill(points, -1);","sourceCodeStart":410,"sourceCodeEnd":446,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/utils/streamhist/StreamingTombstoneHistogramBuilder.java#L410-L446","documentation":"StreamingTombstoneHistogramBuilder.Spool validates its requestedCapacity and throws IllegalArgumentException when it is negative. The spool backs the histogram's sampling phase and cannot allocate a negative-capacity structure.","triggerScenarios":"Constructing StreamingTombstoneHistogramBuilder (or otherwise instantiating the internal Spool) with requestedCapacity < 0, usually from a computed value like maxBinSize or a band parameter that underflowed.","commonSituations":"Hand-tuned cassandra.yaml histogram settings (e.g. tombstone_warn_threshold / histogram bin sizes) producing negative derived capacities; integer underflow in calling code.","solutions":["Pass a positive capacity: check requestedCapacity >= 0 before constructing and clamp to a sensible minimum (e.g. Math.max(1, capacity)).","Fix the computation producing the negative value (often a subtraction or bad config-derived parameter).","If capacity 0 is intended, note the check is < 0, so 0 is accepted; negative values indicate a caller bug."],"exampleFix":"// before\nnew StreamingTombstoneHistogramBuilder(zeroTime, roundSeconds, maxBinSize, volumeType, capacity);\n// after\nint safeCapacity = Math.max(1, capacity);\nnew StreamingTombstoneHistogramBuilder(zeroTime, roundSeconds, maxBinSize, volumeType, safeCapacity);","handlingStrategy":"validation","validationCode":"if (capacity < 0) throw new IllegalArgumentException(\"capacity must be >= 0, got \" + capacity);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp derived capacities with Math.max(0, value) before constructing histograms.","Check cassandra.yaml histogram-related settings for values that can go negative after arithmetic."],"tags":["histogram","validation","java"],"backgroundTag":"invalid-constructor-argument","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"}