An integer is divided by the literal 0, which throws an ArithmeticException
What it finds
count / 0 and index % 0 throw an ArithmeticException when the dividend is an integer, as the language specification says for integer division and remainder. A zero written as the divisor is usually a placeholder that was never replaced, or a test that went missing.
Reported is /, %, /= and %= with the integer literal 0 as divisor and a dividend whose type this file shows to be an integer type. A floating-point dividend gives infinity or NaN instead and is left alone.
From the rule's source, zero_divisor.rs.
class Ratio { int split(int total, long big, double share) { int a = total / 0;tx0 reports: the divisor is 0 long b = big % 0;tx0 reports: the divisor is 0 total /= 0;tx0 reports: the divisor is 0 double c = share / 0; int d = total / 1; return a + (int) b + (int) c + d; }} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/java:zero-divisor" = "off"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/java:zero-divisor] reason="..."tx0 explain tx0/java:zero-divisor shows the same in the terminal. Found a false positive? Report it.