Skip to content

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

Closed

Description

@krallus

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

Activity

  1. added
    a:false-positive
    on Nov 3, 2021
  2. krallus commented on May 2, 2023

    @krallus
    Author

    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. added
    needs:pmd7-revalidation
    on Mar 17, 2024
  4. adangel commented on Mar 21, 2024

    @adangel
    Member

    The issue is still reproducible under PMD 7.0.0.

  5. removed
    needs:pmd7-revalidation
    on Mar 21, 2024
  6. orange-buffalo commented on Oct 13, 2025

    @orange-buffalo

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

  7. 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
  8. added this to the 7.21.0 milestone on Jan 29, 2026
  9. added a commit that references this issue on Jan 29, 2026
    4c3ba5a
  10. added a commit that references this issue on Feb 10, 2026
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-positive

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions