Inspectopedia
 
2024.3

Pointless arithmetic expression

Warning
Last modified: 03 December 2024

Reports pointless arithmetic expressions. Such expressions include adding or subtracting zero, multiplying by zero or one, and division by one.

Such expressions may be the result of automated refactorings and they are unlikely to be what the developer intended to do.

The quick-fix simplifies such expressions.

Example:

After the quick-fix is applied:

Note that in rare cases, the suggested replacement might not be completely equivalent to the original code for all possible inputs. For example, the inspection suggests replacing x / x with 1. However, if x is zero, the original code throws ArithmeticException or results in NaN. Also, if x is NaN, then the result is also NaN. It's very unlikely that such behavior is intended.