Fixes #1541 [java] InvalidSlf4jMessageFormat: False positive with placeholder and exception

This commit is contained in:
Andreas Dangel
2016-12-03 17:52:10 +01:00
parent 048fc32aa0
commit 9afebbea18
3 changed files with 27 additions and 1 deletions

View File

@ -93,7 +93,10 @@ public class InvalidSlf4jMessageFormatRule extends AbstractJavaRule {
}
// Remove throwable param, since it is shown separately.
removeThrowableParam(params);
// But only, if it is not used as a placeholder argument
if (params.size() > expectedArguments) {
removeThrowableParam(params);
}
if (params.size() < expectedArguments) {
addViolationWithMessage(data, node, "Missing arguments," + getExpectedMessage(params, expectedArguments));

View File

@ -152,6 +152,27 @@ public class InvalidSlf4jExceptionTest {
throw e;
}
}
}
]]></code>
</test-code>
<test-code>
<description>#1541 [java] InvalidSlf4jMessageFormat: False positive with placeholder and exception</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class InvalidSl4jExceptionBug1541 {
private static final Logger log = LoggerFactory.getLogger(InvalidSl4jExceptionBug1541.class);
public static void main(String[] args) {
try {
// ...
} catch (Exception e) {
log.error("Arg1 = {}. Exception: {}", "arg1Value", e);
}
}
}
]]></code>
</test-code>