BATCH-1605: fix loop that looks for matching argumemts
This commit is contained in:
@@ -54,11 +54,11 @@ public class HippyMethodInvoker extends MethodInvoker {
|
||||
for (int j = 0; j < arguments.length; j++) {
|
||||
for (int k = 0; k < paramTypes.length; k++) {
|
||||
// Pick the first assignable of the right type that
|
||||
// matches this slot...
|
||||
if (ClassUtils.isAssignableValue(paramTypes[k], arguments[j])
|
||||
&& candidateArguments[k] == null) {
|
||||
// matches this slot and hasn't already been filled...
|
||||
if (ClassUtils.isAssignableValue(paramTypes[k], arguments[j]) && candidateArguments[k] == null) {
|
||||
candidateArguments[k] = arguments[j];
|
||||
assignedParameterCount++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,9 +73,9 @@ public class HippyMethodInvoker extends MethodInvoker {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (transformedArguments==null) {
|
||||
throw new IllegalArgumentException("No matching arguments found for method: "+targetMethod);
|
||||
|
||||
if (transformedArguments == null) {
|
||||
throw new IllegalArgumentException("No matching arguments found for method: " + targetMethod);
|
||||
}
|
||||
|
||||
if (transformedArgumentCount < transformedArguments.length) {
|
||||
|
||||
@@ -39,6 +39,16 @@ public class HippyMethodInvokerTests {
|
||||
assertEquals("2.0.foo", adapter.getMessage(2, "foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTwoArgsOfSameTypeWithInexactMatch() throws Exception {
|
||||
HippyMethodInvoker invoker = new HippyMethodInvoker();
|
||||
invoker.setTargetMethod("duplicate");
|
||||
invoker.setTargetObject(new PlainPojo());
|
||||
invoker.setArguments(new Object[] {"2", "foo"});
|
||||
invoker.prepare();
|
||||
assertEquals("foo.2", invoker.invoke());
|
||||
}
|
||||
|
||||
public static class PlainPojo {
|
||||
public String handle(double value, String input) {
|
||||
return value+"."+input;
|
||||
@@ -46,6 +56,9 @@ public class HippyMethodInvokerTests {
|
||||
public String disorder(String input, double value) {
|
||||
return value+"."+input;
|
||||
}
|
||||
public String duplicate(String input, Object value) {
|
||||
return value+"."+input;
|
||||
}
|
||||
public String missing(String input) {
|
||||
return input+"."+input;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user