New rule to suggest "string".length() == 0 -> "string".isEmpty()

There should be a new rule to suggest a change of

"string".length() == 0

to

"string".isEmpty()

and

"string".length() > 0

to

!"string".isEmpty()

and

"string".trim().length() == 0

to

"string".isBlank()

and

"string".trim().length() > 0

to

!"string".isBlank()

And please add a good quick fix. It’s so easy to indroduce regressions with negation.

On a side node this quick fix should also be applied java:S1155.

2 Likes