This is an automated email from the ASF dual-hosted git repository.
oscerd pushed a commit to branch camel-4.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.18.x by this push:
new 33017fcd6686 [backport camel-4.18.x] CAMEL-24778: camel-kafka - fix
NullPointerException in batching consumer when maxPollRecords is not set
(#26658)
33017fcd6686 is described below
commit 33017fcd6686850b33d0e49822866d07c1dfb2d4
Author: Andrea Cosentino <[email protected]>
AuthorDate: Mon Sep 21 13:28:52 2026 +0200
[backport camel-4.18.x] CAMEL-24778: camel-kafka - fix NullPointerException
in batching consumer when maxPollRecords is not set (#26658)
CAMEL-24778: camel-kafka - fix NullPointerException in batching consumer
when maxPollRecords is not set
Backport of #26521 to camel-4.18.x (the backport bot could not auto-port
it: cherry-pick
conflict because KafkaRecordBatchingProcessorCommonHeadersTest, where the
regression test lives
on main, does not exist on this branch).
The maxPollRecords field had no initializer, so it was null at runtime
while @UriParam(defaultValue
= "500") only documented the default. In batching mode the value is read
directly to size the batch
buffer, throwing NullPointerException. Initialize the field to 500
(streaming behaviour is unchanged
since Kafka's own default is also 500). The regression test is provided as
a dedicated
KafkaRecordBatchingProcessorTest since the original test file is not
present on this branch.
Signed-off-by: Andrea Cosentino <[email protected]>
Co-authored-by: Claude Opus 4.8 <[email protected]>
---
.../camel/component/kafka/KafkaConfiguration.java | 2 +-
.../batching/KafkaRecordBatchingProcessorTest.java | 33 ++++++++++++++++++++++
2 files changed, 34 insertions(+), 1 deletion(-)
diff --git
a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaConfiguration.java
b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaConfiguration.java
index 080c286c8225..51fedf7dc615 100755
---
a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaConfiguration.java
+++
b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaConfiguration.java
@@ -117,7 +117,7 @@ public class KafkaConfiguration implements Cloneable,
HeaderFilterStrategyAware
@UriParam(label = "consumer", defaultValue = "45000")
private Integer sessionTimeoutMs = 45000;
@UriParam(label = "consumer", defaultValue = "500")
- private Integer maxPollRecords;
+ private Integer maxPollRecords = 500;
@UriParam(label = "consumer", defaultValue = "5000", javaType =
"java.time.Duration")
private Long pollTimeoutMs = 5000L;
@UriParam(label = "consumer", javaType = "java.time.Duration")
diff --git
a/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/consumer/support/batching/KafkaRecordBatchingProcessorTest.java
b/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/consumer/support/batching/KafkaRecordBatchingProcessorTest.java
new file mode 100644
index 000000000000..0c09e86eb185
--- /dev/null
+++
b/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/consumer/support/batching/KafkaRecordBatchingProcessorTest.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.kafka.consumer.support.batching;
+
+import org.apache.camel.component.kafka.KafkaConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+
+class KafkaRecordBatchingProcessorTest {
+
+ @Test
+ void processorConstructsWithDefaultMaxPollRecords() {
+ // CAMEL-24778: with maxPollRecords left unset, the batch buffer was
sized from a null Integer,
+ // throwing NullPointerException as the processor was constructed. The
constructor only reads the
+ // configuration, so the processor and commit manager are irrelevant
to this regression.
+ assertDoesNotThrow(() -> new KafkaRecordBatchingProcessor(new
KafkaConfiguration(), null, null));
+ }
+}