{"record":{"id":"02af88aba79983b0","repo":"apache/cassandra","slug":"an-infinite-number-cannot-be-converted-into-a-deci","errorCode":null,"errorMessage":"An infinite number cannot be converted into a decimal","messagePattern":"An infinite number cannot be converted into a decimal","errorType":"validation","errorClass":"NumberFormatException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/DecimalType.java","lineNumber":355,"sourceCode":"     *\n     * @param number the value to convert\n     * @return the converted value\n     */\n    protected BigDecimal toBigDecimal(Number number)\n    {\n        if (number instanceof BigDecimal)\n            return (BigDecimal) number;\n\n        if (number instanceof BigInteger)\n            return new BigDecimal((BigInteger) number);\n\n        double d = number.doubleValue();\n\n        if (Double.isNaN(d))\n            throw new NumberFormatException(\"A NaN cannot be converted into a decimal\");\n\n        if (Double.isInfinite(d))\n            throw new NumberFormatException(\"An infinite number cannot be converted into a decimal\");\n\n        return BigDecimal.valueOf(d);\n    }\n\n    @Override\n    public ByteBuffer add(Number left, Number right)\n    {\n        return decompose(toBigDecimal(left).add(toBigDecimal(right), MAX_PRECISION));\n    }\n\n    @Override\n    public ByteBuffer substract(Number left, Number right)\n    {\n        return decompose(toBigDecimal(left).subtract(toBigDecimal(right), MAX_PRECISION));\n    }\n\n    @Override\n    public ByteBuffer multiply(Number left, Number right)","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/DecimalType.java#L337-L373","documentation":"DecimalType.toBigDecimal also rejects infinite values: BigDecimal has no representation for +/-infinity, so a Number whose doubleValue() is infinite raises this NumberFormatException from any decimal arithmetic operation (add/substract/multiply/mod, etc.).","triggerScenarios":"Passing Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY (e.g. from 1.0/0.0 or overflow of a double computation) into DecimalType.add/substract/multiply/mod/leftOperand/rightOperand.","commonSituations":"Division by zero upstream producing infinity; overflow of double-valued intermediates then combined with decimals; importing JSON with Infinity tokens.","solutions":["Check Double.isInfinite(d) before calling the arithmetic methods","Clamp or reject out-of-range values at ingestion","Fix the upstream computation (guard denominators, use BigDecimal throughout)"],"exampleFix":"// before\nreturn decimalType.multiply(a, b);\n// after\nif (Double.isInfinite(a.doubleValue()) || Double.isInfinite(b.doubleValue()))\n    throw new IllegalArgumentException(\"operands must be finite\");\nreturn decimalType.multiply(a, b);","handlingStrategy":"type-guard","validationCode":"if (Double.isInfinite(x.doubleValue()) || Double.isInfinite(y.doubleValue())) throw new IllegalArgumentException(\"infinite operand not allowed in decimal arithmetic\");","typeGuard":"boolean isFiniteNumber(Number n) { double d = n.doubleValue(); return !Double.isNaN(d) && !Double.isInfinite(d); }","tryCatchPattern":"try { return DecimalType.instance.multiply(l, r); } catch (NumberFormatException e) { if (e.getMessage().contains(\"infinite\")) { /* handle infinite operand */ } throw e; }","preventionTips":["Guard divisions against zero to avoid infinities","Use BigDecimal end-to-end for large-magnitude math","Validate imported numbers for finiteness"],"tags":["decimal","arithmetic","infinity"],"backgroundTag":"invalid-number-format","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"}