Search code examples
findbugs

FindBugs fails to flag RC_REF_COMPARISON when comparing two BigIntegers with ==


In my code I have something like this:

if (a.foo() == b.foo()){ ... something ... }

where foo() returns BigInteger. I think FindBugs should flag this as the bug

RC: Suspicious reference comparison (RC_REF_COMPARISON)

but it doesn't. I have tried to retype the code to something like this:

BigInteger c = a.foo();
BigInteger d = b.foo();
if(c == d){ ... something ...}

but that has no effect. I have tried several configuration settings on which bugs to find with the same false negative result. I have a lot of code to validate and I need to find all of these bugs. What setting am I missing?


Solution

  • Probably FindBugs has a list of classes it knows should not be compared as references, and BigInteger is not on that list.

    You are correct that they should not be compared as references, so BigInteger should be on the list. In general, FindBugs can't know whether it is okay for an arbitrary class.