Fixes #1541 [java] InvalidSlf4jMessageFormat: False positive with placeholder and exception
This commit is contained in:
@ -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));
|
||||
|
@ -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>
|
||||
|
Reference in New Issue
Block a user