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

commit 1eb0135922a485cec0aee34c77f1486dc2539a62
Author: Federico Valeri <fvaleri@localhost>
AuthorDate: Thu Jul 4 14:34:17 2019 +0200

    Fix NPE at component.bean.MethodInfo.invoke
---
 .../org/apache/camel/component/bean/MethodInfo.java   |  5 +++--
 .../java/org/apache/camel/util/ObjectHelperTest.java  | 19 +++++++++++++++++++
 .../main/java/org/apache/camel/util/ObjectHelper.java | 11 +++++++++++
 3 files changed, 33 insertions(+), 2 deletions(-)

diff --git 
a/components/camel-bean/src/main/java/org/apache/camel/component/bean/MethodInfo.java
 
b/components/camel-bean/src/main/java/org/apache/camel/component/bean/MethodInfo.java
index 8296fe9..0021e00 100644
--- 
a/components/camel-bean/src/main/java/org/apache/camel/component/bean/MethodInfo.java
+++ 
b/components/camel-bean/src/main/java/org/apache/camel/component/bean/MethodInfo.java
@@ -56,6 +56,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import static org.apache.camel.util.ObjectHelper.asString;
+import static org.apache.camel.util.ObjectHelper.asList;
 
 /**
  * Information about a method to be used for invocation.
@@ -438,9 +439,9 @@ public class MethodInfo {
         try {
             return ObjectHelper.invokeMethodSafe(mth, pojo, arguments);
         } catch (IllegalAccessException e) {
-            throw new RuntimeExchangeException("IllegalAccessException 
occurred invoking method: " + mth + " using arguments: " + 
Arrays.asList(arguments), exchange, e);
+            throw new RuntimeExchangeException("IllegalAccessException 
occurred invoking method: " + mth + " using arguments: " + asList(arguments), 
exchange, e);
         } catch (IllegalArgumentException e) {
-            throw new RuntimeExchangeException("IllegalArgumentException 
occurred invoking method: " + mth + " using arguments: " + 
Arrays.asList(arguments), exchange, e);
+            throw new RuntimeExchangeException("IllegalArgumentException 
occurred invoking method: " + mth + " using arguments: " + asList(arguments), 
exchange, e);
         }
     }
 
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java 
b/core/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java
index 2af07fc..5228614 100644
--- a/core/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java
@@ -956,4 +956,23 @@ public class ObjectHelperTest extends Assert {
         Method m2 = InterfaceSize.class.getMethod("size");
         
assertFalse(org.apache.camel.util.ObjectHelper.isOverridingMethod(InterfaceSize.class,
 m2, m1, false));
     }
+    
+    @Test
+    public void testAsList() {
+        List<Object> out0 = ObjectHelper.asList(null);
+        assertNotNull(out0);
+        assertTrue(out0 instanceof List && out0.size() == 0);
+
+        List<Object> out1 = ObjectHelper.asList(new Object[0]);
+        assertNotNull(out1);
+        assertTrue(out1 instanceof List && out1.size() == 0);
+
+        String[] args = new String[] {"foo", "bar"};
+        List<Object> out2 = ObjectHelper.asList(args);
+        assertNotNull(out2);
+        assertTrue(out2 instanceof List && out2.size() == 2);
+        assertEquals("foo", out2.get(0));
+        assertEquals("bar", out2.get(1));
+    }
+
 }
diff --git 
a/core/camel-util/src/main/java/org/apache/camel/util/ObjectHelper.java 
b/core/camel-util/src/main/java/org/apache/camel/util/ObjectHelper.java
index 7f97767..317c066 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/ObjectHelper.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/ObjectHelper.java
@@ -1166,4 +1166,15 @@ public final class ObjectHelper {
             return new RuntimeException(e);
         }
     }
+
+    /**
+     * Turns the input array to a list of objects.
+     * 
+     * @param args an array of objects or null
+     * @return an object list
+     */
+    public static List<Object> asList(Object[] objects) {
+        return objects != null ? Arrays.asList(objects) : 
Collections.emptyList();
+    }
+    
 }

Reply via email to