You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[java] InvalidLogMessageFormat: False positive when final parameter is Supplier<Throwable> #3601
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:
importorg.apache.logging.log4j.LogManager;
importorg.apache.logging.log4j.Logger;
publicclassFoo {
privatestaticfinalLoggerlogger = LogManager.getLogger();
publicvoidmyMethod(Objectid) {
try {
thrownewException("aaa");
} catch (finalExceptionexception) {
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.
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
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
Activity
krallus commentedon May 2, 2023
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
adangel commentedon Mar 21, 2024
The issue is still reproducible under PMD 7.0.0.
orange-buffalo commentedon Oct 13, 2025
Still reproducible on 7.17.0.
Also in case when the last argument is a
Throwabledirectly, withoutSupplier.[doc] Update release notes (pmd#3601)
[doc] Update release notes (pmd#3601)
[-][java] False InvalidLogMessageFormat when final parameter is Supplier<Throwable>[/-][+][java] InvalidLogMessageFormat: False positive when final parameter is Supplier<Throwable>[/+][java] Fix pmd#3601: InvalidLogMessageFormat: False positive when fin…
RM-37163: CPD 7.21.0 upgrade (#8)