Skip to content

[java] Deprecate redundant String Comparison rules #2493

Merged
adangel merged 2 commits into
pmd:masterfrom
John-Teng:deprecate_position_literals_first
May 22, 2020
Merged

[java] Deprecate redundant String Comparison rules #2493
adangel merged 2 commits into
pmd:masterfrom
John-Teng:deprecate_position_literals_first

Conversation

@John-Teng

@John-Teng John-Teng commented May 18, 2020

Copy link
Copy Markdown
Contributor

Describe the PR

The AbstractPositionLiteralsFirstInComparisons, PositionLiteralsFirstInComparisons, and PositionLiteralsFirstInCaseInsensitiveComparisons Java rules are replaced with a more general rule (LiteralsFirstInComparisons) that checks all forms of String comparisons.

This PR adds deprecated tags to the rules and the rulesets.

Related issues

Added new replacement rule: #2478
Original thread: #2145

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by travis)
  • Added (in-code) documentation (if needed)

@John-Teng John-Teng force-pushed the deprecate_position_literals_first branch from 9cf64df to 01c283c Compare May 18, 2020 20:56
@ghost

ghost commented May 18, 2020

Copy link
Copy Markdown
1 Message
📖 This changeset introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 275 violations, 0 errors and 0 configuration errors.
Full report

Generated by 🚫 Danger

@adangel adangel added this to the 6.24.0 milestone May 22, 2020

@adangel adangel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! I'll do the minor changes when merging.

<description>
Position literals first in comparisons, if the second argument is null then NullPointerExceptions
can be avoided, they will just return false.
can be avoided, they will just return false. This rule is replaced by the more general LiteralsFirstInComparisons rule.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should directly link to the other rule {% rule "LiteralsFirstInComparisons" %} and use a new paragraph - I'll change that, when merging.


package net.sourceforge.pmd.lang.java.rule.bestpractices;

@Deprecated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should add a javadoc note to mention, that the class has been replaced by LiteralsFirstInComparisons. I'll do that, when merging.

@adangel adangel self-assigned this May 22, 2020
adangel added a commit that referenced this pull request May 22, 2020
adangel added a commit that referenced this pull request May 22, 2020
[java] Deprecate redundant String Comparison rules #2493
@adangel adangel merged commit 261f2d7 into pmd:master May 22, 2020
oowekyala added a commit that referenced this pull request Dec 10, 2020
…omparsons, PositionLiteralsFirstInComparisons

Refs #2493, #2701, #2022
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.

2 participants