-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathUnusedLabel.qhelp
More file actions
49 lines (36 loc) · 1.86 KB
/
UnusedLabel.qhelp
File metadata and controls
49 lines (36 loc) · 1.86 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
39
40
41
42
43
44
45
46
47
48
49
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>Loop and <code>switch</code> statements can be labeled. These labels
can serve as targets for <code>break</code> or
<code>continue</code> statements, to specify which loop or <code>switch</code> statement they refer to.</p>
<p>Apart from serving as such jump targets, the labels have no effect on
program behavior, which means that having an unused label is suspicious.</p>
</overview>
<recommendation>
<p>If the label is used to document the intended behavior of a loop or <code>switch</code> statement, remove it.
It is better to use comments for this purpose. However, an unused label may
indicate that something is wrong: that some of the nested <code>break</code>
or <code>continue</code> statements should be using the label. In this case, the current control
flow is probably wrong, and you should adjust some jumps to use the label
after checking the desired behavior.</p>
</recommendation>
<example>
<p>The following example uses a loop and a nested loop to check whether any of the
currently active shopping carts contains a particular item. On line 4, the <code>carts:</code> label
is unused. Inspecting the code, we can see that the <code>break</code> statement on line 10
is inefficient because it only breaks out of the nested loop. It
could in fact break out of the outer loop, which should improve
performance in common cases. By changing the statement on line 10 to read <code>break carts;</code>, the label
is no longer unused and we improve the code.</p>
<sample src="UnusedLabel.java" />
</example>
<references>
<li>
Help - Eclipse Platform:
<a href="http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fpreferences%2Fjava%2Fcompiler%2Fref-preferences-errors-warnings.htm">Java Compiler Errors/Warnings Preferences</a>.
</li>
</references>
</qhelp>