-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathUselessComparisonTest.qhelp
More file actions
38 lines (31 loc) · 1.04 KB
/
UselessComparisonTest.qhelp
File metadata and controls
38 lines (31 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>The result of certain comparison tests can sometimes be inferred from their
context and the results of other
comparisons. This can be an indication of faulty logic and may result in dead
code or infinite loops if, for example, a loop condition never changes its value.
</p>
</overview>
<recommendation>
<p>Inspect the code to check whether the logic is correct, and consider
simplifying the logical expression.
</p>
</recommendation>
<example>
<p>In the following example the final test on <code>x</code> will always be
<code>true</code>, and thus the condition is redundant and potentially wrong.
If the "do more stuff" part is intended to always execute after the loop then
the condition should be removed to make this clear.
</p>
<sample src="UselessComparisonTest.java" />
</example>
<references>
<li>
Java Language Specification:
<a href="https://docs.oracle.com/javase/specs/jls/se11/html/jls-14.html#jls-14.9">The if Statement</a>.
</li>
</references>
</qhelp>