
...
Exceptions
Wiki Markup |
---|
*MSC09-EX1EX0*: The {{break}} statement at the end of the final case in a {{switch}} statement may be omitted. By convention, this is the {{default}} label. The {{break}} statement serves to transfer control to the end of the {{switch}} block. Fall-through behavior also causes control to arrive at the end of the {{switch}} block. Consequently, control transfers to the statements following the {{switch}} block without regard to the presence or absence of the {{break}} statement. Nevertheless, the final case in a {{switch}} statement should end with a {{break}} statement, in accordance with good programming style (see \[[Rogue 2000|AA. Bibliography#Rogue 00]\]). |
MSC09-EX2EX1: When multiple cases require execution of identical code, then break
statements may be omitted from all cases except the last one. For example:
Code Block | ||
---|---|---|
| ||
int card = 11; int value; // Cases 11,12,13 fall through to the same case switch (card) { // MSC13-J:EX2: these three cases are treated identically case 11: // break not required case 12: // break not required case 13: value = 10; break; // break required default: // Handle Error Condition } |
MSC09-EX3EX2: When a case ends with a return
or throw
statement, the break
statement may be omitted.
...
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
MSC09-J | medium | unlikely | low | P6 | L2 |
Related Vulnerabilities
...
Related Guidelines
MSC17-C. Finish every set of statements associated with a case label with a break statement | ||||
MSC18-CPP. Finish every set of statements associated with a case label with a break statement | ||||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="890090c91f1f017e-e5a5cfe2-491f4246-be4fa06e-39c6fbaf32fee0689d443ff9"><ac:plain-text-body><![CDATA[ | [ISO/IEC TR 24772:2010 | http://www.aitcnet.org/isai/] | "Switch Statements and Static Analysis [CLL]" | ]]></ac:plain-text-body></ac:structured-macro> |
CWE ID 484, "Omitted Break Statement in Switch" |
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="e81eb3d832f3d78d-35e7bbda-4d8b4445-8c758465-28396f88265d511dc86e5c79"><ac:plain-text-body><![CDATA[ | [[JLS 2005 | AA. Bibliography#JLS 05]] | [Section 14.11 The switch Statement | http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.11] | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="68e1774891dfd73e-292ae0df-43a048b1-89c48bf7-4f4031a397bc1c7ac8006b1a"><ac:plain-text-body><![CDATA[ | [[Rogue 2000 | AA. Bibliography#Rogue 00]] | [The Elements of Java Style | http://www.ambysoft.com/books/elementsJavaStyle.html], Rule 78. | ]]></ac:plain-text-body></ac:structured-macro> |
...