allthingssecurity opened a new pull request, #29895: URL: https://github.com/apache/camel/pull/29895
# Description [CAMEL-26904](https://issues.apache.org/jira/browse/CAMEL-26904) `KafkaIdempotentRepository` applies each record of its topic in `addToCache`, which takes the action from the record value with `CacheAction.valueOf(value)`. A record without a value (a tombstone, which an operator or a tool can write to the topic, for example to delete a key from a compacted topic; the repository never writes one) makes `valueOf` throw a `NullPointerException`, and only `IllegalArgumentException` was caught: - at start the repository reads the topic from the beginning (`KafkaChangelog.populateCache`, no catch), so it fails to start for as long as the record is in the topic; - in the background poll (`KafkaChangelog.TopicPoller` catches per poll) the records after it in that poll are not applied, and the consumer position is already past them, so the keys they add or remove are missing on this node. A record with the action `add` or `remove` and no key fails the same way (the cache does not take a null key). This was listed as a residual in CAMEL-23996 (a null-valued record aborts the startup). Change, in `KafkaIdempotentRepository.addToCache`: a record without a value, or an `add` or `remove` without a key, is logged at WARN and skipped (a `clear` has no key, as before). The WARN for an unknown action now logs the value (it logged the key). Nothing changes for the records the repository writes itself. A tombstone is skipped, not applied as a remove, as `SingleNodeKafkaResumeStrategy` does (CAMEL-26709): the repository never writes one, and keeping the key cannot let a message through twice. A per-record catch in `KafkaChangelog` would cover the other repository that uses it too, but would also hide an unexpected failure of a handler, so the check stays in the repository. Tests, in `KafkaIdempotentRepositoryTest` (no broker, the records applied through `addToCache` as `testAddRollbackKeepsTheKeyAddedByAPeer` does): - `testTombstoneIsSkippedAndTheNextRecordsAreApplied`: a tombstone for a key in the cache (the key stays: skipped, not removed), then an `add` of another key, which must be applied; - `testAddOrRemoveWithoutKeyIsSkipped`: an `add` and a `remove` without a key leave the cache as it was, the next `add` is applied; - `testClearWithoutKeyIsApplied`: a control, a `clear` (which has no key) still clears. Without the change the first two fail with the `NullPointerException`; the control passes. With it the camel-kafka unit tests pass (328 run, 0 failures, 1 skipped). The ITs need a Kafka container and were not run locally (CI runs them). No documentation or upgrade guide change: only records the repository never writes are affected. Backport: `addToCache` is the same on 4.18.x and 4.14.x, so the change to it applies there; `KafkaIdempotentRepositoryTest` is on main only. # 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-26904](https://issues.apache.org/jira/browse/CAMEL-26904). # 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 core modules and camel-kafka with the formatter and import-sort plugins and ran its unit tests. I did not run the full root build. The ITs, which need a Kafka container, were not run locally; CI runs them.) # 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]
