openrewrite / openrewrite/rewrite-static-analysis

Prefer String::equalsToIgnoreCase - "foo".equals("Foo".toLowercase()) -> "foo".equalsToIgnoreCase("Foo")

Open
#274 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
62
Forks
112
Avg merge
1d 19h
Merged PRs (30d)
40

Description

What problem are you trying to solve?

Just came across this finding from IntelliJ:

String upperFoo = "FoO"
"foo".equals(upperFoo.toLowercase())

can be

String upperFoo = "FoO"
"foo".equalsToIgnoreCase(upperFoo)

Condition: the first string is all lowercase

Would be nice to have that automated.
I've considered posting this in rewrite-migrate-java, but as there is no "since" in the API I guess it has been around forever and was never a new language feature.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the existing Java static-analysis recipes and their tests for String equality or case conversion. Check how the project represents chained String calls, then define tests for the lowercase-first-string condition and the requested case-insensitive comparison transformation. Done means the qualifying example is automated without changing non-qualifying expressions.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.