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: False positive when final parameter is Supplier<Throwable> · Issue #3601 · pmd/pmd

[java] InvalidLogMessageFormat: False positive when final parameter is Supplier<Throwable> #3601

New issue
Copy link
New issue
Copy link
Closed
#6407
Closed
[java] InvalidLogMessageFormat: False positive when final parameter is Supplier<Throwable>#3601
#6407
Copy link
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
7.21.0

Description

@krallus
krallus
opened on Nov 3, 2021
Issue body actions

Affects PMD Version: 7.0.0

Rule: InvalidLogMessageFormat

Description:
PMD issues a false positive "InvalidLogMessageFormat" with message "Too many arguments, expected 1 argument but have 2" (for the below code sample). This occurs when the parameters are passed as type Supplier<?> functions and the final supplier supplies a Throwable type. Log4j always treats the last parameter as special when it is a Throwable, even when using parameter suppliers for all parameters. Therefore, in the code sample below, there is indeed only one parameter that is supplied.

Code Sample demonstrating the issue:

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class Foo {
    private static final Logger logger = LogManager.getLogger();

    public void myMethod(Object id) {
        try {
            throw new Exception("aaa");
        } catch (final Exception exception) {
            logger.warn("Object with ID {} had a problem.", () -> String.valueOf(id), () -> exception);
        }
    }
}

Expected outcome:
No problem reported as the last parameter references an exception.

However, PMD reports a violation at the logger.warn(...) line.

Running PMD through: PMD Plug-in 4.29 for Eclipse

Reacted by Bogdan Ilchyshyn

Activity

  1. krallus
    added
    a:false-positivePMD flags a piece of code that is not problematic
    on Nov 3, 2021
  2. krallus commented on May 2, 2023

    @krallus
    krallus
    on May 2, 2023
    Author
    More actions

    Note that I just confirmed that this is still an issue with:
    PMD Plug-in 7.0.0.v20230502-1028-rc2
    Log4j 2.20.0
    Eclipse 2023-03 (4.27.0)
    Linux Mint 21.1 Cinnamon

  3. jsotuyod
    added
    needs:pmd7-revalidationThe issue hasn't yet been retested vs PMD 7 and may be stale
    on Mar 17, 2024
  4. adangel commented on Mar 21, 2024

    @adangel
    adangel
    on Mar 21, 2024
    Member
    More actions

    The issue is still reproducible under PMD 7.0.0.

    Reacted by Philip Hachey
  5. adangel
    removed
    needs:pmd7-revalidationThe issue hasn't yet been retested vs PMD 7 and may be stale
    on Mar 21, 2024
  6. orange-buffalo commented on Oct 13, 2025

    @orange-buffalo
    orange-buffalo
    on Oct 13, 2025
    More actions

    Still reproducible on 7.17.0.
    Also in case when the last argument is a Throwable directly, without Supplier.

  7. lukasgraef
    added a commit that references this issue on Jan 17, 2026

    [doc] Update release notes (pmd#3601)

    32fc88d
  8. lukasgraef
    added a commit that references this issue on Jan 25, 2026

    [doc] Update release notes (pmd#3601)

    7abd970
  9. adangel
    changed the title [-][java] False InvalidLogMessageFormat when final parameter is Supplier<Throwable>[/-] [+][java] InvalidLogMessageFormat: False positive when final parameter is Supplier<Throwable>[/+] on Jan 29, 2026
  10. adangel
    added this to the 7.21.0 milestone on Jan 29, 2026
  11. adangel
    closed this as completedin 4c3ba5aon Jan 29, 2026
  12. adangel
    added a commit that references this issue on Jan 29, 2026

    [java] Fix pmd#3601: InvalidLogMessageFormat: False positive when fin…

    This issue will close once commit 4c3ba5a is merged into the 'main' branch.
    4c3ba5a
  13. wener-tiobe
    added a commit that references this issue on Feb 10, 2026

    RM-37163: CPD 7.21.0 upgrade (#8)

    6a1959a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      • 7.21.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.