gnodet opened a new pull request, #28822:
URL: https://github.com/apache/camel/pull/28822
## Summary
Four bugs fixed in the `camel-ehcache` component:
1. **Shared default CacheManager** — Each endpoint URI without an explicit
`cacheManager` created its own `CacheManager`, so a GET on one endpoint could
not find what PUT stored on another endpoint using the same cache name. Fixed
by routing the default branch through `managers.computeIfAbsent()` with a
sentinel key, like the other three branches.
2. **Consumer event delivery** — A consumer on an unconfigured cache (using
the `UserManagedCache` fallback) never received events because
`UserManagedCache` requires explicit event executor services for listeners to
work. Fixed by replacing the `UserManagedCache` fallback with a fully managed
cache created via `cacheManager.createCache()`, which provides event executors
out of the box.
3. **Null body stores DefaultMessage** — `PUT`/`PUT_IF_ABSENT`/`REPLACE`
with a null body and no `CamelEhcacheValue` header silently stored the
`DefaultMessage` object in the cache instead of throwing. This happened because
`message.getBody(Object.class)` converts a null body to the Message itself.
Fixed by using `message.getBody()` (no type parameter) when the value type is
`Object.class`, which correctly returns null and triggers the existing
null-value exception.
4. **NPE when setting valueType without keyType** — Setting `valueType`
without `keyType` caused an NPE because the condition `if (keyType == null &&
valueType == null)` required *both* to be null. Fixed by defaulting each
independently.
## Root Causes
| Bug | File | Root Cause |
|-----|------|------------|
| 1 | `EhcacheComponent.java` | Default branch in `createCacheManager()`
created a new `EhcacheManager` every call instead of using `computeIfAbsent()` |
| 2 | `EhcacheManager.java` | `UserManagedCacheBuilder` does not configure
event executor services, so `registerCacheEventListener()` silently does
nothing |
| 3 | `EhcacheProducer.java` | `message.getBody(Object.class)` type-converts
null body to the Message itself |
| 4 | `EhcacheManager.java` | `&&` instead of independent `if` checks for
keyType/valueType null defaults |
## Changes
### Production code
- **`EhcacheComponent.java`**: Use
`managers.computeIfAbsent(EhcacheComponent.class, ...)` for the default branch
with a clean `EhcacheConfiguration`
- **`EhcacheManager.java`**:
- Remove `UserManagedCache`/`userCaches` — replaced with
`cacheManager.createCache()` using `ResourcePoolsBuilder.heap(100)`
- Add `getCache()` overload accepting an endpoint-specific
`EhcacheConfiguration` so shared managers can use per-endpoint cache configs
- Default `keyType` and `valueType` independently
- **`EhcacheProducer.java`**: Use `message.getBody()` when type is
`Object.class`; pass endpoint config to `getCache()`
- **`EhcacheConsumer.java`**: Pass endpoint config to `getCache()`
### Test code
- **`EhcacheDefaultsTest.java`** (new): 5 tests covering all 4 bugs — shared
cache across endpoints, consumer event delivery, null body exception,
valueType-only NPE, and PUT_IF_ABSENT null body
- **`EhcacheCacheConfigurationTest.java`**: Removed `UserManagedCache`
assertion (cache is now managed)
- **`EhcacheRemoveRouteTest.java`**: Updated tests that depended on
`UserManagedCache` status tracking
## Test Coverage
All 89 tests pass (`mvn test -pl components/camel-ehcache`).
_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]