Skip to content

[java] GuardLogStatement: False positive when using negative guard conditions #1287

Closed

Description

@numeralnathan

Affects PMD Version:
Eclipse PMD Plug-in 1.13.0.201806091459

Rule:
GuardLogStatement

Description:
A short-circuit if statement at the top of the method is not detected by GuardLogStatement and hence a PMD warning shows up on the later log statement.

Code Sample demonstrating the issue:

Problematic code:

private void log()
{
   if (!s_logger.isDebugEnabled())
      return;
   ...
   s_logger.debug("logging from " + this);      // PMD warning shows up here
}

Working code:

private void log()
{
   if (s_logger.isDebugEnabled())
   {
      ...
      s_logger.debug("logging from " + this);      // No PMD warning
   }
}

The "..." has identical code in it.

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
Eclipse

Activity

  1. added
    a:false-positive
    on Aug 9, 2018
  2. changed the title [-][Java] GuardLogStatement does not understand negative if conditions[/-] [+][java] GuardLogStatement does not understand negative if conditions[/+] on Aug 9, 2018
  3. added
    needs:pmd7-revalidation
    on Mar 17, 2024
  4. removed
    needs:pmd7-revalidation
    on Apr 2, 2024
  5. changed the title [-][java] GuardLogStatement does not understand negative if conditions[/-] [+][java] GuardLogStatement: False positive when using negative guard conditions[/+] on Jun 9, 2026
  6. added this to the 7.27.0 milestone on Aug 14, 2026
  7. added a commit that references this issue on Aug 14, 2026
    2789d74
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