Skip to content

Conversation

@AlexCai2019
Copy link
Contributor

There are some equals() that are not constant.equals(variable), but variable.equals(constant).
I suggested to always use constant.equals(variable), since it can avoid vary unintentionally bug, such as NullPointerException.

There are some equals() that are not constant.equals(variable), but variable.equals(constant)
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 4, 2025

@stleary
Copy link
Owner

stleary commented Jun 5, 2025

@AlexCai2019 refactoring is not encouraged in this project, but I think in this case it improves the code.
Test coverage is good overall, except for JSONObject removeLeadingZerosOfNumber()
image

If you get a chance to add some test coverage in the next 3 days, it would be appreciated. Otherwise, I can add something later.

@stleary
Copy link
Owner

stleary commented Jun 5, 2025

What problem does this code solve?
Improves code safety by checking for string equality with literals on the lhs.

Does the code still compile with Java6?
Yes

Risks
Low

Changes to the API?
No

Will this require a new release?
No

Should the documentation be updated?
No

Does it break the unit tests?
No, but low coverage was found in one method.

Was any code refactored in this commit?
This commit is a refactor.

Review status
APPROVED

Starting 3-day comment window

@stleary stleary merged commit f1935f5 into stleary:master Jun 7, 2025
8 checks passed
@stleary stleary changed the title Use constant.equals() Refactor: Check equality with literal on lhs Dec 24, 2025
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