mirror of
https://github.com/github/codeql.git
synced 2026-04-28 10:15:14 +02:00
Merge pull request #19998 from tamasvajk/quality/label-in-switch
Java: Add query to detect non-case labels in switch statements
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
| Test.java:14:17:14:31 | <Label>: ... | Possibly erroneous non-case label in switch statement. The case keyword might be missing. |
|
||||
| Test.java:17:17:17:39 | <Label>: ... | Confusing non-case label in switch statement. |
|
||||
@@ -0,0 +1,2 @@
|
||||
query: Language Abuse/LabelInSwitch.ql
|
||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
||||
21
java/ql/test/query-tests/LabelInSwitch/Test.java
Normal file
21
java/ql/test/query-tests/LabelInSwitch/Test.java
Normal file
@@ -0,0 +1,21 @@
|
||||
public class Test {
|
||||
void test_case_label_only_in_switch(int p) {
|
||||
switch (p) {
|
||||
case 1:
|
||||
case 2:
|
||||
break;
|
||||
}
|
||||
notcaselabelnotinswitch: for (;;) {}
|
||||
}
|
||||
|
||||
void test_noncase_label_in_switch(int p) {
|
||||
switch (p) {
|
||||
case 1:
|
||||
notcaselabel1:; // $ Alert | Possibly erroneous non-case label in switch statement. The case keyword might be missing.
|
||||
break;
|
||||
case 2:
|
||||
notcaselabel2: for (;;) { break notcaselabel2; } // $ Alert | Confusing non-case label in switch statement.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user