Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
adangel opened this issue Oct 29, 2020 · 1 comment
Closed

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

adangel opened this issue Oct 29, 2020 · 1 comment
Labels
a:false-negative PMD doesn't flag a problematic piece of code good first issue A great starting point for new contributors help-wanted
Milestone

Comments

@adangel
Copy link
Member

adangel commented Oct 29, 2020

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

@adangel adangel added good first issue A great starting point for new contributors a:false-negative PMD doesn't flag a problematic piece of code help-wanted labels Oct 29, 2020
@oowekyala oowekyala added this to the 7.0.0 milestone Nov 10, 2020
oowekyala added a commit to oowekyala/pmd that referenced this issue Nov 10, 2020
@adangel
Copy link
Member Author

adangel commented Dec 11, 2020

Fixed via #2899 for PMD 7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-negative PMD doesn't flag a problematic piece of code good first issue A great starting point for new contributors help-wanted
Projects
None yet
Development

No branches or pull requests

2 participants