handle nulls and add a test

This commit is contained in:
Piszmog
2018-08-14 19:20:58 -06:00
committed by Dave Syer
parent f769c6de9a
commit 540787cc99
2 changed files with 22 additions and 7 deletions

View File

@@ -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;
}
}

View File

@@ -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>(