Use Objects.equals instead of hand-rolled String == comparison (CodeQL java/reference-equality-on-strings)#230
Open
vharseko wants to merge 1 commit into
Conversation
…L java/reference-equality-on-strings) ResourceResponseImpl.equals() delegated to a private isEqual(String, String) helper that started with a "s1 == s2" reference check. The reference compare was an intentional fast-path / both-null shortcut and the real value compare was done by s1.equals(s2), so the code was correct, but CodeQL flags the String == String and the helper simply reimplements java.util.Objects.equals. Replace the two isEqual calls with Objects.equals (already imported) and drop the helper. Behaviour is identical - Objects.equals performs the same "a == b || (a != null && a.equals(b))" null-safe comparison.
maximthomas
approved these changes
Jul 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves the single
java/reference-equality-on-stringsCodeQL alert inResponses.java.ResourceResponseImpl.equals()delegated to a privateisEqual(String, String)helper whose first line was a
s1 == s2reference comparison. The referencecheck was an intentional fast-path (and both-
nullshortcut) with the realvalue comparison delegated to
s1.equals(s2)— so the code was correct, but:String == String, andjava.util.Objects.equals.Fix
Replace the two
isEqual(...)calls withObjects.equals(...)(alreadyimported) and delete the helper:
Behaviour is identical —
Objects.equals(a, b)performs the samea == b || (a != null && a.equals(b))null-safe comparison, including thesame reference fast-path and both-
nullhandling.Testing
mvn -o -pl commons/rest/json-resource -am compile— BUILD SUCCESS.