InvalidSlf4jMessageFormat: Fix class cast exception with method calls
This commit is contained in:
@ -26,6 +26,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclarator;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId;
|
||||
import net.sourceforge.pmd.lang.java.ast.AbstractJavaTypeNode;
|
||||
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
|
||||
import net.sourceforge.pmd.lang.java.symboltable.VariableNameDeclaration;
|
||||
import net.sourceforge.pmd.lang.symboltable.NameDeclaration;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -42,8 +43,8 @@ public class InvalidSlf4jMessageFormatRule extends AbstractJavaRule {
|
||||
@Override
|
||||
public Object visit(final ASTName node, final Object data) {
|
||||
final NameDeclaration nameDeclaration = node.getNameDeclaration();
|
||||
// ignore imports
|
||||
if (nameDeclaration == null) {
|
||||
// ignore imports or methods
|
||||
if (nameDeclaration == null || !(nameDeclaration instanceof VariableNameDeclaration)) {
|
||||
return super.visit(node, data);
|
||||
}
|
||||
|
||||
|
@ -74,6 +74,22 @@ public class Foo {
|
||||
public void call() {
|
||||
LOGGER.error("params {} and {}", "arg1", "arg2", new IllegalStateException("Extra arg"));
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>Class cast exception with Method calls</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class MethodCallClassCastExceptionProblem {
|
||||
public void foo() {
|
||||
// a method call
|
||||
otherMethod();
|
||||
}
|
||||
|
||||
private void otherMethod() {
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
Reference in New Issue
Block a user