Fix patch 3130615: fix xpath rule to consider the correct if-condition.

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.3.x@7362 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Romain Pelisse 2011-09-29 14:52:46 +00:00
parent 66ef2399e3
commit 0496cc8fc5
2 changed files with 20 additions and 1 deletions

View File

@ -49,6 +49,25 @@ public class Test {
__log.debug("bla" + "",e );
}
}
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
Complex logging wit misplaced guard
]]></description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Test {
private static final Log __log = LogFactory.getLog(Test.class);
public void test() {
if (true) {
// bad:
__log.debug("log something" + " and " + "concat strings");
// this is useless:
__log.isDebugEnabled();
}
}
}
]]></code>
</test-code>

View File

@ -103,7 +103,7 @@ around, with the restriction that the logger needs to be passed into the constru
<property name="xpath">
<value>
<![CDATA[
//PrimaryPrefix[ends-with(Name/@Image, '.debug') and count(../descendant::AdditiveExpression) > 0 and count(ancestor::IfStatement/descendant::PrimaryExpression[ends-with(descendant::PrimaryPrefix/Name/@Image, 'isDebugEnabled')]) = 0]
//PrimaryPrefix[ends-with(Name/@Image, '.debug') and count(../descendant::AdditiveExpression) > 0 and count(ancestor::IfStatement/Expression/descendant::PrimaryExpression[ends-with(descendant::PrimaryPrefix/Name/@Image, 'isDebugEnabled')]) = 0]
]]>
</value>
</property>