[camel] branch camel-2.24.x updated: [CAMEL-14156] Avoid NPE with endpoint is null in JmsBinding (#3328)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[camel] branch camel-2.24.x updated: [CAMEL-14156] Avoid NPE with endpoint is null in JmsBinding (#3328)

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

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


The following commit(s) were added to refs/heads/camel-2.24.x by this push:
     new 0d32cdd  [CAMEL-14156] Avoid NPE with endpoint is null in JmsBinding (#3328)
0d32cdd is described below

commit 0d32cdd815fdcd5a09eb8f967fd1815be4937dee
Author: Jean-Baptiste Onofré <[hidden email]>
AuthorDate: Fri Nov 8 22:14:12 2019 +0100

    [CAMEL-14156] Avoid NPE with endpoint is null in JmsBinding (#3328)
---
 .../java/org/apache/camel/component/jms/JmsBinding.java   |  2 +-
 .../org/apache/camel/component/jms/JmsBindingTest.java    | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java
index 2d080f4..9e13928 100644
--- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java
+++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java
@@ -376,7 +376,7 @@ public class JmsBinding {
     public void appendJmsProperty(Message jmsMessage, Exchange exchange, org.apache.camel.Message in,
                                   String headerName, Object headerValue) throws JMSException {
         if (isStandardJMSHeader(headerName)) {
-            if (headerName.equals("JMSCorrelationID") && !endpoint.isUseMessageIDAsCorrelationID()) {
+            if (headerName.equals("JMSCorrelationID") && (endpoint == null || !endpoint.isUseMessageIDAsCorrelationID())) {
                 jmsMessage.setJMSCorrelationID(ExchangeHelper.convertToType(exchange, String.class, headerValue));
             } else if (headerName.equals("JMSReplyTo") && headerValue != null) {
                 if (headerValue instanceof String) {
diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsBindingTest.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsBindingTest.java
index 4efeb3f..a109bda 100644
--- a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsBindingTest.java
+++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsBindingTest.java
@@ -22,6 +22,9 @@ import java.time.Instant;
 import java.util.Date;
 
 import org.apache.activemq.command.ActiveMQBlobMessage;
+import org.apache.activemq.command.ActiveMQTextMessage;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultExchange;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -54,6 +57,18 @@ public class JmsBindingTest {
     }
 
     @Test
+    public void noEndpointTest() throws Exception {
+        JmsBinding testBindingWithoutEndpoint = new JmsBinding();
+        ActiveMQTextMessage message = new ActiveMQTextMessage();
+        message.setText("test");
+        DefaultCamelContext camelContext = new DefaultCamelContext();
+        DefaultExchange exchange = new DefaultExchange(camelContext);
+        exchange.getIn().setBody("test");
+        exchange.getIn().setHeader("JMSCorrelationID", null);
+        testBindingWithoutEndpoint.appendJmsProperties(message, exchange);
+    }
+
+    @Test
     public void testExtractNullBodyFromJmsShouldReturnNull() throws Exception {
         assertNull(jmsBindingUnderTest.extractBodyFromJms(null, new ActiveMQBlobMessage()));
     }