allthingssecurity opened a new pull request, #30462: URL: https://github.com/apache/camel/pull/30462
# Description [CAMEL-27215](https://issues.apache.org/jira/browse/CAMEL-27215) `JCacheIdempotentRepository`, `JCacheAggregationRepository` and `JCacheKeyValueRepository` open their cache on start when they are given a configuration (`cacheName`), and close their `JCacheManager` on stop, which releases the cache and closes it (with the cache manager and the caching provider) when nothing else uses it (CAMEL-26287). They keep the cache field, so the next start does not open the cache again but wraps the closed cache in a new manager: every `add` / `get` / `put` then fails with `IllegalStateException` (cache closed). The repository is stopped and started again when its route is removed and added again, as a route reload does (the Idempotent Consumer and the Aggregate EIP stop their repository when their route is removed), or when the CamelContext is stopped and started. After that every exchange of the route fails. Fix: on stop, a repository that opened its cache from its configuration (its manager has a configuration) forgets the cache after closing the manager, so the next start opens it again. A cache given with `setCache` is kept as before: the repository wraps it and never closes it. The aggregation repository also gets the null check on stop that the other two have. Model: a small TLA+ model (`RepoRestart.tla`, KIND=jcache: a repository that opens a reference-counted cache on start and releases it on stop, another user of the cache or none, stop and start again) checks "no operation uses a closed cache". On main it is violated in 4 states (start, stop: the last user closes the cache, start: the closed cache is wrapped, use); with the change it holds (12 distinct states). Tests: `JCacheRepositoriesRestartTest` (camel-jcache, Hazelcast JCache provider as the other tests of the module): an idempotent consumer with a repository from `cacheName`, the route removed and added again, then a new message must pass; and each of the three repositories started, stopped and started again must work. On main all four tests fail (`IllegalStateException`: the cache is closed; the reloaded route fails its exchange). With the change they pass, and the camel-jcache tests pass (107 run, 0 failures). The new class 20 times in one JVM: 80 run, 0 failures. # Target - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch) # Tracking - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it): [CAMEL-27215](https://issues.apache.org/jira/browse/CAMEL-27215). # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. (I built the touched module with the formatter and import-sort plugins; no option, doc or generated file changes. I did not run the full root build.) # AI-assisted contributions - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used. This PR was prepared with Claude Code (Claude Opus 5.5). The commit carries a `Co-Authored-By` trailer. _Claude Code on behalf of allthingssecurity_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
