From b41e6ff6820a2652b4b31ba2c921b6b3ae6dda7c Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sun, 24 Aug 2014 11:42:00 +0200 Subject: [PATCH] #1246 False positive from MissingBreakInSwitch --- pmd/src/main/resources/rulesets/java/design.xml | 3 ++- pmd/src/site/markdown/changelog.md | 1 + .../pmd/lang/java/rule/design/xml/MissingBreakInSwitch.xml | 5 ++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pmd/src/main/resources/rulesets/java/design.xml b/pmd/src/main/resources/rulesets/java/design.xml index 5a20490bb9..bfb8878d9d 100644 --- a/pmd/src/main/resources/rulesets/java/design.xml +++ b/pmd/src/main/resources/rulesets/java/design.xml @@ -929,8 +929,9 @@ may indicate problematic behaviour. Empty cases are ignored as these indicate an [(count(.//BreakStatement) + count(BlockStatement/Statement/ReturnStatement) + count(BlockStatement/Statement/ThrowStatement) + + count(BlockStatement/Statement/IfStatement[@Else='true' and Statement[2][ReturnStatement|ThrowStatement]]/Statement[1][ReturnStatement|ThrowStatement]) + count(SwitchLabel[name(following-sibling::node()) = 'SwitchLabel']) - + count(SwitchLabel[count(following-sibling::node()) = 0 or count(child::node()) = 0]) + + count(SwitchLabel[count(following-sibling::node()) = 0]) < count (SwitchLabel))] ]]> diff --git a/pmd/src/site/markdown/changelog.md b/pmd/src/site/markdown/changelog.md index 1363a46892..ffbfd49d92 100644 --- a/pmd/src/site/markdown/changelog.md +++ b/pmd/src/site/markdown/changelog.md @@ -16,6 +16,7 @@ * [#1241](https://sourceforge.net/p/pmd/bugs/1241/): False+ AvoidProtectedMethodInFinalClassNotExtending * [#1243](https://sourceforge.net/p/pmd/bugs/1243/): Useless Parentheses False Positive * [#1245](https://sourceforge.net/p/pmd/bugs/1245/): False Positive for Law of Demeter +* [#1246](https://sourceforge.net/p/pmd/bugs/1246/): False positive from MissingBreakInSwitch * [#1247](https://sourceforge.net/p/pmd/bugs/1247/): Not able to recognize JDK 8 Static Method References **Feature Requests and Improvements:** diff --git a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/MissingBreakInSwitch.xml b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/MissingBreakInSwitch.xml index 50d3028f2d..5973d42f22 100644 --- a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/MissingBreakInSwitch.xml +++ b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/MissingBreakInSwitch.xml @@ -140,7 +140,10 @@ public class Foo { else return null; case x3: - return new Object(); + if (condition) + return new Object(); + else + return null; default: return null; }