oscerd opened a new pull request, #26521:
URL: https://github.com/apache/camel/pull/26521

   ## What this does
   
   Fixes a `NullPointerException` that occurs when a Kafka consumer is 
configured with `batching=true` but `maxPollRecords` is not explicitly set.
   
   ## Root cause
   
   `KafkaConfiguration.maxPollRecords` is an `Integer` field with **no 
initializer** (null by default). The `@UriParam(defaultValue = "500")` on it is 
only catalog/documentation metadata and is not applied to the field at runtime.
   
   - In **streaming** mode this is harmless: the value is pushed to Kafka via 
`addPropertyIfNotEmpty(..., MAX_POLL_RECORDS_CONFIG, getMaxPollRecords())`, 
which skips `null` and lets the Kafka client fall back to its own default of 
500.
   - In **batching** mode the value is read directly:
     - `KafkaRecordBatchingProcessor` constructor: `new 
ArrayBlockingQueue<>(configuration.getMaxPollRecords())` unboxes `null` → 
**NPE** at construction (first poll / reconnect).
     - `exchangeList.size() >= configuration.getMaxPollRecords()` would also 
NPE.
   
   So enabling the documented, supported `batching` feature out of the box 
crashes the consumer thread.
   
   ## Fix
   
   Initialize the field to `500` (matching the sibling `sessionTimeoutMs` / 
`pollTimeoutMs` fields), making the documented default real. Streaming 
behaviour is unchanged since Kafka's own default is also 500, and the 
`@UriParam` metadata is untouched so no catalog/DSL regeneration is required.
   
   ## Tests
   
   - `KafkaConfigurationTest#maxPollRecordsDefaultsTo500` — asserts the runtime 
default is 500.
   - 
`KafkaRecordBatchingProcessorCommonHeadersTest#processorConstructsWithDefaultMaxPollRecords`
 — reproduces the crash site (batching processor construction with a default 
configuration).
   
   The full `camel-kafka` module build (unit + integration tests) is green 
locally.
   
   JIRA: https://issues.apache.org/jira/browse/CAMEL-24778
   
   _Claude Code on behalf of @oscerd_
   
   🤖 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]

Reply via email to