diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 34fb78e0c0..9403457ac1 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -29,6 +29,7 @@ This is a {{ site.pmd.release_type }} release. * [#5083](https://github.com/pmd/pmd/issues/5083): \[java] UnusedPrivateMethod false positive when method reference has no target type * [#5318](https://github.com/pmd/pmd/issues/5318): \[java] PreserveStackTraceRule: false-positive on Pattern Matching with instanceof * java-performance + * [#5287](https://github.com/pmd/pmd/issues/5287): \[java] TooFewBranchesForSwitch false-positive with switch using list of case constants * [#5314](https://github.com/pmd/pmd/issues/5314): \[java] InsufficientStringBufferDeclarationRule: Lack of handling for char type parameters ### 🚨 API Changes diff --git a/pmd-java/src/main/resources/category/java/performance.xml b/pmd-java/src/main/resources/category/java/performance.xml index a8e4c37142..8b2d4e20c5 100644 --- a/pmd-java/src/main/resources/category/java/performance.xml +++ b/pmd-java/src/main/resources/category/java/performance.xml @@ -629,7 +629,7 @@ Note: This rule was named TooFewBranchesForASwitchStatement before PMD 7.7.0. diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/performance/xml/TooFewBranchesForSwitch.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/performance/xml/TooFewBranchesForSwitch.xml index e603390ec6..4cbc9893c7 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/performance/xml/TooFewBranchesForSwitch.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/performance/xml/TooFewBranchesForSwitch.xml @@ -136,6 +136,68 @@ public class SwitchWithRecordPattern { } } } +]]> + + + + #5287 [java] TooFewBranchesForSwitch false-positive with switch using list of case constants + 3 + 0 + 1; + default -> 0; + }; + } + + int checkSwitchStatement(SomeEnum someEnumValue) { + int result; + switch(someEnumValue) { + case A, B, C -> { result = 1; } + default -> { result = 0; } + } + return result; + } + + int checkSwitchExpressionGroup(SomeEnum someEnumValue) { + return switch(someEnumValue) { + case A, B, C: yield 1; + default: yield 0; + }; + } + + int checkSwitchStatementGroup(SomeEnum someEnumValue) { + int result; + switch(someEnumValue) { + case A, B, C: result = 1; break; + default: result = 0; break; + } + return result; + } +} +]]> + + + + From #5311: Another example for list of case constants + 0 + "Hello"; + case E, F, G -> "World"; + }; + } + + enum Bar { + A, B, C, D, E, F, G + } +} ]]>