Fixes #1509 [java] InvalidSlf4jMessageFormat NPE

This commit is contained in:
Andreas Dangel
2016-08-03 19:43:10 +02:00
parent 4bb02531c7
commit a6acf7ca81
3 changed files with 32 additions and 1 deletions

View File

@ -71,7 +71,15 @@ public class InvalidSlf4jMessageFormatRule extends AbstractJavaRule {
final List<ASTExpression> argumentList = parentNode.getFirstChildOfType(ASTPrimarySuffix.class)
.getFirstDescendantOfType(ASTArgumentList.class).findChildrenOfType(ASTExpression.class);
for (final ASTExpression astExpression : argumentList) {
params.add(astExpression.getFirstChildOfType(ASTPrimaryExpression.class));
ASTPrimaryExpression primaryExpression = astExpression.getFirstChildOfType(ASTPrimaryExpression.class);
if (primaryExpression != null) {
params.add(primaryExpression);
}
}
if (params.isEmpty()) {
// no params we could analyze
return super.visit(node, data);
}
final ASTPrimaryExpression messageParam = params.get(0);

View File

@ -105,6 +105,26 @@ public class NullPointerTypeProblem {
System.out.println(st.nextToken());
}
}
}
]]></code>
</test-code>
<test-code>
<description>#1509 [java] InvalidSlf4jMessageFormat NPE</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
package my.test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Test {
private static final Logger log = LoggerFactory.getLogger(Test.class);
public static void main(String[] args) {
log.info("1" + "2");
}
}
]]></code>
</test-code>

View File

@ -12,4 +12,7 @@
**Bugfixes:**
* java
* [#1509](https://sourceforge.net/p/pmd/bugs/1509/) \[java] InvalidSlf4jMessageFormat NPE
**API Changes:**