{"record":{"id":"8bf6c7cce598ec8f","repo":"prestodb/presto","slug":"invalid-weight","errorCode":null,"errorMessage":"Invalid weight: ","messagePattern":"Invalid weight: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-spi/src/main/java/com/facebook/presto/spi/SplitWeight.java","lineNumber":95,"sourceCode":"        }\n        return BigDecimal.valueOf(value, -UNIT_SCALE).stripTrailingZeros().toPlainString();\n    }\n\n    @JsonCreator\n    public static SplitWeight fromRawValue(long value)\n    {\n        return value == UNIT_VALUE ? STANDARD_WEIGHT : new SplitWeight(value);\n    }\n\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();","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-spi/src/main/java/com/facebook/presto/spi/SplitWeight.java#L77-L113","documentation":"SplitWeight.fromProportion converts a relative proportion (fraction of total work) into a SplitWeight. It throws IllegalArgumentException(\"Invalid weight: ...\") when the proportion is <= 0 or not finite (NaN or infinite).","triggerScenarios":"Calling SplitWeight.fromProportion(0), fromProportion(-0.5), fromProportion(Double.NaN), or fromProportion(Double.POSITIVE_INFINITY).","commonSituations":"Computing a weight from a ratio whose denominator was 0 (yielding NaN/Infinity); uninitialized or defaulted weighting factors of 0; averaging weights over an empty set.","solutions":["Clamp the proportion to a small positive value before calling, e.g. Math.max(proportion, 1e-9)","Fix the upstream computation producing NaN/infinity (check for division by zero)","Fall back to SplitWeight.STANDARD_WEIGHT when the computed proportion is not a valid positive finite number"],"exampleFix":"// before\nSplitWeight w = SplitWeight.fromProportion(ratio); // ratio may be NaN\n// after\nSplitWeight w = (ratio > 0 && Double.isFinite(ratio)) ? SplitWeight.fromProportion(ratio) : SplitWeight.STANDARD_WEIGHT;","handlingStrategy":"validation","validationCode":"boolean valid = weight > 0 && Double.isFinite(weight);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check for division-by-zero in code computing weight proportions","Clamp computed proportions to a small positive floor before conversion"],"tags":["spi","illegal-argument","split-weight","nan"],"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"}