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

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


The following commit(s) were added to refs/heads/master by this push:
     new add071b  CAMEL-12348: camel-core - Potential NPE in 
ExchangeHelper.isStreamCaching
add071b is described below

commit add071b58447bcd5fb8a7abf91ed257a59fe693c
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Mon Mar 12 17:36:28 2018 +0100

    CAMEL-12348: camel-core - Potential NPE in ExchangeHelper.isStreamCaching
---
 .../src/main/java/org/apache/camel/impl/DefaultCamelContext.java  | 8 +++++---
 .../src/main/java/org/apache/camel/util/ExchangeHelper.java       | 8 +++++---
 .../src/test/java/org/apache/camel/util/ExchangeHelperTest.java   | 8 +++++++-
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git 
a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java 
b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index c54f7e4..daee1bf 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -899,9 +899,11 @@ public class DefaultCamelContext extends ServiceSupport 
implements ModelCamelCon
     }
 
     public Route getRoute(String id) {
-        for (Route route : getRoutes()) {
-            if (route.getId().equals(id)) {
-                return route;
+        if (id != null) {
+            for (Route route : getRoutes()) {
+                if (route.getId().equals(id)) {
+                    return route;
+                }
             }
         }
         return null;
diff --git a/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java 
b/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
index 672523e..f588af5 100644
--- a/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
@@ -40,6 +40,7 @@ import org.apache.camel.NoSuchEndpointException;
 import org.apache.camel.NoSuchHeaderException;
 import org.apache.camel.NoSuchPropertyException;
 import org.apache.camel.NoTypeConversionAvailableException;
+import org.apache.camel.Route;
 import org.apache.camel.TypeConversionException;
 import org.apache.camel.TypeConverter;
 import org.apache.camel.impl.DefaultExchange;
@@ -687,10 +688,11 @@ public final class ExchangeHelper {
      * @return <tt>true</tt> if enabled, <tt>false</tt> otherwise
      */
     public static boolean isStreamCachingEnabled(final Exchange exchange) {
-        if (exchange.getFromRouteId() == null) {
-            return 
exchange.getContext().getStreamCachingStrategy().isEnabled();
+        Route route = 
exchange.getContext().getRoute(exchange.getFromRouteId());
+        if (route != null) {
+            return route.getRouteContext().isStreamCaching();
         } else {
-            return 
exchange.getContext().getRoute(exchange.getFromRouteId()).getRouteContext().isStreamCaching();
+            return 
exchange.getContext().getStreamCachingStrategy().isEnabled();
         }
     }
 
diff --git 
a/camel-core/src/test/java/org/apache/camel/util/ExchangeHelperTest.java 
b/camel-core/src/test/java/org/apache/camel/util/ExchangeHelperTest.java
index 5a2d4d8..ab6ebfb 100644
--- a/camel-core/src/test/java/org/apache/camel/util/ExchangeHelperTest.java
+++ b/camel-core/src/test/java/org/apache/camel/util/ExchangeHelperTest.java
@@ -177,11 +177,17 @@ public class ExchangeHelperTest extends 
ContextTestSupport {
         assertEquals("text/xml", ExchangeHelper.getContentType(exchange));
     }
 
-    public void testGetContentEncpding() throws Exception {
+    public void testGetContentEncoding() throws Exception {
         exchange.getIn().setHeader(Exchange.CONTENT_ENCODING, "iso-8859-1");
         assertEquals("iso-8859-1", 
ExchangeHelper.getContentEncoding(exchange));
     }
 
+    public void testIsStreamCaching() throws Exception {
+        assertFalse(ExchangeHelper.isStreamCachingEnabled(exchange));
+        exchange.getContext().getStreamCachingStrategy().setEnabled(true);
+        assertTrue(ExchangeHelper.isStreamCachingEnabled(exchange));
+    }
+
     @Override
     protected void setUp() throws Exception {
         super.setUp();

-- 
To stop receiving notification emails like this one, please contact
davscl...@apache.org.

Reply via email to