Fixed issue for multiple recovery methods creating an ArrayIndexOutOfBoundsException. Fixed #145
This commit is contained in:
@@ -117,7 +117,7 @@ public class RecoverAnnotationRecoveryHandler<T> implements MethodInvocationReco
|
||||
private boolean compareParameters(Object[] args, int argCount, Class<?>[] parameterTypes) {
|
||||
if (argCount == (args.length + 1)) {
|
||||
int startingIndex = 0;
|
||||
if (parameterTypes.length > 0 && parameterTypes[0] == Throwable.class) {
|
||||
if (parameterTypes.length > 0 && Throwable.class.isAssignableFrom(parameterTypes[0])) {
|
||||
startingIndex = 1;
|
||||
}
|
||||
for (int i = startingIndex; i < parameterTypes.length; i++) {
|
||||
|
||||
@@ -146,6 +146,19 @@ public class RecoverAnnotationRecoveryHandlerTests {
|
||||
handler.recover(new Object[] { "Randell" }, new RuntimeException("Planned")));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleQualifyingRecoverMethodsExtendsThrowable(){
|
||||
Method foo = ReflectionUtils.findMethod(MultipleQualifyingRecoversExtendsThrowable.class,
|
||||
"foo", String.class);
|
||||
RecoverAnnotationRecoveryHandler<?> handler = new RecoverAnnotationRecoveryHandler<Integer>(
|
||||
new MultipleQualifyingRecoversExtendsThrowable(), foo);
|
||||
assertEquals(2,
|
||||
handler.recover(new Object[] { "Kevin" }, new IllegalArgumentException("Planned")));
|
||||
assertEquals(3,
|
||||
handler.recover(new Object[] { "Kevin" }, new UnsupportedOperationException("Planned")));
|
||||
|
||||
}
|
||||
|
||||
private static class InAccessibleRecover {
|
||||
|
||||
@@ -310,5 +323,29 @@ public class RecoverAnnotationRecoveryHandlerTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static class MultipleQualifyingRecoversExtendsThrowable {
|
||||
|
||||
@Retryable
|
||||
public int foo(String name) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Recover
|
||||
public int fooRecover(IllegalArgumentException e, String name) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Recover
|
||||
public int barRecover(IllegalArgumentException e, String name) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Recover
|
||||
public int bazRecover(UnsupportedOperationException e, String name) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user