A value is divided by the integer literal 0
What it finds
x / 0 and x % 0 throw ArithmeticException when x is an integer, and give infinity or NaN when it is a floating-point number. Either way the result is rarely what the code meant.
From the rule's source, division_by_zero.rs.
fun ratio(a: Int, b: Double): Double { val x = a / 0tx0 reports: dividing by the integer 0 var y = a y %= 0tx0 reports: dividing by the integer 0 return b / 0.0 + x / 1 + y} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/kotlin:division-by-literal-zero" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/kotlin:division-by-literal-zero] reason="..."tx0 explain tx0/kotlin:division-by-literal-zero shows the same in the terminal. Found a false positive? Report it.