Affects PMD Version:
PMD version: 6.26.0
Description:
In my code the PMD rule InvalidLogMessageFormat
found a bug, that is not a bug.
I was able to reproduce it with this code sample
Code Sample demonstrating the issue:
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Foo {
private static final Logger LOG = LoggerFactory.getLogger(Foo.class);
public static class Event {
private Throwable lastThrowable;
public Throwable getLastThrowable() {
return lastThrowable;
}
}
public void bar(Event event) {
Optional.of(event).ifPresent(e -> LOG.warn(
"Failed on {}",
1,
e.getLastThrowable()));
}
}
Steps to reproduce:
On my machine:
mvn clean compile pmd:check
- See
You have 1 PMD violation
cat target/pmd.xml
- See
<file name="/xyz/Foo.java">
<violation beginline="21" endline="21" begincolumn="39" endcolumn="46" rule="InvalidLogMessageFormat" ruleset="Error Prone" package="xyz" class="Foo" method="bar" externalInfoUrl="https://pmd.github.io/pmd-6.26.0/pmd_rules_java_errorprone.html#invalidlogmessageformat" priority="5">
Too many arguments, expected 1 argument but have 2
</violation>
</file>
In this project:
- Add the snippet to src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/InvalidLogMessageFormat.xml
- Run
mvn test
- See
[ERROR] Failures:
[ERROR] net.sourceforge.pmd.lang.java.rule.errorprone.InvalidLogMessageFormatTest.null
...
[ERROR] Run 45: InvalidLogMessageFormatTest>RuleTst.runTest:157 "My bug" resulted in wrong number of failures, expected:<0> but was:<1>
Running PMD through: Maven
maven-pmd-plugin:3.13.0
Apache Maven 3.6.3
Java version: 11.0.1, vendor: AdoptOpenJDK,
platform encoding: UTF-8
OS name: "mac os x"
Affects PMD Version:
PMD version: 6.26.0
Description:
In my code the PMD rule InvalidLogMessageFormat
found a bug, that is not a bug.
I was able to reproduce it with this code sample
Code Sample demonstrating the issue:
Steps to reproduce:
On my machine:
mvn clean compile pmd:checkYou have 1 PMD violationcat target/pmd.xmlIn this project:
mvn testRunning PMD through: Maven
maven-pmd-plugin:3.13.0
Apache Maven 3.6.3
Java version: 11.0.1, vendor: AdoptOpenJDK,
platform encoding: UTF-8
OS name: "mac os x"