A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/3071 below:

[java] BrokenNullCheck FP with PMD 6.30.0 · Issue #3071 · pmd/pmd · GitHub

Affects PMD Version: pmd 6.30.0

Rule: BrokenNullCheck
https://pmd.github.io/pmd-6.30.0/pmd_rules_java_errorprone.html#brokennullcheck

Description:
Hello, I think I found some False Positives in BrokenNullCheck and I want to report them.

There are some alarms on cases which don't call method on object. It means that they cannot throw NullPointException.
I think that I found three cases which are different from each other.
Case 1. Using instanceof
Case 2. Using Boolean Class
Case 3. Comparing between Local Variable and Field which have the same identifier and accessed by this.

Details about codes are below.
Thank you.

Code Sample demonstrating the issue:

class Test {
    Object obj = new Object();
    Object objectWithDifferentName;

    public void testPMD(){
        Object obj = new Object();
        String str = "str";
        Boolean boo = null;

        //Case 1. : An Alarm is generated
        if(obj == null && !(obj instanceof String));

        //Case 2. : Alarms are generated for each line.
        if(boo == null && boo != true) ;
        if(boo == null && boo != false);

        //Case 3.
        if(obj == null && this.obj == null); //An Alarm is generated
        if(obj == null && this.objectWithDifferentName); //An Alarm isn't generated
        if(obj == null && objectWithDifferentName); //An Alarm isn't generated
    }
 }

Expected outcome:
Expected that there wouldn't be any alarms.

Running PMD through: [CLI]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4