fixes #1552 [java] continue does not require break

Similar to RETURN after a CONTINUE statement break is not required in a
case section
This commit is contained in:
Felix Otto
2016-12-05 12:19:21 +01:00
parent f10a1ecab7
commit 2ab57e339a
2 changed files with 27 additions and 1 deletions

View File

@ -944,8 +944,9 @@ may indicate problematic behaviour. Empty cases are ignored as these indicate an
//SwitchStatement
[(count(.//BreakStatement)
+ count(BlockStatement//Statement/ReturnStatement)
+ count(BlockStatement//Statement/ContinueStatement)
+ count(BlockStatement//Statement/ThrowStatement)
+ count(BlockStatement//Statement/IfStatement[@Else='true' and Statement[2][ReturnStatement|ThrowStatement]]/Statement[1][ReturnStatement|ThrowStatement])
+ count(BlockStatement//Statement/IfStatement[@Else='true' and Statement[2][ReturnStatement|ContinueStatement|ThrowStatement]]/Statement[1][ReturnStatement|ContinueStatement|ThrowStatement])
+ count(SwitchLabel[name(following-sibling::node()) = 'SwitchLabel'])
+ count(SwitchLabel[count(following-sibling::node()) = 0])
< count (SwitchLabel))]

View File

@ -191,6 +191,31 @@ public class Foo {
}
}
}
}
]]></code>
</test-code>
<test-code>
<description>#1552 MissingBreakInSwitch - False positive for continue</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class DemoMissingBreakContinue {
public DemoMissingBreakContinue() {
method();
}
private void method() {
for (int i = 0; i < 10; i = i + 1) {
switch (i) {
case 1:
break;
case 2:
continue; //PMD complains about missing break which would be unreachable code
default:
break;
}
}
}
}
]]></code>
</test-code>