Skip to content

Commit 3462624

Browse files
committed
Java: Add test.
1 parent da57dbc commit 3462624

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
public class A {
2+
3+
public interface Cond {
4+
boolean cond();
5+
}
6+
7+
void test1(int x, Cond c) {
8+
int i;
9+
10+
// --- do loops ---
11+
12+
do {
13+
if (c.cond())
14+
continue; // BAD
15+
if (c.cond())
16+
break;
17+
} while (false);
18+
19+
do {
20+
if (c.cond())
21+
continue;
22+
if (c.cond())
23+
break;
24+
} while (true);
25+
26+
do {
27+
if (c.cond())
28+
continue;
29+
if (c.cond())
30+
break;
31+
} while (c.cond());
32+
33+
// --- while, for loops ---
34+
35+
while (false) {
36+
if (c.cond())
37+
continue; // GOOD [never reached, if the condition changed so it was then the result would no longer apply]
38+
if (c.cond())
39+
break;
40+
}
41+
42+
for (i = 0; false; i++) {
43+
if (c.cond())
44+
continue; // GOOD [never reached, if the condition changed so it was then the result would no longer apply]
45+
if (c.cond())
46+
break;
47+
}
48+
49+
// --- nested loops ---
50+
51+
do {
52+
do {
53+
if (c.cond())
54+
continue; // BAD
55+
if (c.cond())
56+
break;
57+
} while (false);
58+
if (c.cond())
59+
break;
60+
} while (true);
61+
62+
do {
63+
do {
64+
if (c.cond())
65+
continue; // GOOD
66+
if (c.cond())
67+
break;
68+
} while (true);
69+
} while (false);
70+
71+
do {
72+
switch (x) {
73+
case 1:
74+
// do [1]
75+
break; // break out of the switch
76+
default:
77+
// do [2]
78+
// break out of the loop entirely, skipping [3]
79+
continue; // BAD; labelled break is better
80+
};
81+
// do [3]
82+
} while (false);
83+
}
84+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| A.java:14:9:14:17 | stmt | This 'continue' never re-runs the loop - the $@ is always false. | A.java:17:14:17:18 | false | loop condition |
2+
| A.java:54:11:54:19 | stmt | This 'continue' never re-runs the loop - the $@ is always false. | A.java:57:16:57:20 | false | loop condition |
3+
| A.java:79:9:79:17 | stmt | This 'continue' never re-runs the loop - the $@ is always false. | A.java:82:14:82:18 | false | loop condition |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Likely Bugs/Statements/ContinueInFalseLoop.ql

0 commit comments

Comments
 (0)