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.
|
||||
// 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>
|
||||
|
@ -51,6 +51,8 @@
|
||||
* [#1545](https://sourceforge.net/p/pmd/bugs/1545/): \[java] Symbol Table fails to resolve inner classes
|
||||
* java-imports
|
||||
* [#1546](https://sourceforge.net/p/pmd/bugs/1546/): \[java] UnnecessaryFullyQualifiedNameRule doesn't take into consideration conflict resolution
|
||||
* java-logging-java
|
||||
* [#1541](https://sourceforge.net/p/pmd/bugs/1541/): \[java] InvalidSlf4jMessageFormat: False positive with placeholder and exception
|
||||
* XML
|
||||
* [#1518](https://sourceforge.net/p/pmd/bugs/1518/): \[xml] Error while processing xml file with ".webapp" in the file or directory name
|
||||
* psql
|
||||
|
Reference in New Issue
Block a user