GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] InvalidLogMessageFormat FP with StringFormattedMessage and ParameterizedMessage · Issue #3133 · pmd/pmd

[java] InvalidLogMessageFormat FP with StringFormattedMessage and ParameterizedMessage #3133

New issue
Copy link
New issue
Copy link
Closed
#3138
Closed
[java] InvalidLogMessageFormat FP with StringFormattedMessage and ParameterizedMessage#3133
#3138
Copy link
Assignees
adangel
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
6.32.0

Description

@testation21
testation21
opened on Feb 23, 2021
Issue body actions

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]

Activity

  1. testation21
    added
    a:false-negativePMD doesn't flag a problematic piece of code
    a:false-positivePMD flags a piece of code that is not problematic
    on Feb 23, 2021
  2. adangel
    removed
    a:false-negativePMD doesn't flag a problematic piece of code
    on Feb 25, 2021
  3. adangel
    changed the title [-][java] InvalidLogMessageFormat FP in 6.31[/-] [+][java] InvalidLogMessageFormat FP with StringFormattedMessage and ParameterizedMessage[/+] on Feb 25, 2021
  4. adangel
    self-assigned this
    on Feb 25, 2021
  5. adangel
    added this to the 6.32.0 milestone on Feb 25, 2021
  6. adangel
    added a commit that references this issue on Feb 25, 2021

    [java] InvalidLogMessageFormat fix FP

    This issue will close once commit 760e868 is merged into the 'main' branch.
    760e868
  7. adangel
    closed this as completedin 760e868on Feb 26, 2021
  8. adangel
    closed this as completedin #3138on Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @adangel
    adangel

Labels

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

Type

No type

Projects

No projects

    Milestone

    • 6.32.0

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.