This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-4.8.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-4.8.x by this push:
     new 86b733b63b7 CAMEL-22364: camel-jms - Fix rare 
ConcurrentModificationException in camel-jms due to destination produced is set 
as header after sent, which can lead to a race condition when doing 
request/reply over JMS and reply is already received and continued processing. 
Thanks to Vladimir Dobos for the analysis. (#18996)
86b733b63b7 is described below

commit 86b733b63b7a1e9d4b786a2c35f5ffe4fb6b5ee1
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Aug 26 10:49:07 2025 +0200

    CAMEL-22364: camel-jms - Fix rare ConcurrentModificationException in 
camel-jms due to destination produced is set as header after sent, which can 
lead to a race condition when doing request/reply over JMS and reply is already 
received and continued processing. Thanks to Vladimir Dobos for the analysis. 
(#18996)
---
 .../apache/camel/component/jms/JmsProducer.java    | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git 
a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java
 
b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java
index 30952840cfe..8719520a1f0 100644
--- 
a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java
+++ 
b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java
@@ -218,7 +218,6 @@ public class JmsProducer extends DefaultAsyncProducer {
             in.setHeader(correlationPropertyToUse, 
GENERATED_CORRELATION_ID_PREFIX + getUuidGenerator().generateUuid());
         }
 
-        final String to = destinationName != null ? destinationName : 
getDestinationName(destination);
         MessageCreator messageCreator = new MessageCreator() {
             public Message createMessage(Session session) throws JMSException {
                 Message answer = 
endpoint.getBinding().makeJmsMessage(exchange, in, session, null);
@@ -254,12 +253,7 @@ public class JmsProducer extends DefaultAsyncProducer {
             }
         };
 
-        doSend(true, destinationName, destination, messageCreator, 
messageSentCallback);
-
-        // record where we sent the message
-        if (to != null) {
-            
exchange.getMessage().setHeader(JmsConstants.JMS_DESTINATION_NAME_PRODUCED, to);
-        }
+        doSend(exchange, true, destinationName, destination, messageCreator, 
messageSentCallback);
 
         // continue routing asynchronously (reply will be processed async when 
its received)
         return false;
@@ -396,14 +390,10 @@ public class JmsProducer extends DefaultAsyncProducer {
             }
         };
 
-        doSend(false, destinationName, destination, messageCreator, 
messageSentCallback);
+        doSend(exchange, false, destinationName, destination, messageCreator, 
messageSentCallback);
 
         // after sending then set the OUT message id to the JMSMessageID so 
its identical
         setMessageId(exchange);
-        // record where we sent the message
-        if (to != null) {
-            
exchange.getMessage().setHeader(JmsConstants.JMS_DESTINATION_NAME_PRODUCED, to);
-        }
 
         // we are synchronous so return true
         callback.done(true);
@@ -413,6 +403,7 @@ public class JmsProducer extends DefaultAsyncProducer {
     /**
      * Sends the message using the JmsTemplate.
      *
+     * @param exchange        the exchange
      * @param inOut           use inOut or inOnly template
      * @param destinationName the destination name
      * @param destination     the destination (if no name provided)
@@ -420,9 +411,16 @@ public class JmsProducer extends DefaultAsyncProducer {
      * @param callback        optional callback to invoke when message has 
been sent
      */
     protected void doSend(
+            Exchange exchange,
             boolean inOut, String destinationName, Destination destination,
             MessageCreator messageCreator, MessageSentCallback callback) {
 
+        // record where we sent the message
+        String to = destinationName != null ? destinationName : 
getDestinationName(destination);
+        if (to != null) {
+            
exchange.getMessage().setHeader(JmsConstants.JMS_DESTINATION_NAME_PRODUCED, to);
+        }
+
         CamelJmsTemplate template = (CamelJmsTemplate) (inOut ? 
getInOutTemplate() : getInOnlyTemplate());
 
         if (LOG.isTraceEnabled()) {

Reply via email to