GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] UnconditionalIfStatement: False negative for negated boolean constant · Issue #6435 · pmd/pmd

[java] UnconditionalIfStatement: False negative for negated boolean constant #6435

New issue
Copy link
New issue
Copy link
Closed
#6939
Closed
[java] UnconditionalIfStatement: False negative for negated boolean constant#6435
#6939
Copy link
Labels
a:false-negativePMD doesn't flag a problematic piece of code
Milestone
7.27.0

Description

@leemeii
leemeii
opened on Feb 1, 2026
Issue body actions

Affects PMD Version: 7.20.0

Rule: UnconditionalIfStatement
https://pmd.github.io/pmd/pmd_rules_java_errorprone.html#unconditionalifstatement

Description:
UnconditionalIfStatement fails to detect cases where the condition is an effectively constant boolean expression, such as a UnaryExpression involving a boolean literal (e.g., if (!false)).

In the AST, !false is parsed as a UnaryExpression containing a BooleanLiteral, which does not satisfy the current [BooleanLiteral[1]] predicate. This allows unconditional code blocks to bypass static analysis simply by adding a logical NOT operator.

Code Sample demonstrating the issue:

public class Bug {
    public void method() {
        
        if (!false) { //<-should report (FN)
            int i = 1;
        }
    }
}

Expected outcome:

PMD should report a violation at line 4, but doesn't. This is a false-negative. The rule should be updated to account for simple constant expressions or at least unary-negated literals.

Actual outcome
Line 4 is ignored.

Running PMD through: CLI

Activity

  1. leemeii
    added
    a:false-negativePMD doesn't flag a problematic piece of code
    on Feb 1, 2026
  2. adangel
    changed the title [-]UnconditionalIfStatement: False negative when boolean literal is wrapped in UnaryExpression[/-] [+][java] UnconditionalIfStatement: False negative when boolean literal is wrapped in UnaryExpression[/+] on Feb 16, 2026
  3. adangel
    changed the title [-][java] UnconditionalIfStatement: False negative when boolean literal is wrapped in UnaryExpression[/-] [+][java] UnconditionalIfStatement: False negative for negated boolean expression[/+] on Feb 16, 2026
  4. adangel
    changed the title [-][java] UnconditionalIfStatement: False negative for negated boolean expression[/-] [+][java] UnconditionalIfStatement: False negative for negated boolean constant[/+] on Feb 16, 2026
  5. adangel commented on Feb 16, 2026

    @adangel
    adangel
    on Feb 16, 2026
    Member
    More actions

    Thanks for reporting.

    bypass static analysis simply by adding a logical NOT operator.

    By adding single not, you would change the semantic. But the easier way to bypass this rule is !!true ...

  6. fudianchn
    added a commit that references this issue on Aug 11, 2026

    [java] Fix pmd#6435: UnconditionalIfStatement flags arbitrarily negat…

    This issue will close once commit 14cb000 is merged into the 'main' branch.
    14cb000
  7. UncleOwen
    added this to the 7.27.0 milestone on Aug 11, 2026
  8. UncleOwen
    closed this as completedin #6939on Aug 11, 2026
  9. UncleOwen
    added a commit that references this issue on Aug 11, 2026

    [java] Fix #6435: UnconditionalIfStatement flags arbitrarily negated …

    This issue will close once commit eb9dc7d is merged into the 'main' branch.
    eb9dc7d
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-negativePMD doesn't flag a problematic piece of code

    Type

    No type

    Projects

    No projects

      Milestone

      • 7.27.0

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.