Constant Zero Denominator
ID |
java.zero_possible_denominator |
Severity |
critical |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
Java |
Tags |
reliability |
Description
Reports a division whose denominator is provably always the literal 0: either written directly, or a local variable initialized to 0 and never reassigned before it is used as the divisor.
Rationale
A division by a denominator that can only ever be zero always fails at runtime — ArithmeticException for integral types, Infinity/NaN for floating-point types:
int divisor = 0;
int result = total / divisor; // always throws ArithmeticException
Remediation
Assign the intended value before the division, or remove the division if it no longer applies:
int divisor = computeDivisor();
int result = total / divisor;
What is not reported
Only a denominator that is exactly the literal 0, or exactly a never-reassigned zero-initialized local, is reported. A denominator that is merely provably zero through arithmetic (x - x), through a field or a method parameter, or only along some execution paths, is out of scope — this is a syntactic check, not a symbolic range analysis.