Dhairya-007 opened a new pull request, #29675:
URL: https://github.com/apache/camel/pull/29675

   ## Problem
   
   `WordpressAPIConfiguration.equals` delegates back to itself:
   
   ```java
   @Override
   public boolean equals(Object obj) {
       if (obj == null) {
           return false;
       }
       if (!WordpressAPIConfiguration.class.isAssignableFrom(obj.getClass())) {
           return false;
       }
       return Objects.equals(this, obj);
   }
   ```
   
   `Objects.equals(a, b)` is `(a == b) || (a != null && a.equals(b))`. With `a 
== this`, comparing **two distinct instances** re-enters this same method with 
the same arguments and recurses until it throws `StackOverflowError`. The only 
case that terminates is `config.equals(config)`, and then only because of the 
`a == b` shortcut inside `Objects.equals` — so the method never actually 
compared anything.
   
   `hashCode()` right above it hashes `apiUrl`, `apiVersion` and 
`authentication`, which shows what `equals` was meant to compare.
   
   ## Fix
   
   Compare those same three fields, so `equals` terminates and is consistent 
with `hashCode`.
   
   ## Tests
   
   New `WordpressAPIConfigurationTest`:
   
   - two distinct but equal instances are equal and share a hash code (this is 
the case that throws `StackOverflowError` on `main`);
   - `equals` is reflexive;
   - instances differing in `apiUrl`, `apiVersion` or `authentication` are not 
equal;
   - another type and `null` are not equal.


-- 
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]

Reply via email to