diff --git a/src/main/java/org/springframework/retry/annotation/RecoverAnnotationRecoveryHandler.java b/src/main/java/org/springframework/retry/annotation/RecoverAnnotationRecoveryHandler.java index afab81d..176739a 100644 --- a/src/main/java/org/springframework/retry/annotation/RecoverAnnotationRecoveryHandler.java +++ b/src/main/java/org/springframework/retry/annotation/RecoverAnnotationRecoveryHandler.java @@ -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 the type of the return value from the recovery */ public class RecoverAnnotationRecoveryHandler implements MethodInvocationRecoverer { @@ -130,7 +131,7 @@ public class RecoverAnnotationRecoveryHandler implements MethodInvocationReco if (argument == null) { continue; } - if (parameterTypes[i] != argument.getClass()) { + if (!parameterTypes[i].isAssignableFrom(argument.getClass())) { return false; } } diff --git a/src/test/java/org/springframework/retry/annotation/RecoverAnnotationRecoveryHandlerTests.java b/src/test/java/org/springframework/retry/annotation/RecoverAnnotationRecoveryHandlerTests.java index e13d707..2c9f5f3 100644 --- a/src/test/java/org/springframework/retry/annotation/RecoverAnnotationRecoveryHandlerTests.java +++ b/src/test/java/org/springframework/retry/annotation/RecoverAnnotationRecoveryHandlerTests.java @@ -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( + new InheritanceOnArgumentClass(), foo); + assertEquals(1, handler.recover(new Object[] { new ArrayList() }, + new IllegalArgumentException("Planned"))); + } + private static class InAccessibleRecover { @Retryable @@ -355,4 +368,23 @@ public class RecoverAnnotationRecoveryHandlerTests { } + protected static class InheritanceOnArgumentClass { + + @Retryable + public int foo(List list) { + return 0; + } + + @Recover + public int fooRecover(Throwable t, List list) { + return 1; + } + + @Recover + public int barRecover(Throwable t, String name) { + return 2; + } + + } + }