Skip to content

TraceSessionRepositoryAspect#callMethodOnWrappedObject does not handle InvocationTargetException #2246

@ghost

Description

Describe the bug
I am using spring-cloud-sleuth-instrumentation-3.1.5.jar in combination with spring-aop-5.3.24.jar

The method callMethodOnWrappedObject(ProceedingJoinPoint pjp, T target) invokes a method to access a sessionRepository.
But it doesn't handle the case properly, when the invoked method throws a RuntimeException or another declared Exception.

The result of this bug is, that a org.springframework.web.reactive.handler.WebFluxResponseStatusExceptionHandler and perhaps other places also see a java.lang.reflect.UndeclaredThrowableException instead of the actually thrown exception.
The UndeclaredThrowableException is created in https://github.com/spring-projects/spring-framework/blob/46875c91ced9387a598c3ca7eba3ed23fdb4fc63/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java#L769
because the called sessionRepository method doesn't declare to throw an InvocationTargetException (which is correct).

Current implementation:

Suggested implementation:

try {
  return method.invoke(target, pjp.getArgs());
} catch(InvocationTargetException ex) {
  throw ex.getCause();
}

similar to https://github.com/spring-projects/spring-framework/blob/46875c91ced9387a598c3ca7eba3ed23fdb4fc63/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java#L640
or you use org.springframework.util.ReflectionUtils.invokeMethod.

I found a similar issue #1092. Maybe there are more like this.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions