Skip to content

[java] CompareObjectsWithEquals - false negative with type res #2880

@adangel

Description

@adangel

Affects PMD Version: 6.30.0-SNAPSHOT

Rule: CompareObjectsWithEquals

Description:

From #2871 (comment)

Code Sample demonstrating the issue:

See https://chunk.io/pmd/fc7db65b2c6a46eca4c9a0c3012482e2/diff/checkstyle/index.html#A111

import java.math.BigInteger;

public class Foo {
    private BigInteger field = new BigInteger("10");
    private BigInteger field2 = new BigInteger("20");
    
    public boolean check(final BigInteger param) {
        final BigInteger other = new BigInteger("20");

        return (field == null
                || param != field   // warning expected: Use equals() to compare object references. 
                && other != field)  // warning expected: Use equals() to compare object references. 
            && param.testBit(field2.intValue())
            && other.testBit(field2.intValue());
    }
}

Expected outcome:

  • Is PMD missing to report a violation, where there should be one? -> false-negative

Running PMD through: regression-tester

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-negativePMD doesn't flag a problematic piece of codegood first issueA great starting point for new contributorshelp-wanted

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions