Skip to content

[java] Update rule UnnecessaryBooleanAssertion#3525

Merged
adangel merged 3 commits into
pmd:pmd/7.0.xfrom
adangel:pmd7-update-UnnecessaryBooleanAssertion
Oct 8, 2021
Merged

[java] Update rule UnnecessaryBooleanAssertion#3525
adangel merged 3 commits into
pmd:pmd/7.0.xfrom
adangel:pmd7-update-UnnecessaryBooleanAssertion

Conversation

@adangel

@adangel adangel commented Sep 30, 2021

Copy link
Copy Markdown
Member

Describe the PR

Part of #2701

Note: This fixes #3087

@adangel adangel added this to the 7.0.0 milestone Sep 30, 2021
@ghost

ghost commented Sep 30, 2021

Copy link
Copy Markdown
2 Messages
📖 Compared to pmd/7.0.x:
This changeset changes 0 violations,
introduces 2 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report
📖 Compared to master:
This changeset changes 31204 violations,
introduces 21308 new violations, 1 new errors and 0 new configuration errors,
removes 136427 violations, 8 errors and 3 configuration errors.
Full report
Compared to pmd/7.0.x:
This changeset changes 0 violations,
introduces 2 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report
Compared to master:
This changeset changes 31204 violations,
introduces 21203 new violations, 1 new errors and 0 new configuration errors,
removes 137235 violations, 8 errors and 3 configuration errors.
Full report

Generated by 🚫 Danger

@adangel

adangel commented Oct 8, 2021

Copy link
Copy Markdown
Member Author

There seem to a lot of false negatives now:

// https://github.com/spring-projects/spring-framework/tree/v5.0.6.RELEASE/spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests.java#L917
assertTrue(!rod6.destroyed);
// https://github.com/spring-projects/spring-framework/tree/v5.0.6.RELEASE/spring-tx/src/test/java/org/springframework/transaction/TransactionSupportTests.java#L89
assertTrue("no rollback", !tm.rollback);

is missing now...

Maybe that's a real fix? According to the rule description only boolean literals should be detected: https://pmd.github.io/pmd/pmd_rules_java_errorprone.html#unnecessarybooleanassertion

There are two interesting test cases on pmd6:

<test-code>
<description>asserting true a !</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
import junit.framework.TestCase;
public class Foo extends TestCase {
void bar() {
assertTrue(!foo);
}
}
]]></code>
</test-code>
<test-code>
<description>asserting false a !</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
import junit.framework.TestCase;
public class Foo extends TestCase {
void bar() {
assertFalse(!foo);
}
}
]]></code>
</test-code>

But I guess, this is a little bit different: Instead of assertTrue(!something) one should write assertFalse(something)... Not sure, if this really is in the realm of this rule - as it is clearly not assertTrue(true) and so it is not unnecessary (except "something" would be a boolean constant)....

@adangel

adangel commented Oct 8, 2021

Copy link
Copy Markdown
Member Author

Ok, see #3087 - this is actually UnneccessaryBooleanAssertion doing the same as SimplifiableTestAssertion (formerly SimplifyBooleanAssertion). So, we should probably really remove this from this rule.

@adangel adangel self-assigned this Oct 8, 2021

@adangel adangel left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the regression tester report, this looks fine. I'm going to merge this.

@adangel adangel merged commit 5643659 into pmd:pmd/7.0.x Oct 8, 2021
@adangel adangel deleted the pmd7-update-UnnecessaryBooleanAssertion branch October 8, 2021 09:59
@adangel adangel mentioned this pull request Jan 23, 2023
55 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[java] UnnecessaryBooleanAssertion overlaps with SimplifiableTestAssertion

1 participant