spring-retry icon indicating copy to clipboard operation
spring-retry copied to clipboard

About RecoverAnnotationRecoveryHandler's recover method

Open angelsinistanbul opened this issue 6 years ago • 1 comments

Hello,

If you use more than exceptions to catch it by divided recover methods , you should change the method. Because, i have debugged the code, the "recover" method's cause always gives us "Throwable.class". Thus, I changed the code by using commons lib,

Throwable rootCause = ExceptionUtils.getRootCause(cause);

to get cause..

You should change the code by doing this if you want.

 public T recover(Object[] args, Throwable cause) {
        Method method = findClosestMatch(args, ExceptionUtils.getRootCause(cause).getClass());
        if (method == null) {
            throw new ExhaustedRetryException("Cannot locate recovery method", cause);
        }
        SimpleMetadata meta = (SimpleMetadata) this.methods.get(method);
        Object[] argsToUse = meta.getArgs(cause, args);
        boolean methodAccessible = method.isAccessible();
        try {
            ReflectionUtils.makeAccessible(method);

            T result = (T) ReflectionUtils.invokeMethod(method, this.target, argsToUse);
            return result;
        } finally {

            if (methodAccessible != method.isAccessible()) {
                method.setAccessible(methodAccessible);
            }
        }
    }

angelsinistanbul avatar Oct 31 '19 20:10 angelsinistanbul

Sorry, I'm not sure what code you are talking about. Would you like to propose a change in a pull request? Or be a bit more specific about where the snippets above come from or apply to?

dsyer avatar Jan 20 '20 11:01 dsyer