I'm trying to create a custom rule that flags up the use of return statements in void methods, for example:
public class MyClass
{
public void myMethod(Object someObj)
{
if (someObj == null)
{
return;
}
...
}
}
I have created a custom XPath rule with the following XPath:
//MethodDeclaration[not(ResultType/Type) and (count(//ReturnStatement) > 0)]
Which returns the ASTMethodDeclaration element in the RuleDesigner, however when I import this rule into Eclipse and run PMD against the code, it doesn't flag a method that I expected it to, i.e. one that matches the above description (void method containing return).
Anyone got any ideas what the problem could be here? Is there something wrong with my XPath or could it be something else?
I'm using v3.2.6 of the plugin, which contains pmd14-4.2.5.jar.
Thanks, Chris