gnodet opened a new pull request, #31284:
URL: https://github.com/apache/camel/pull/31284
## Summary
Fixes three bugs in `Olingo2Configuration` and `Olingo2Component` that were
silently corrupting
equality checks, polluting the component-level shared proxy, and leaving
`httpClientBuilder` dead code.
## Root Cause
**Bug 1 — `equals()` ternary-chain without parentheses
(`Olingo2Configuration`, lines 242–266):**
The ternary operator `? :` has lower precedence than `&&`. Without explicit
parentheses the chain
```java
return a && b && serviceUri == null ? other.serviceUri == null :
serviceUri.equals(...)
```
actually evaluates as
```java
return (a && b && serviceUri == null) ? other.serviceUri == null :
(serviceUri.equals(...))
```
meaning only `connectTimeout`, `filterAlreadySeen`, `splitResult`,
`socketTimeout`, and the
`serviceUri` null-check influenced the result — every other field was
ignored. Additionally, if
`serviceUri` was non-null and `contentType` happened to be `null`,
`contentType.equals(...)` would
throw `NullPointerException`.
**Bug 2 — shared proxy overwrite (`Olingo2Component.createOlingo2App`, line
191):**
`createOlingo2App` ended with `apiProxy = new Olingo2AppWrapper(...); return
apiProxy;`, assigning
the field unconditionally. `createApiProxy` calls this method for
endpoint-specific configurations
too (the `else` branch), so every endpoint that differed from the shared
configuration silently
replaced `this.apiProxy`. Subsequent endpoints that matched the shared
configuration then received
the stale wrapper, and `closeApiProxy` could no longer identify the shared
instance correctly.
**Bug 3 — `httpClientBuilder` never used
(`Olingo2Component.createOlingo2App`):**
`httpClientBuilder` was declared as a `@UriParam`, wired via setters, but
ignored in
`createOlingo2App`. The logic checked `httpAsyncClientBuilder == null`, and
if so built a fresh
`HttpAsyncClientBuilder` and assigned it back to `clientBuilder`. The `else`
branch
(`HttpClientBuilder`) was therefore unreachable.
## Fix
- **Bug 1:** Replaced the ternary chain with `Objects.equals()` calls on
each nullable field,
using Java 16 pattern-matching `instanceof` to bind `other` in one step.
- **Bug 2:** Introduced a local `wrapper` variable in `createOlingo2App`;
the method now returns
it without touching `this.apiProxy`. Only `createApiProxy`'s locked
shared-proxy block writes
`this.apiProxy`.
- **Bug 3:** Added an explicit check for `httpClientBuilder` before the
async-builder fallback,
so a user-supplied synchronous `HttpClientBuilder` is now honoured.
## Tests
`Olingo2ConfigurationTest` (new, 9 tests):
- `equals()` returns `true` for identical configurations, `false` when any
field differs
(`serviceUri`, `contentType`, `proxy`, `connectTimeout`, `socketTimeout`).
- `equals()` does not throw NPE when `serviceUri` is `null`.
- Endpoint-specific `createApiProxy` does **not** replace the shared proxy.
All 9 tests pass locally (confirmed from surefire report).
Fixes CAMEL-27977
---
_Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet_
--
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]