It's is pretty easy to compare one path's @Image to a static string but how to compare 2 paths'@Image ?
Code that should trigger the rule :
public class Foo implements {
public String checkDBConnexion() {
try {
int result = jdbcTemplate.queryForObject("SELECT 1 FROM dual ", Integer.class);
} catch (DataAccessException e) {
// This is Ok : throw new MyException(test, e);
// this is not : hrow new MyException(test);
// This is also not ok if there are no thrown;
return "KO : " + e.getMessage();
}
}
}
Xpath for the param name of the Catch block :
//CatchStatement[//FormalParameter//VariableDeclaratorId]
Xpath for the variable name of the thrown method :
//ThrowStatement//Arguments//Expression//Name
It's easy to compare both to 'e' :
//CatchStatement[//FormalParameter//VariableDeclaratorId[@Image = 'e']]
//CatchStatement[//ThrowStatement//Arguments//Expression//Name[@Image = 'e']]
How do I compare them with eachother ?
Also if you have a link with detailled PMD XPath synthax exemple. The basic PMD page has ... well the basic ;)