Closed ghost closed 3 years ago
The DivZero check only matches literal zeros, so I would say this is the expected behavior actually.
This is sort of similar to https://github.com/google/error-prone/issues/2414, our focus is mostly on catching bugs with simple intraprocedural analysis.
Catching the example you provided would be do-able, but would add complexity to the check and may not catch a lot of additional bugs. And continuing to generalize it to handle more cases like that would quickly require dataflow, and then interprocedural analysis.
We're not trying to provide sound guarantees that e.g. an ArithmeticException
from dividing by zero can never happen, we're just trying to prevent some simple cases where it definitely will.
Description of the problem / feature request:
A false negative related to DivZero
Feature requests: what underlying problem are you trying to solve with this feature?
An exception caused by this issue's case. Based on the description in the official document, Error Prone should have reported a warning to detect the bug because when var is equal to zero, the program will throw an exception.
Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
What version of Error Prone are you using?