Skip to content

[java] InvalidLogMessageFormat: False positive for unresolved exception type (incomplete auxclasspath) #7137

Closed

Description

@piotridzikowski

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

Activity

  1. added
    a:false-positive
    on Oct 2, 2026
  2. KaustAbhinand commented on Oct 4, 2026

    @KaustAbhinand
    Contributor

    Hi has anyone opened a PR for this? If not, i would like to take it up :)

  3. UncleOwen commented on Oct 4, 2026

    @UncleOwen
    Member

    @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")

  4. 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, 2026
  5. KaustAbhinand commented on Oct 7, 2026

    @KaustAbhinand
    Contributor

    Hi @UncleOwen! I have opened a PR, please review it.

  6. zbynek commented on Oct 18, 2026

    @zbynek
    Contributor
  7. piotridzikowski commented on Oct 20, 2026

    @piotridzikowski
    Author
  8. zbynek commented on Oct 21, 2026

    @zbynek
    Contributor

    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.

  9. 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, 2026
  10. adangel commented on Oct 26, 2026

    @adangel
    Member

    It's definitely auxclasspath problem, as the fix/PR clearly says "unresolved type"...

  11. added
    in:type-resolution
    on Oct 26, 2026
  12. 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, 2026
  13. added this to the 7.29.0 milestone on Oct 26, 2026
  14. added a commit that references this issue on Oct 26, 2026
    817b8cd
  15. 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
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-positivein:type-resolution

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions