handle nulls and add a test
This commit is contained in:
@@ -16,6 +16,10 @@
|
||||
|
||||
package org.springframework.retry.annotation;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.classify.SubclassClassifier;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.retry.ExhaustedRetryException;
|
||||
@@ -23,10 +27,6 @@ import org.springframework.retry.interceptor.MethodInvocationRecoverer;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.ReflectionUtils.MethodCallback;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A recoverer for method invocations based on the <code>@Recover</code> annotation. A
|
||||
* suitable recovery method is one with a Throwable type as the first parameter and the
|
||||
@@ -121,7 +121,11 @@ public class RecoverAnnotationRecoveryHandler<T> implements MethodInvocationReco
|
||||
startingIndex = 1;
|
||||
}
|
||||
for (int i = startingIndex; i < parameterTypes.length; i++) {
|
||||
if (parameterTypes[i] != args[i-1].getClass()) {
|
||||
final Object argument = args[i-1];
|
||||
if (argument == null) {
|
||||
continue;
|
||||
}
|
||||
if (parameterTypes[i] != argument.getClass()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public class RecoverAnnotationRecoveryHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleQualifyingRecoverMethods (){
|
||||
public void multipleQualifyingRecoverMethods(){
|
||||
Method foo = ReflectionUtils.findMethod(MultipleQualifyingRecovers.class,
|
||||
"foo", String.class);
|
||||
RecoverAnnotationRecoveryHandler<?> handler = new RecoverAnnotationRecoveryHandler<Integer>(
|
||||
@@ -126,7 +126,18 @@ public class RecoverAnnotationRecoveryHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleQualifyingRecoverMethodsReOrdered (){
|
||||
public void multipleQualifyingRecoverMethodsWithNull(){
|
||||
Method foo = ReflectionUtils.findMethod(MultipleQualifyingRecovers.class,
|
||||
"foo", String.class);
|
||||
RecoverAnnotationRecoveryHandler<?> handler = new RecoverAnnotationRecoveryHandler<Integer>(
|
||||
new MultipleQualifyingRecovers(), foo);
|
||||
assertEquals(1,
|
||||
handler.recover(new Object[] { null }, new RuntimeException("Planned")));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleQualifyingRecoverMethodsReOrdered(){
|
||||
Method foo = ReflectionUtils.findMethod(MultipleQualifyingRecoversReOrdered.class,
|
||||
"foo", String.class);
|
||||
RecoverAnnotationRecoveryHandler<?> handler = new RecoverAnnotationRecoveryHandler<Integer>(
|
||||
|
||||
Reference in New Issue
Block a user