allthingssecurity opened a new pull request, #29997: URL: https://github.com/apache/camel/pull/29997
# Description [CAMEL-26910](https://issues.apache.org/jira/browse/CAMEL-26910) The sibling of the `KafkaIdempotentRepository` fix for a record without a value (CAMEL-26904, #29895, merged), named in its description. `KafkaKeyValueRepository` (since 4.23) applies each record of its topic in `addToCache`. It skips a record without a value already, but: - a put or delete record without a key makes the cache throw a `NullPointerException`. The repository never writes one (`put` and `delete` use the cache, which refuses a null key, before they send); another application or a tool can; - a put whose value cannot be deserialized throws a `RuntimeCamelException` from `KeyValueRepositoryHelper.deserialize`: a class that is not on the classpath of this application (for example a value stored by another version of it), a class that the `deserializationFilter` does not allow, or bytes that are not a serialized object. Either way, 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. Change, in `KafkaKeyValueRepository.addToCache`: such a record is logged at WARN (with its topic, partition and offset, and the cause of a failed read on one line; the stack trace at DEBUG) and skipped, and the next records are applied. A clear (which has no key) is applied as before, and nothing changes for a record that this application can read. Only the `RuntimeCamelException` of `KeyValueRepositoryHelper.deserialize` is caught, so a malformed `deserializationFilter` pattern still fails as before (the start, or the poll, at the first put read from the topic). For a put whose value cannot be read, the cache keeps what it has for the key, as for a record without a value (and as the sibling does for a tombstone). The poller also reads back the puts of this repository: with a filter that does not allow the class of a stored value (by default only `java.*`, `javax.*` and `org.apache.camel.*` classes, and at most 10 MB and a depth of 20; for example a POJO body in the cache EIP, or a large aggregate), the value stays in the cache of the node that put it, as on main, where the next start then failed; now that start succeeds without those values, with a WARN per record, and the fix is to widen `deserializationFilter`, as the Serialization section of the page says. A put of another node whose value this node cannot read leaves the value this node had (the other persistent backends throw from `get` in that case; the Kafka repository reads at start and in the background, where there is no caller to throw to). The `=== Kafka` section of `key-value -repository.adoc` says so in one sentence. Not changed: a per-record catch in `KafkaChangelog` would cover both repositories and any other failure of a record handler; I kept the change in the repository, as for `KafkaIdempotentRepository`, so an unexpected failure of a handler is not hidden. Tests, in `KafkaKeyValueRepositoryTest` (no broker, the records applied through `addToCache` as the existing tests of the class do): - `putWithoutKeyIsSkippedAndTheNextRecordsAreApplied` and `deleteWithoutKeyIsSkippedAndTheNextRecordsAreApplied`: a put, or a delete, without a key leaves the cache as it was, and the next put is applied; - `putWhoseValueCannotBeReadIsSkipped`: a put of a key that is in the cache, whose value is cut after a few bytes: skipped, the key keeps its value, and the next put is applied; - `putWhoseValueTheDeserializationFilterRejectsIsSkipped`: with `deserializationFilter=java.lang.String;!*`, a put of an `Integer` is skipped, and the next put of a `String` is applied; - `ownPutWhoseValueTheDeserializationFilterRejectsKeepsItsValue`: the same filter, the repository puts an `Integer` and its record is read back: the value stays; - `clearWithoutKeyIsApplied`: a control, a clear still clears. Without the change the first five fail (the `NullPointerException` twice, and the `RuntimeCamelException` three times); the control passes. With it the camel-kafka unit tests pass (338 run, 0 failures, 1 skipped). The ITs need a Kafka container and were not run locally (CI runs them). No upgrade guide change (nothing worked before for these records). Main only: the class is also in 4.23.0, but the earlier fixes of this class (CAMEL-26740, CAMEL-26822) went to 4.24.0 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-26910](https://issues.apache.org/jira/browse/CAMEL-26910). # 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 camel-kafka and the core modules with the formatter and import-sort plugins and ran the camel-kafka unit tests. 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]
