Files
openide/java/java-impl/resources/inspectionDescriptions/PointlessArithmeticExpression.html
Leonid Shalupov 40795fe787 IJI-2422: community/java: move resources under resources root
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
2025-02-05 04:43:28 +00:00

31 lines
1.1 KiB
HTML

<html>
<body>
Reports pointless arithmetic expressions. Such expressions include adding or subtracting zero,
multiplying by zero or one, and division by one.
<p>Such expressions may be the result of automated refactorings and they are unlikely to be what the developer intended to do.</p>
<p>The quick-fix simplifies such expressions.</p>
<p><b>Example:</b>
<pre><code>
void f(int a) {
int x = a - a;
int y = a + 0;
int res = x / x;
}
</code></pre>
<p>After the quick-fix is applied:</p>
<pre><code>
void f(int a) {
int x = 0;
int y = a;
int res = 1;
}
</code></pre>
<!-- tooltip end -->
<p>
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 <code>x / x</code> with <code>1</code>.
However, if <code>x</code> is zero, the original code throws <code>ArithmeticException</code> or results in <code>NaN</code>.
Also, if <code>x</code> is <code>NaN</code>, then the result is also <code>NaN</code>. It's very unlikely that such behavior is intended.
</p>
</body>
</html>