{"record":{"id":"10af7452f9386fca","repo":"apache/cassandra","slug":"natural-log-of-number-zero-or-less-10af74","errorCode":null,"errorMessage":"Natural log of number zero or less","messagePattern":"Natural log of number zero or less","errorType":"exception","errorClass":"ArithmeticException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/IntegerType.java","lineNumber":573,"sourceCode":"    {\n        return decompose(toBigInteger(input).abs());\n    }\n\n    @Override\n    public ByteBuffer exp(Number input)\n    {\n        BigInteger bi = toBigInteger(input);\n        BigDecimal bd = new BigDecimal(bi);\n        BigDecimal result = DecimalType.instance.exp(bd);\n        BigInteger out = result.toBigInteger();\n        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","sourceCodeStart":555,"sourceCodeEnd":591,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/IntegerType.java#L555-L591","documentation":"IntegerType.log(Number) computes the natural log of a varint by first converting the input to a BigInteger; if the value is zero or negative it throws ArithmeticException with this message, mirroring Math.log's domain restriction. This is a mathematical domain error: log is only defined for strictly positive inputs.","triggerScenarios":"Calling IntegerType.instance.log(number) (e.g. via the log() CQL native function) with 0 or a negative varint argument; toBigInteger(input).compareTo(BigInteger.ZERO) <= 0 triggers the throw.","commonSituations":"User-supplied function arguments of 0 or negative values in SELECT log(x); data columns that unexpectedly contain zero/negative values (sensor dropouts, accounting deltas); sign errors in computed expressions.","solutions":["Guard the input and only call log(x) when x > 0 (e.g. log(x + 1) or filter WHERE x > 0 first)","Handle negative/zero domain needs explicitly in the query (CASE/IF expressions)","Fix upstream data producing non-positive values","Catch ArithmeticException around the function invocation if input cannot be pre-validated"],"exampleFix":"// before\nSELECT log(delta) FROM events; // delta can be 0 or negative\n// after\nSELECT CASE WHEN delta > 0 THEN log(delta) ELSE NULL END FROM events;","handlingStrategy":"try-catch","validationCode":"BigInteger bi = toBigInteger(input);\nif (bi.signum() <= 0) throw new IllegalArgumentException(\"log() requires a positive value, got: \" + bi);","typeGuard":"static boolean isLogSafe(Number n) { return toBigInteger(n).signum() > 0; }","tryCatchPattern":"try { ByteBuffer r = IntegerType.instance.log(input); } catch (ArithmeticException e) { /* non-positive input; return NULL or default */ }","preventionTips":["Filter or CASE-guard non-positive operands in queries using log()","Validate column data domains (positivity) before using math functions","Prefer log(x + 1) when zero values are legitimate","Add data-quality checks for sign-sensitive columns"],"tags":["cassandra","arithmetic","math","domain-error"],"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"}