Merge pull request #3259 from

oowekyala:issue2737-doc-SwitchStmtsShouldHaveDefault

[java] Fix misleading rule message on rule SwitchStmtsShouldHaveDefault
with non-exhaustive enum switch
This commit is contained in:
Andreas Dangel committed 2021-05-08 19:51:44 +02:00
commit 8208dc9cd6
2 files changed
+9 -5

No files matched your search

+1
View File
@@ -30,6 +30,7 @@ This is a {{ site.pmd.release_type }} release.
* dist
* [#2466](https://github.com/pmd/pmd/issues/2466): \[dist] Distribution archive doesn't include all batch scripts
* java-bestpractices
* [#2737](https://github.com/pmd/pmd/issues/2737): \[java] Fix misleading rule message on rule SwitchStmtsShouldHaveDefault with non-exhaustive enum switch
* [#3236](https://github.com/pmd/pmd/issues/3236): \[java] LiteralsFirstInComparisons should consider constant fields (cont'd)
* java-codestyle
* [#2655](https://github.com/pmd/pmd/issues/2655): \[java] UnnecessaryImport false positive for on-demand imports
@@ -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 adding a `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>