You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Jaderccesar (via GitHub)" <gi...@apache.org> on 2026/06/14 18:33:16 UTC
[PR] Fix: replace String == comparison with .equals() in ObjectToStringCom… [commons-lang]
Jaderccesar opened a new pull request, #1705:
URL: https://github.com/apache/commons-lang/pull/1705
## Problem
SpotBugs reports ES_COMPARING_STRINGS_WITH_EQ in ObjectToStringComparator.compare().
The original code compared String objects using `==`, which checks reference equality
rather than content equality. This can cause incorrect comparisons when two distinct
String objects have the same content.
## Solution
- Removed the `if (string1 == string2)` reference comparison
- Added null checks before content comparison (to avoid NullPointerException)
- Used `string1.equals(string2)` for correct content-based comparison
## Testing
Existing tests in ObjectToStringComparatorTest cover this method.
No new behavior is introduced, only the comparison mechanism is corrected.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix: replace String == comparison with .equals() in ObjectToStringCom… [commons-lang]
Posted by "sebbASF (via GitHub)" <gi...@apache.org>.
sebbASF commented on PR #1705:
URL: https://github.com/apache/commons-lang/pull/1705#issuecomment-4702738881
Whilst it is true that using == to compare strings is generally incorrect, in this case it is essential to ensure that nulls are handled correctly. If both objects return null for toString(), the result should be 0, but it will be 1.
Also, the equals comparison at line 74 is redundant.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix: replace String == comparison with .equals() in ObjectToStringCom… [commons-lang]
Posted by "sebbASF (via GitHub)" <gi...@apache.org>.
sebbASF closed pull request #1705: Fix: replace String == comparison with .equals() in ObjectToStringCom…
URL: https://github.com/apache/commons-lang/pull/1705
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org