Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@MeterTag does not work on package private method #4506

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public AnnotationHandler(BiConsumer<KeyValue, T> keyValueConsumer,
public void addAnnotatedParameters(T objectToModify, ProceedingJoinPoint pjp) {
try {
Method method = ((MethodSignature) pjp.getSignature()).getMethod();
method = pjp.getTarget().getClass().getMethod(method.getName(), method.getParameterTypes());
method = pjp.getTarget().getClass().getDeclaredMethod(method.getName(), method.getParameterTypes());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to have broken existing support for methods that are only declared in the parent class, was it intended?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't think that was intended. Could you open an issue for it? I guess we're missing a test case to cover that scenario since we didn't notice it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done: #4983

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bpernetupgrade Ooops, no it wasn't intended and as @shakuzen says the lack of test coverage is at fault here.

Good found though, I'll see if I can provide a fix for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bpernetupgrade @shakuzen

Please take a look at #4985

List<AnnotatedParameter> annotatedParameters = AnnotationUtils.findAnnotatedParameters(annotationClass,
method, pjp.getArgs());
getAnnotationsFromInterfaces(pjp, method, annotatedParameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,23 @@ void meterTagsWithExpression(AnnotatedTestClass annotatedClass) {
assertThat(registry.get("method.timed").tag("test", "hello characters").timer().count()).isEqualTo(1);
}

@Test
void meterTagOnPackagePrivateMethod() {
MeterRegistry registry = new SimpleMeterRegistry();
TimedAspect timedAspect = new TimedAspect(registry);
timedAspect.setMeterTagAnnotationHandler(meterTagAnnotationHandler);

AspectJProxyFactory pf = new AspectJProxyFactory(new MeterTagClass());
pf.setProxyTargetClass(true);
pf.addAspect(timedAspect);

MeterTagClass service = pf.getProxy();

service.getAnnotationForPackagePrivateMethod("bar");

assertThat(registry.get("method.timed").tag("foo", "bar").timer().count()).isEqualTo(1);
}

enum AnnotatedTestClass {

CLASS_WITHOUT_INTERFACE(MeterTagClass.class), CLASS_WITH_INTERFACE(MeterTagClassChild.class);
Expand Down Expand Up @@ -492,6 +509,10 @@ public void getAnnotationForTagValueExpression(
public void getAnnotationForArgumentToString(@MeterTag("test") Long param) {
}

@Timed
void getAnnotationForPackagePrivateMethod(@MeterTag("foo") String foo) {
}

}

static class MeterTagClassChild implements MeterTagClassInterface {
Expand Down