fb-contrib icon indicating copy to clipboard operation
fb-contrib copied to clipboard

UTAO false positive with complex boolean expression

Open ThrawnCA opened this issue 8 years ago • 4 comments

I have a unit test to ensure that a utility class is properly defined (private constructor, all methods static, etc), and one of the assertions is triggering UTAO_JUNIT_ASSERTION_ODDITIES_USE_ASSERT_NOT_EQUALS, but I don't see another (let alone a better) way to structure it.

The assertion looks like:

    for (final Method method : clazz.getMethods()) {
        assertTrue("method should be static:" + method,
            Modifier.isStatic(method.getModifiers()) || !method.getDeclaringClass().equals(clazz));
    }

ThrawnCA avatar Jun 22 '17 05:06 ThrawnCA

i added the above, but unfortunately it didn't fire the FP. See anything i screwed up?

mebigfatguy avatar Jun 22 '17 05:06 mebigfatguy

No, I can't see anything wrong with the sample, but the detector is still firing for me. I've tried altering my compiler configuration (switched between JDK7 and 8, toggled debug and optimise flags on and off); no change. I also tried increasing my threshold to Default, but it still fired.

ThrawnCA avatar Jun 22 '17 06:06 ThrawnCA

I'm still seeing this - including for an exact copy of the code in the sample GitHubIssue207 class - with version 7.4.0.sb.

ThrawnCA avatar Jun 01 '18 04:06 ThrawnCA

I'm not enough of an expert to read this properly, but it looks like UnitTestAssertionOddities will only record this bug when it thinks it has seen a negated equals expression. This occurs as part of the sample code, !method.getDeclaringClass().equals(clazz), but since this is only one part of the expression, it shouldn't fire.

ThrawnCA avatar Jun 01 '18 04:06 ThrawnCA