Skip to content

About RecoverAnnotationRecoveryHandler's recover method #186

Open
@angelsinistanbul

Description

@angelsinistanbul

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions