A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/253 below:

[java] InvalidLogMessageFormat doesn't handle formats assembled via multi-stage concatenation · Issue #253 · pmd/pmd · GitHub

Rule Set:
Logging-Java/InvalidSlf4jMessageFormat
Now: InvalidLogMessageFormat

Description:
Some of our code assembles SLF4J format strings in multiple stages; a method might define a message format containing a placeholder, then an error format that adds to the message format, etc. However, InvalidSlf4jMessageFormat only checks the number of placeholders in the most recent concatenation, eg if message contained 2 placeholders and error added one more, then InvalidSlf4jMessageFormat would expect only one argument when it is used.

Code Sample demonstrating the issue:

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

public class Slf4JMessageFormatConcatenation {
    private static final Logger LOG = LoggerFactory.getLogger(Slf4JMessageFormatConcatenation.class);

    public void run() {
        String message = "Field: {}";
        // some code
        String error = message + ", error: {}";
        
        LOG.error(error, "fieldValue", "errorMessage");
    }
}

Running PMD through:
Maven

lidel, jeffjensen, matdelong-tii and Frettman


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