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] SimplifyConditional: False negative when null check and instanceof are separated by other && conditions · Issue #6513 · pmd/pmd

[java] SimplifyConditional: False negative when null check and instanceof are separated by other && conditions #6513

New issue
Copy link
New issue
Copy link
Closed
#6946
Closed
[java] SimplifyConditional: False negative when null check and instanceof are separated by other && conditions#6513
#6946
Copy link
Labels
a:false-negativePMD doesn't flag a problematic piece of code
Milestone
7.28.0

Description

@leemeii
leemeii
opened on Mar 20, 2026
Issue body actions

Affects PMD Version: 7.22.0

Rule:SimplifyConditional

Description:
The SimplifyConditional rule only detects the pattern x != null && x instanceof Type when the null check is directly adjacent to the instanceof expression.
When additional conditions are inserted in the && chain, the rule fails to trigger even though the null check before instanceof remains completely redundant (semantically identical after removal).
This is very common in real-world code, where developers frequently insert additional non-null checks or other conditions in the middle of the && chain .

Code Sample demonstrating the issue:

public class a{
    public void foo(){
        String s = "a";
        if( s!=null&&s instanceof String){   // Scenario A: Direct adjacent case (correctly reported - TP)
            System.out.println(s);
        }

        String s2="a";
        if(s!=null && s2!=null && s instanceof String){   // Scenario B: Intervening condition (False Negative)
            System.out.println(s);
        }
    }
}

Expected outcome:

PMD should report a violation at line 10 with the message:
"No need to check for null before an instanceof"
But currently it only reports the first if, completely missing the second one. This is a false-negative.

Running PMD through: CLI

Activity

  1. leemeii
    added
    a:false-negativePMD doesn't flag a problematic piece of code
    on Mar 20, 2026
  2. leemeii
    added a commit that references this issue on Mar 30, 2026

    [java] Fix SimplifyConditional false negative when null check and ins…

    This issue will close once commit 5bda90a is merged into the 'main' branch.
    5bda90a
  3. fudianchn
    added a commit that references this issue on Aug 12, 2026

    [java] Fix pmd#6513: SimplifyConditional detects null check separated…

    This issue will close once commit 1b55586 is merged into the 'main' branch.
    1b55586
  4. fudianchn
    added 3 commits that reference this issue on Aug 22, 2026

    [java] Fix pmd#6513: detect the redundant null check at any position …

    This issue will close once commit 439ad33 is merged into the 'main' branch.
    439ad33

    [java] Fix pmd#6513: detect the redundant null check at any position …

    This issue will close once commit 9ba5e99 is merged into the 'main' branch.
    9ba5e99

    [java] Fix pmd#6513: dedicated message when the null check alone cann…

    This issue will close once commit aa95d35 is merged into the 'main' branch.
    aa95d35
  5. UncleOwen
    added this to the 7.28.0 milestone on Sep 12, 2026
  6. UncleOwen
    closed this as completedin #6946on Sep 12, 2026
  7. UncleOwen
    added a commit that references this issue on Sep 12, 2026

    [java] Fix pmd#6513: SimplifyConditional detects null check separated…

    This issue will close once commit dd5b3e5 is merged into the 'main' branch.
    dd5b3e5
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.28.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.