camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dhira...@apache.org
Subject [07/35] git commit: Fixed array argument handling
Date Tue, 10 Jun 2014 19:51:35 GMT
Fixed array argument handling


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0932ed48
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0932ed48
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0932ed48

Branch: refs/heads/master
Commit: 0932ed48a947ae607b1d7572888531702dc8fb4e
Parents: 03f63df
Author: Dhiraj Bokde <dhirajsb@yahoo.com>
Authored: Wed May 28 14:18:17 2014 -0700
Committer: Dhiraj Bokde <dhirajsb@yahoo.com>
Committed: Tue Jun 10 12:48:30 2014 -0700

----------------------------------------------------------------------
 .../camel/util/component/ApiMethodHelper.java     | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/0932ed48/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodHelper.java
b/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodHelper.java
index 9f250f0..dbbc332 100644
--- a/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodHelper.java
@@ -128,7 +128,7 @@ public final class ApiMethodHelper<T extends Enum<T> & ApiMethod>
{
                 // also collect argument names for all methods, and detect clashes here
                 final Class<?> previousType = VALID_ARGUMENTS.get(argName);
                 if (previousType != null && previousType != argType) {
-                    throw new ExceptionInInitializerError(String.format(
+                    throw new IllegalArgumentException(String.format(
                         "Argument %s has ambiguous types (%s, %s) across methods!",
                         name, previousType, argType));
                 } else if (previousType == null) {
@@ -334,14 +334,16 @@ public final class ApiMethodHelper<T extends Enum<T> &
ApiMethod> {
                     }
                     value = array;
                 } else if (value.getClass().isArray()
-                    && type.getComponentType().isAssignableFrom(value.getClass().getComponentType()))
{
-                    // convert derived array to super array
-                    final int size = Array.getLength(value);
-                    Object array = Array.newInstance(type.getComponentType(), size);
-                    for (int i = 0; i < size; i++) {
-                        Array.set(array, i, Array.get(value, i));
+                        && type.getComponentType().isAssignableFrom(value.getClass().getComponentType()))
{
+                    // convert derived array to super array if needed
+                    if (type.getComponentType() != value.getClass().getComponentType()) {
+                        final int size = Array.getLength(value);
+                        Object array = Array.newInstance(type.getComponentType(), size);
+                        for (int i = 0; i < size; i++) {
+                            Array.set(array, i, Array.get(value, i));
+                        }
+                        value = array;
                     }
-                    value = array;
                 } else {
                     throw new IllegalArgumentException(
                         String.format("Cannot convert %s to %s", value.getClass(), type));


Mime
View raw message