Affects PMD Version: 6.31
Rule: InvalidLogMessageFormat
Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/pmd-6.31.0/pmd_rules_java_errorprone.html#invalidlogmessageformat
Description:
In Log4j documents(https://logging.apache.org/log4j/2.x/manual/messages.html),ParameterizedMessage
and StringFormattedMessage
are described.
However, PMD shows alarms for it.
Also, even if there are no place holder with Throwable
type in parameter, it shows an alarm.
Case 1. shows StringFormattedMessage
,
Case 2. shows ParameterizedMessage
and no place holder example
which are from brooklyn-server project in Apach Software Foundation.
Please, check them.
Thank you.
Code Sample demonstrating the issue:
Case 1.
import org.slf4j.Logger; import org.slf4j.LoggerFactory; class TestInvalidLogMessageFormat{ Logger log = new LogggerFactory(TestInvalidLogMessageFormat.class); public void testPMD(){ log.debug("param %s", "1"); } }
Detection message:
TestInvalidLogMessageFormat.java:7: InvalidLogMessageFormat: Too many arguments, expected 0 argument but have 1
Case 2.
protected void logProblem(String type, Object val) { if (lastWasProblem && currentProblemLoggedAsWarning) { ... } else { ... if (!lastWasProblem) { if (expiryTime <= nowTime) { ... if (log.isDebugEnabled() && val instanceof Throwable) { /*whistled*/ log.debug("Trace for "+type+" reading "+getBriefDescription()+": "+val, (Throwable)val); } } ... } else { if (expiryTime <= nowTime) { ... if (log.isDebugEnabled() && val instanceof Throwable) { /*whistled*/ log.debug("Trace for "+type+" reading "+getBriefDescription()+": "+val, (Throwable)val); } } else { if (log.isDebugEnabled()) { /*whistled*/ log.debug("Recurring {} reading {} in {} (still in grace period): {}", new Object[] {type, this, getBriefDescription(), val}); } } } } }
brooklyn-server/core/src/main/java/org/apache/brooklyn/core/feed/AttributePollHandler.java:167: InvalidLogMessageFormat: Too many arguments, expected 0 argument but have 1
brooklyn-server/core/src/main/java/org/apache/brooklyn/core/feed/AttributePollHandler.java:183: InvalidLogMessageFormat: Too many arguments, expected 0 argument but have 1
brooklyn-server/core/src/main/java/org/apache/brooklyn/core/feed/AttributePollHandler.java:186: InvalidLogMessageFormat: Missing arguments, expected 4 arguments but have 1
Expected outcome:
No Alarms.
Running PMD through: [CLI]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4