Improve doc of SwitchStmtsShouldHaveDefault, fix #2737

This commit is contained in:
Clément Fournier committed 2021-05-06 14:06:28 +02:00
1 parent d69325f03a
commit 223b4e6efe
1 file changed
+8 -5
@@ -1287,12 +1287,15 @@ public class Foo {
<rule name="SwitchStmtsShouldHaveDefault"
language="java"
since="1.0"
message="Switch statements should have a default label"
message="Switch statements should be exhaustive, add a default case (or missing enum branches)"
typeResolution="true"
class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#switchstmtsshouldhavedefault">
<description>
All switch statements should include a default option to catch any unspecified values.
Switch statements should be exhaustive, to make their control flow
easier to follow. This can be achieved by addinga `default` case, or,
if the switch is on an enum type, by ensuring there is one switch branch
for each enum constant.
</description>
<priority>3</priority>
<properties>
@@ -1305,14 +1308,14 @@ All switch statements should include a default option to catch any unspecified v
</properties>
<example>
<![CDATA[
public void bar() {
class Foo {{
int x = 2;
switch (x) {
case 1: int j = 6;
case 2: int j = 8;
// missing default: here
// missing default: here
}
}
}}
]]>
</example>
</rule>