mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
31 lines
1.1 KiB
HTML
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> |