Fix bug when there are multiple recover methods
...and a potential inheritance with argument types like List. Fixes #174
This commit is contained in:
committed by
Dave Syer
parent
c7174c9ee5
commit
0f9a918f3c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -42,6 +42,7 @@ import org.springframework.util.ReflectionUtils.MethodCallback;
|
||||
* @author Josh Long
|
||||
* @author Aldo Sinanaj
|
||||
* @author Randell Callahan
|
||||
* @author Nathanaël Roberts
|
||||
* @param <T> the type of the return value from the recovery
|
||||
*/
|
||||
public class RecoverAnnotationRecoveryHandler<T> implements MethodInvocationRecoverer<T> {
|
||||
@@ -130,7 +131,7 @@ public class RecoverAnnotationRecoveryHandler<T> implements MethodInvocationReco
|
||||
if (argument == null) {
|
||||
continue;
|
||||
}
|
||||
if (parameterTypes[i] != argument.getClass()) {
|
||||
if (!parameterTypes[i].isAssignableFrom(argument.getClass())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,11 +25,14 @@ import org.springframework.retry.ExhaustedRetryException;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Aldo Sinanaj
|
||||
* @author Randell Callahan
|
||||
* @author Nathanaël Roberts
|
||||
*/
|
||||
public class RecoverAnnotationRecoveryHandlerTests {
|
||||
|
||||
@@ -160,6 +163,16 @@ public class RecoverAnnotationRecoveryHandlerTests {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inheritanceOnArgumentClass() {
|
||||
Method foo = ReflectionUtils.findMethod(
|
||||
InheritanceOnArgumentClass.class, "foo", List.class);
|
||||
RecoverAnnotationRecoveryHandler<?> handler = new RecoverAnnotationRecoveryHandler<Integer>(
|
||||
new InheritanceOnArgumentClass(), foo);
|
||||
assertEquals(1, handler.recover(new Object[] { new ArrayList<String>() },
|
||||
new IllegalArgumentException("Planned")));
|
||||
}
|
||||
|
||||
private static class InAccessibleRecover {
|
||||
|
||||
@Retryable
|
||||
@@ -355,4 +368,23 @@ public class RecoverAnnotationRecoveryHandlerTests {
|
||||
|
||||
}
|
||||
|
||||
protected static class InheritanceOnArgumentClass {
|
||||
|
||||
@Retryable
|
||||
public int foo(List<String> list) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Recover
|
||||
public int fooRecover(Throwable t, List<String> list) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Recover
|
||||
public int barRecover(Throwable t, String name) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user