[java] TooFewBranchesForSwitch: don't report empty switch

Empty switch statements are already reported
by EmptyControlStatement
This commit is contained in:
Andreas Dangel
2024-10-24 12:51:42 +02:00
parent d9d6b57f2a
commit 45b1217485
3 changed files with 6 additions and 4 deletions

View File

@ -24,6 +24,8 @@ See [PR #5040](https://github.com/pmd/pmd/pull/5040) for details.
### 🌟 Rule Changes
#### Changed Rules
* {% rule java/performance/TooFewBranchesForSwitch %} (Java Performance) doesn't report empty switches anymore.
To detect these, use {% rule java/codestyle/EmptyControlStatement %}.
* {% rule java/bestpractices/UnitTestShouldUseAfterAnnotation %} (Java Best Practices) now also considers JUnit 5 and TestNG tests.
* {% rule java/bestpractices/UnitTestShouldUseBeforeAnnotation %} (Java Best Practices) now also considers JUnit 5 and TestNG tests.

View File

@ -631,7 +631,7 @@ Note: This rule was named TooFewBranchesForASwitchStatement before PMD 7.7.0.
//(SwitchStatement | SwitchExpression)
[ (count(*) - 1) < $minimumNumberCaseForASwitch ]
(: only consider if no pattern matching is used :)
[not(*/SwitchLabel[@PatternLabel = true()])]
[*/SwitchLabel[@PatternLabel = false()]]
]]>
</value>
</property>

View File

@ -5,13 +5,13 @@
xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd">
<test-code>
<description>Switch Statement with no case, not ok</description>
<description>Switch Statement with no case, ok</description>
<rule-property name="minimumNumberCaseForASwitch">3</rule-property>
<expected-problems>1</expected-problems>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class DumbSwitch {
public void foo(int i) {
switch (i) { }
switch (i) { } // This is detected by EmptyControlStatement
}
}
]]></code>