GeezerVison is showing github.com — [java] InvalidLogMessageFormat: False positive for unresolved exception type (incomplete auxclasspath) · Issue #7137 · pmd/pmd
[java] InvalidLogMessageFormat: False positive for unresolved exception type (incomplete auxclasspath) #7137Description
Affects PMD Version:
7.28.0
Rule: InvalidLogMessageFormat
Description:
Using log4j in some cases PMD gives false positives. I think the problem is in if / else inside catch block.
In one case the code uses
void error(String message, Object p0);
and in the other case
void error(String message, Throwable throwable);
Code Sample demonstrating the issue:
catch ( CustomerKickoutException ckE ) {
if ( isDeploymentTypeProduction() ) {
logger.error( "Kickout error: {}", ckE.toString() );
} else {
logger.error( "Kickout error:", ckE ); // <-- Too many arguments, expected 0 argument but found 1.
}
Expected outcome:
The code in the else block uses correct void error(String message, Throwable throwable); overloaded method of this function and it should not be marked
Running PMD through: ANT ActivityKaustAbhinand commented on Oct 4, 2026 Hi has anyone opened a PR for this? If not, i would like to take it up :) UncleOwen commented on Oct 4, 2026 @KaustAbhinand No, there isn't a PR for this, yet. Go ahead!
(If there was a PR for this, you'd see it on the right under "Development") changed the title [-]InvalidLogMessageFormat false possitive when if/else blocck in the catch block[/-] [+][java] InvalidLogMessageFormat false positive when if/else block in the catch block[/+] on Oct 5, 2026KaustAbhinand commented on Oct 7, 2026 Hi @UncleOwen! I have opened a PR, please review it. zbynek commented on Oct 18, 2026 @piotridzikowski are you sure you configured the aux classpath for PMD analysis correctly? Specifically, CustomerKickoutException and all its superclasses should be visible to PMD.
piotridzikowski commented on Oct 20, 2026 Hi,
Yes, for me it looks like the auxclasspath is correct.
…zbynek commented on Oct 21, 2026 Interesting, the following code has no violations of this rule, as expected:
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
public class Bug {
private static final Logger logger = LogManager.getLogger();
public void test() {
try {
generateMessage();
} catch ( CustomerKickoutException ckE) {
if ( isDeploymentTypeProduction() ) {
logger.error( "Kickout error: {}", ckE.toString() );
} else {
logger.error( "Kickout error:", ckE );
}
}
}
private boolean isDeploymentTypeProduction() { return false; }
private String generateMessage() throws CustomerKickoutException {
if (1 < 0) {
throw new CustomerKickoutException();
}
return "message";
}
private class CustomerKickoutException extends Exception {}
}
so it's very likely that CustomerKickoutException is not visible to PMD, resulting in the false positive. Is it defined in the same library/project as the code you're validating using PMD? Could you reduce your testcase into a minimal reproducble example. changed the title [-][java] InvalidLogMessageFormat false positive when if/else block in the catch block[/-] [+][java] InvalidLogMessageFormat: false positive when if/else block in the catch block[/+] on Oct 26, 2026adangel commented on Oct 26, 2026 It's definitely auxclasspath problem, as the fix/PR clearly says "unresolved type"... changed the title [-][java] InvalidLogMessageFormat: false positive when if/else block in the catch block[/-] [+][java] InvalidLogMessageFormat: false positive for unresolved exception type (incomplete auxclasspath)[/+] on Oct 26, 2026added a commit that references this issue on Oct 26, 2026This issue will close once commit 817b8cd is merged into the 'main' branch.817b8cd changed the title [-][java] InvalidLogMessageFormat: false positive for unresolved exception type (incomplete auxclasspath)[/-] [+][java] InvalidLogMessageFormat: False positive for unresolved exception type (incomplete auxclasspath)[/+] on Oct 29, 2026
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|