2020-06-30 10:16:44 +02:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
|
|
|
include::../noncompliant.adoc[]
|
|
|
|
|
|
|
|
include::../compliant.adoc[]
|
|
|
|
|
|
|
|
== Exceptions
|
|
|
|
|
|
|
|
This rule is relaxed in the following cases:
|
|
|
|
|
2022-02-02 17:36:35 +01:00
|
|
|
[source,java]
|
2020-06-30 10:16:44 +02:00
|
|
|
----
|
|
|
|
switch (myVariable) {
|
|
|
|
case 0: // Empty case used to specify the same behavior for a group of cases.
|
|
|
|
case 1:
|
|
|
|
doSomething();
|
|
|
|
break;
|
2022-02-02 17:36:35 +01:00
|
|
|
case 2: // Use of a fallthrough comment
|
|
|
|
// fallthrough
|
|
|
|
case 3: // Use of return statement
|
2020-06-30 10:16:44 +02:00
|
|
|
return;
|
2022-02-02 17:36:35 +01:00
|
|
|
case 4: // Use of throw statement
|
2020-06-30 10:16:44 +02:00
|
|
|
throw new IllegalStateException();
|
2022-02-02 17:36:35 +01:00
|
|
|
case 5: // Use of continue statement
|
2020-06-30 10:16:44 +02:00
|
|
|
continue;
|
|
|
|
default: // For the last case, use of break statement is optional
|
|
|
|
doSomethingElse();
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
2021-09-21 15:40:35 +02:00
|
|
|
== See
|
|
|
|
|
2022-04-07 08:53:59 -05:00
|
|
|
* https://cwe.mitre.org/data/definitions/484[MITRE, CWE-484] - Omitted Break Statement in Switch
|
2021-09-21 15:40:35 +02:00
|
|
|
* https://wiki.sei.cmu.edu/confluence/x/ldYxBQ[CERT, MSC17-C.] - Finish every set of statements associated with a case label with a break statement
|
|
|
|
* https://wiki.sei.cmu.edu/confluence/x/1DdGBQ[CERT, MSC52-J.] - Finish every set of statements associated with a case label with a break statement
|
2021-06-02 20:44:38 +02:00
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
ifdef::env-github,rspecator-view[]
|
2021-09-20 15:38:42 +02:00
|
|
|
|
|
|
|
'''
|
|
|
|
== Implementation Specification
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../message.adoc[]
|
|
|
|
|
2021-06-08 15:52:13 +02:00
|
|
|
'''
|
2021-06-02 20:44:38 +02:00
|
|
|
== Comments And Links
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../comments-and-links.adoc[]
|
2021-06-03 09:05:38 +02:00
|
|
|
endif::env-github,rspecator-view[]
|