Skip to content

Commit

Permalink
Try to read method from current class
Browse files Browse the repository at this point in the history
gh-4983 fixed not being able to read methods from super class but it broke tracing tests
this commit tries to read method from current class but in case of method missing falls back to the default method

related to gh-4983
  • Loading branch information
marcingrzejszczak committed May 8, 2024
1 parent a9c08d8 commit 7c85c65
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public AnnotationHandler(BiConsumer<KeyValue, T> keyValueConsumer,
public void addAnnotatedParameters(T objectToModify, ProceedingJoinPoint pjp) {
try {
Method method = ((MethodSignature) pjp.getSignature()).getMethod();
method = tryToTakeMethodFromTargetClass(pjp, method);
List<AnnotatedParameter> annotatedParameters = AnnotationUtils.findAnnotatedParameters(annotationClass,
method, pjp.getArgs());
getAnnotationsFromInterfaces(pjp, method, annotatedParameters);
Expand All @@ -99,6 +100,16 @@ public void addAnnotatedParameters(T objectToModify, ProceedingJoinPoint pjp) {
}
}

private static Method tryToTakeMethodFromTargetClass(ProceedingJoinPoint pjp, Method method) {
try {
return pjp.getTarget().getClass().getDeclaredMethod(method.getName(), method.getParameterTypes());
}
catch (NoSuchMethodException ex) {
// matching method not found - will be taken from parent
}
return method;
}

private void getAnnotationsFromInterfaces(ProceedingJoinPoint pjp, Method mostSpecificMethod,
List<AnnotatedParameter> annotatedParameters) {
Class<?>[] implementedInterfaces = pjp.getThis().getClass().getInterfaces();
Expand Down

0 comments on commit 7c85c65

Please sign in to comment.