Skip to content

[java] False Positives in InvalidLogMessageFormat rule #3433

@Noah0120

Description

@Noah0120

Affects PMD Version:
6.36.0
Rule:
InvalidLogMessageFormat
Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/latest/pmd_rules_java_errorprone.html#invalidlogmessageformat

Description:
When using Brooklyn util exception's
getFirstInteresting(java.lang.Throwable throwable) method,
it returns java.lang.Throwable.
Ref. https://brooklyn.apache.org/v/0.6.0/use/api/brooklyn/util/exceptions/Exceptions.html

However, PMD detects it as an argument connected to a placeholder.

Code Sample demonstrating the issue:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class InvalidLogMessageFormat{
        private static final Logger log = LoggerFactory.getLogger(InvalidLogMessageFormat.class);
        public void test(){
                //detected
                log.error("Error starting " + app + ": "+ Exceptions.collapseText(e),Exceptions.getFirstInteresting(e));
        }
}

Expected outcome:
PMD should not report any warnings.
That's a false positive because there is no placeholder and the argument is Throwable.

Running PMD through: [CLI]

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions