{"record":{"id":"1d12cfc8e3939cb6","repo":"apache/cassandra","slug":"log10-of-number-zero-or-less","errorCode":null,"errorMessage":"Log10 of number zero or less","messagePattern":"Log10 of number zero or less","errorType":"validation","errorClass":"ArithmeticException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/DecimalType.java","lineNumber":453,"sourceCode":"\n    protected BigDecimal log(BigDecimal input)\n    {\n        if (input.compareTo(BigDecimal.ZERO) <= 0) throw new ArithmeticException(\"Natural log of number zero or less\");\n        int precision = input.precision();\n        precision = Math.max(MIN_SIGNIFICANT_DIGITS, precision);\n        precision = Math.min(MAX_PRECISION.getPrecision(), precision);\n        return BigDecimalMath.log(input, new MathContext(precision, RoundingMode.HALF_EVEN));\n    }\n\n    @Override\n    public ByteBuffer log10(Number input)\n    {\n        return decompose(log10(toBigDecimal(input)));\n    }\n\n    protected BigDecimal log10(BigDecimal input)\n    {\n        if (input.compareTo(BigDecimal.ZERO) <= 0) throw new ArithmeticException(\"Log10 of number zero or less\");\n        int precision = input.precision();\n        precision = Math.max(MIN_SIGNIFICANT_DIGITS, precision);\n        precision = Math.min(MAX_PRECISION.getPrecision(), precision);\n        return BigDecimalMath.log10(input, new MathContext(precision, RoundingMode.HALF_EVEN));\n    }\n\n    @Override\n    public ByteBuffer round(Number input)\n    {\n        return DecimalType.instance.decompose(\n        toBigDecimal(input).setScale(0, RoundingMode.HALF_UP));\n    }\n\n    @Override\n    public ByteBuffer getMaskedValue()\n    {\n        return MASKED_VALUE;\n    }","sourceCodeStart":435,"sourceCodeEnd":471,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/DecimalType.java#L435-L471","documentation":"Fired in DecimalType.log10 when the input Number converts to a BigDecimal that is zero or negative; logarithm is undefined there, so an ArithmeticException is thrown. Reached via log10() for CQL native functions on numeric arguments.","triggerScenarios":"Executing a CQL expression like log10(col) reaching log10(Number) with input <= 0.","commonSituations":"Log-scaling metrics that can be zero (counts) or negative (differences); unfiltered user-supplied values.","solutions":["Add WHERE col > 0 filtering before applying log10()","Wrap in CASE or a UDF returning null for non-positive input","Validate/clean data at write time to keep the column strictly positive"],"exampleFix":"// before\nSELECT log10(count_col) FROM metrics;\n// after\nSELECT log10(count_col) FROM metrics WHERE count_col > 0;","handlingStrategy":"validation","validationCode":"if (input == null || input.signum() <= 0) throw new IllegalArgumentException(\"log10 requires a strictly positive value\");","typeGuard":"boolean isPositive(BigDecimal v) { return v != null && v.signum() > 0; }","tryCatchPattern":"try { result = DecimalType.instance.log10(value); } catch (ArithmeticException e) { /* map non-positive input to null/default */ }","preventionTips":["Filter col > 0 in queries using log10()","Use CASE or UDF to nullify non-positive inputs","Validate positivity of count-like columns at write time"],"tags":["decimal","math","logarithm"],"backgroundTag":"value-out-of-range","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"}