{"record":{"id":"49b4e9603bac3f68","repo":"apache/cassandra","slug":"log10-of-number-zero-or-less-49b4e9","errorCode":null,"errorMessage":"Log10 of number zero or less","messagePattern":"Log10 of number zero or less","errorType":"exception","errorClass":"ArithmeticException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/IntegerType.java","lineNumber":584,"sourceCode":"        return IntegerType.instance.decompose(out);\n    }\n\n    @Override\n    public ByteBuffer log(Number input)\n    {\n        BigInteger bi = toBigInteger(input);\n        if (bi.compareTo(BigInteger.ZERO) <= 0) throw new ArithmeticException(\"Natural log of number zero or less\");\n        BigDecimal bd = new BigDecimal(bi);\n        BigDecimal result = DecimalType.instance.log(bd);\n        BigInteger out = result.toBigInteger();\n        return IntegerType.instance.decompose(out);\n    }\n\n    @Override\n    public ByteBuffer log10(Number input)\n    {\n        BigInteger bi = toBigInteger(input);\n        if (bi.compareTo(BigInteger.ZERO) <= 0) throw new ArithmeticException(\"Log10 of number zero or less\");\n        BigDecimal bd = new BigDecimal(bi);\n        BigDecimal result = DecimalType.instance.log10(bd);\n        BigInteger out = result.toBigInteger();\n        return IntegerType.instance.decompose(out);\n    }\n\n    @Override\n    public ByteBuffer round(Number input)\n    {\n        return decompose(toBigInteger(input));\n    }\n\n    @Override\n    public ByteBuffer getMaskedValue()\n    {\n        return MASKED_VALUE;\n    }\n}","sourceCodeStart":566,"sourceCodeEnd":602,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/IntegerType.java#L566-L602","documentation":"IntegerType.log10 computes the base-10 logarithm of an integer value. Because log10 is mathematically undefined for zero and negative numbers, the method proactively throws ArithmeticException when the parsed BigInteger is <= 0 instead of letting BigDecimal math fail later.","triggerScenarios":"Calling log10() (via the log10 CQL native function or directly on IntegerType.instance) with a value of 0, a negative number, or a value that converts to BigInteger <= 0.","commonSituations":"CQL queries like SELECT log10(col) where col is 0 or negative; user-supplied function arguments not validated by the application; log math applied to counters or deltas that can be zero or negative.","solutions":["Validate the input is strictly positive before calling log10 (e.g. WHERE col > 0 or application-side check).","Use a CASE/IF expression in CQL to guard: log10(col) only when col > 0, else a fallback value.","If negatives are expected, take abs() first or handle the domain explicitly in application code."],"exampleFix":"// before\nSELECT log10(delta) FROM metrics;\n// after\nSELECT CASE WHEN delta > 0 THEN log10(delta) ELSE null END FROM metrics;","handlingStrategy":"validation","validationCode":"if (value == null || value.signum() <= 0) throw new IllegalArgumentException(\"log10 requires a value > 0, got: \" + value);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate positivity at the application boundary before issuing log10 in a query.","Use CASE WHEN in CQL to guard function arguments.","Remember log10's domain excludes 0 and negatives; document that constraint for API consumers."],"tags":["arithmetic","math","domain-error","cql-function"],"backgroundTag":"invalid-argument-value","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"}