-
Notifications
You must be signed in to change notification settings - Fork 156
Description
Description
The RefToken class has a semantic bug in its equals() and hashCode() implementations. Currently, these methods only consider the decodedToken field, ignoring the index and keyRef fields. This causes semantically different tokens to be incorrectly treated as equal.
Problem
Two RefToken instances can have the same decodedToken but represent different operations:
append("0")createsRefToken("0", null, null)— field accessappend(0)createsRefToken("0", 0, null)— array index access
The current implementation would incorrectly consider these tokens equal, which can cause AbstractJsonPointer.equals() to fail when comparing paths that differ in semantic type (e.g., /a/0/b where the 0 is a field name vs. an array index).
Expected Behavior
The equals() method should compare all three fields: decodedToken, index, and keyRef using null-safe comparisons (e.g., Objects.equals).
The hashCode() method should include all three fields (e.g., Objects.hash(decodedToken, index, keyRef)).
Additional Context
This is a pre-existing issue from the original JsonPointer implementation where RefToken was an inner class. It was identified during PR #221 (Jackson 3.x support) when RefToken was extracted to a standalone class.
Reference:
- PR: Add Jackson 3 support #221
- Discussion: Add Jackson 3 support #221 (comment)
Reported by: @sondemar
Location
src/main/java/com/flipkart/zjsonpatch/RefToken.java lines 121-134