forked from phoedos/pmd
[java] TooFewBranchesForSwitch should ignore Pattern Matching
Fixes #5249
This commit is contained in:
parent
a0818d5ab2
commit
90f436fd28
@ -34,6 +34,9 @@ The old rule names still work but are deprecated.
|
||||
* [#4532](https://github.com/pmd/pmd/issues/4532): \[java] Rule misnomer for JUnit* rules
|
||||
* java-errorprone
|
||||
* [#5067](https://github.com/pmd/pmd/issues/5067): \[java] CloseResource: False positive for FileSystems.getDefault()
|
||||
* java-performance
|
||||
* [#5249](https://github.com/pmd/pmd/issues/5249): \[java] TooFewBranchesForASwitchStatement false positive for Pattern Matching
|
||||
* [#....](https://github.com/pmd/pmd/issues/....): \[java] TooFewBranchesForASwitchStatement should consider Switch Expressions
|
||||
|
||||
### 🚨 API Changes
|
||||
* java-bestpractices
|
||||
|
@ -625,6 +625,8 @@ if-else statement to increase code readability.
|
||||
<value>
|
||||
<![CDATA[
|
||||
//SwitchStatement[ (count(*) - 1) < $minimumNumberCaseForASwitch ]
|
||||
(: exclude pattern matching :)
|
||||
[not(*/SwitchLabel/TypePattern)]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
|
@ -69,4 +69,26 @@ public class ValidSwitch {
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>[java] TooFewBranchesForASwitchStatement false positive for Pattern Matching</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
sealed interface S permits A {}
|
||||
final class A implements S {}
|
||||
public class Sample {
|
||||
public void simpleSwitchStatment(S s) {
|
||||
switch(s) {
|
||||
case A a -> System.out.println("a");
|
||||
}
|
||||
}
|
||||
|
||||
public void simpleSwitchExpression(S s) {
|
||||
String result = switch(s) {
|
||||
case A a -> "a";
|
||||
};
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
||||
|
Loading…
x
Reference in New Issue
Block a user