This is an automated email from the ASF dual-hosted git repository.
davsclaus 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 46126983ca83 CAMEL-23061: camel-sql - Fix NPE in sql consumer if
exchange factory statistics is enabled.
46126983ca83 is described below
commit 46126983ca8318da0ce5cdba09a5d7486db2fd1e
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Feb 23 18:52:49 2026 +0100
CAMEL-23061: camel-sql - Fix NPE in sql consumer if exchange factory
statistics is enabled.
---
.../src/main/java/org/apache/camel/component/sql/SqlConsumer.java | 7 ++-----
.../test/java/org/apache/camel/component/sql/SqlConsumerTest.java | 2 ++
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git
a/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlConsumer.java
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlConsumer.java
index 1ae2d6ecbce0..2a5c732dc4f3 100644
---
a/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlConsumer.java
+++
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlConsumer.java
@@ -30,7 +30,6 @@ import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.RollbackExchangeException;
import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.spi.ExchangeFactory;
import org.apache.camel.support.ResourceHelper;
import org.apache.camel.support.ScheduledBatchPollingConsumer;
import org.apache.camel.util.CastUtils;
@@ -51,7 +50,6 @@ public class SqlConsumer extends
ScheduledBatchPollingConsumer {
private final String query;
private String resolvedQuery;
- private final ExchangeFactory exchangeFactory;
private final JdbcTemplate jdbcTemplate;
private final NamedParameterJdbcTemplate namedJdbcTemplate;
private final SqlParameterSource parameterSource;
@@ -86,7 +84,6 @@ public class SqlConsumer extends
ScheduledBatchPollingConsumer {
this.parameterSource = null;
this.sqlPrepareStatementStrategy = sqlPrepareStatementStrategy;
this.sqlProcessingStrategy = sqlProcessingStrategy;
- this.exchangeFactory =
endpoint.getCamelContext().getCamelContextExtension().getExchangeFactory();
}
public SqlConsumer(DefaultSqlEndpoint endpoint, Processor processor,
NamedParameterJdbcTemplate namedJdbcTemplate,
@@ -99,7 +96,6 @@ public class SqlConsumer extends
ScheduledBatchPollingConsumer {
this.parameterSource = parameterSource;
this.sqlPrepareStatementStrategy = sqlPrepareStatementStrategy;
this.sqlProcessingStrategy = sqlProcessingStrategy;
- this.exchangeFactory =
endpoint.getCamelContext().getCamelContextExtension().getExchangeFactory();
}
@Override
@@ -133,7 +129,7 @@ public class SqlConsumer extends
ScheduledBatchPollingConsumer {
shutdownRunningTask = null;
pendingExchanges = 0;
- final Exchange dummy = exchangeFactory.create(getEndpoint(), true);
+ final Exchange dummy = createExchange(false);
final String preparedQuery
= sqlPrepareStatementStrategy.prepareQuery(resolvedQuery,
getEndpoint().isAllowNamedParameters(), dummy);
@@ -184,6 +180,7 @@ public class SqlConsumer extends
ScheduledBatchPollingConsumer {
if (closeEager) {
closeResultSet(rs);
}
+ releaseExchange(dummy, false);
}
// okay we have some response from SQL so lets mark the
consumer as ready
diff --git
a/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlConsumerTest.java
b/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlConsumerTest.java
index 99bc82e13817..2525d8372a11 100644
---
a/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlConsumerTest.java
+++
b/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlConsumerTest.java
@@ -79,6 +79,8 @@ public class SqlConsumerTest extends CamelTestSupport {
return new RouteBuilder() {
@Override
public void configure() {
+
getContext().getCamelContextExtension().getExchangeFactory().setStatisticsEnabled(true);
+
getContext().getComponent("sql",
SqlComponent.class).setDataSource(db);
from("sql:select * from projects order by
id?initialDelay=0&delay=50")