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

GH-2456: Suppress Duplicate Annotations with Spy #2457

Merged
merged 1 commit into from
May 22, 2023

Conversation

garyrussell
Copy link
Contributor

Resolves #2456

When spying a @RabbitListener bean, duplicate methods are resolved as well as duplicate class level @RabbitListener annotations.

cherry-pick to 2.4.x (will require instanceof polishing for Java 8)

Resolves spring-projects#2456

When spying a `@RabbitListener` bean, duplicate methods are resolved as well
as duplicate class level `@RabbitListener` annotations.

**cherry-pick to 2.4.x** (will require instanceof polishing for Java 8)
@artembilan
Copy link
Member

@garyrussell ,

does this confirm that premise of the spy() works even if we skip those Mockito generated methods from candidates?
How does those verify() then pass?

Thanks

@garyrussell
Copy link
Contributor Author

Yes, that's why I added the verify() to ensure the spy still works as expected.

I couldn't detect any difference at runtime - the mock method is still in the stack trace (set a breakpoint in MultiListenerBean.bar() and you will see it.

This doesn't actually make any difference to the spy, it just avoids us finding both sets of annotations which causes duplicate containers/methods.

@artembilan
Copy link
Member

... and cherry-picked to 2.4.x after fixing instanceof pattern.

@garyrussell garyrussell deleted the GH-2456 branch May 25, 2023 14:31
@@ -339,7 +339,8 @@ private TypeMetadata buildMetadata(Class<?> targetClass) {
multiMethods.add(method);
}
}
}, ReflectionUtils.USER_DECLARED_METHODS);
}, ReflectionUtils.USER_DECLARED_METHODS
.and(meth -> !meth.getDeclaringClass().getName().contains("$MockitoMock$")));
Copy link

Choose a reason for hiding this comment

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

cherry-picked to 2.4.x breaks compatibility with Spring Framework 5.2, USER_DECLARED_METHODS comes with a and method only after 5.3.2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Spring Framework 5.2.x is no longer supported as OSS and goes out of commercial support at the end of the year.

https://spring.io/projects/spring-framework#support

However, 2.4.x has always used Spring Framework 5.3.x; it has never supported being run on 5.2.x. Here is the version on the v2.4.0 tag:

springVersion = project.hasProperty('springVersion') ? project.springVersion : '5.3.13'

It currently requires 5.3.30.

Copy link

Choose a reason for hiding this comment

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

But the reference said it works with 5.2.x.
And in fact, everything else looks good with 5.2.x

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a bug in the documentation but, in any case, as I said 5.2.x is out of support anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made an exception and made the change dcc49ba

The next release is mid-October.

But I still recommend that you move to a supported version of Spring Framework.

Copy link

Choose a reason for hiding this comment

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

Thank you! I'd like to upgrade, but it's out of my control.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AmqpException when testing @RabbitListener with @RabbitHandler
3 participants