{"record":{"id":"a86b87a6355d2b6d","repo":"prestodb/presto","slug":"splitcount-must-be-0-found","errorCode":null,"errorMessage":"splitCount must be >= 0, found: ","messagePattern":"splitCount must be >= 0, found: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-spi/src/main/java/com/facebook/presto/spi/SplitWeight.java","lineNumber":104,"sourceCode":"\n    public static SplitWeight standard()\n    {\n        return STANDARD_WEIGHT;\n    }\n\n    public static SplitWeight fromProportion(double weight)\n    {\n        if (weight <= 0 || !Double.isFinite(weight)) {\n            throw new IllegalArgumentException(\"Invalid weight: \" + weight);\n        }\n        // Must round up to avoid small weights rounding to 0\n        return fromRawValue((long) Math.ceil(weight * UNIT_VALUE));\n    }\n\n    public static long rawValueForStandardSplitCount(int splitCount)\n    {\n        if (splitCount < 0) {\n            throw new IllegalArgumentException(\"splitCount must be >= 0, found: \" + splitCount);\n        }\n        return multiplyExact(splitCount, UNIT_VALUE);\n    }\n\n    public static <T> long rawValueSum(Collection<T> collection, Function<T, SplitWeight> getter)\n    {\n        long sum = 0;\n        for (T item : collection) {\n            long value = getter.apply(item).getRawValue();\n            sum = addExact(sum, value);\n        }\n        return sum;\n    }\n}\n","sourceCodeStart":86,"sourceCodeEnd":119,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-spi/src/main/java/com/facebook/presto/spi/SplitWeight.java#L86-L119","documentation":"SplitWeight.rawValueForStandardSplitCount converts a count of standard-weight splits into a raw weight value using Math.multiplyExact. It throws IllegalArgumentException(\"splitCount must be >= 0, found: ...\") when splitCount is negative.","triggerScenarios":"Calling SplitWeight.rawValueForStandardSplitCount(-1) or any negative count, typically from bookkeeping code computing split counts that underflowed.","commonSituations":"Subtracting more splits than were added in a stats tracker; int underflow on large counters; passing a delta instead of an absolute count.","solutions":["Fix the caller so split counts never go negative (use max(0, count))","Audit increment/decrement logic for double decrements or underflow","Note multiplyExact will also throw ArithmeticException on overflow, so validate the range of the count too"],"exampleFix":"// before\nlong raw = SplitWeight.rawValueForStandardSplitCount(delta);\n// after\nlong raw = SplitWeight.rawValueForStandardSplitCount(Math.max(0, delta));","handlingStrategy":"validation","validationCode":"if (splitCount < 0) splitCount = 0;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp counters/deltas with Math.max(0, n) before use","Beware int overflow when tracking split counts; use long internally"],"tags":["spi","illegal-argument","split-weight"],"backgroundTag":"invalid-numeric-value","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}