Dhairya-007 opened a new pull request, #29679:
URL: https://github.com/apache/camel/pull/29679
## Problem
`ReferenceId.equals` compares the **normalized** error lists:
```java
return Objects.equals(id, other.id) && Objects.equals(referenceId,
other.referenceId)
&& Objects.equals(getErrors(), other.getErrors());
```
```java
public List<RestError> getErrors() {
return unmodifiableList(ofNullable(errors).orElse(emptyList()));
}
```
while `hashCode` reads the raw field:
```java
result = prime * result + (errors == null ? 0 : errors.hashCode());
```
So two reference ids with the same `id` and `referenceId`, one deserialized
from a response without an `errors` property (`errors == null`) and one from
`"errors": []`, are **equal** but hash to different values — `0` versus
`emptyList().hashCode()`, which is `1`.
That violates the `Object.hashCode` contract ("equal objects must have equal
hash codes"), so a `HashMap`/`HashSet` keyed on `ReferenceId` can miss an entry
stored under the other form. Both forms do occur: `SObjectTreeResponse` and
`SObjectCompositeResponse` carry reference ids with and without errors
depending on whether the record succeeded.
## Fix
Hash `getErrors()`, the same accessor `equals` compares. It never returns
null, so the null guard is no longer needed.
## Tests
New `ReferenceIdTest` (same package, so it can use the package-private
constructor):
- `missingAndEmptyErrorsShouldHashAlike` — the contract case; fails on
`main`.
- `equalReferenceIdsShouldHashAlike` and
`differentReferenceIdsShouldNotBeEqual` as guards around the rest of the
behaviour.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]