Skip to content

Increased idempotency of EqualsAvoidsNull by avoiding too many swaps#496

Merged
greg-at-moderne merged 2 commits into
mainfrom
greg-EqualsAvoidsNull-idempotency-2
Apr 7, 2025
Merged

Increased idempotency of EqualsAvoidsNull by avoiding too many swaps#496
greg-at-moderne merged 2 commits into
mainfrom
greg-EqualsAvoidsNull-idempotency-2

Conversation

@greg-at-moderne

@greg-at-moderne greg-at-moderne commented Apr 7, 2025

Copy link
Copy Markdown
Contributor

What's changed?

Increasing the idempotency of EqualsAvoidsNull recipe. Specifically preventing thrashing between expressions like FOO.equals(BAR) changed to BAR.equals(FOO) changed to FOO.equals(BAR), etc.

The test code has been taken from #487 (kudos to @pankratz76).

What's your motivation?

@greg-at-moderne greg-at-moderne self-assigned this Apr 7, 2025
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Apr 7, 2025
@Pankraz76

Copy link
Copy Markdown
Contributor

nice to see this going on, thanks.

@greg-at-moderne greg-at-moderne marked this pull request as ready for review April 7, 2025 16:03
@greg-at-moderne greg-at-moderne requested a review from Copilot April 7, 2025 16:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNull.java:174

  • Consider whether other constant expression types beyond J.Literal should be included in this check, as the current condition may not cover all cases where swapping should be avoided.
if (!(firstArgument instanceof J.Literal) && !(m.getSelect() instanceof J.Literal)) {

src/test/java/org/openrewrite/staticanalysis/EqualsAvoidsNullTest.java:599

  • [nitpick] The parameter name '_null' might be confused with the actual null literal; consider renaming it to a more descriptive identifier.
public void bar(String _null) {

@greg-at-moderne greg-at-moderne merged commit 252ef7f into main Apr 7, 2025
@greg-at-moderne greg-at-moderne deleted the greg-EqualsAvoidsNull-idempotency-2 branch April 7, 2025 16:13
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants