-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Duplicate BeanOverrideHandler
discovered in @Nested
test class hierarchy when upgrading to Spring 6.2.2
#34324
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
Comments
BeanOverrideHandler
discovered in @Nested
test class hierarchy when upgrading to Spring 6.2.2
What happens if you declare |
Similarly, what happens if you annotate your non-static nested base class with @NestedTestConfiguration(EnclosingConfiguration.OVERRIDE)
abstract class BaseClassForNestedTests {
// ...
} Alternatively, you should be able to annotate |
The change in behavior that you have reported is not related to #34204 but rather results from the changes made to |
This would work, however, in my real-world case I cannot make the base class static.
This fixes the error. |
Thanks for confirming that In light of that, I am closing this issue as "works as designed". Cheers, Sam |
Oh, I’m actually surprised to be honest and thought that this behavior change will be addressed. I think from a developer point of view it will be quite surprising and I’m sure that many developers will not know why the exception occurs and how to fix it (i.e. adding the |
Thanks for the feedback, @bwaldvogel. Although the current behavior (introduced in 6.2.2) may be considered technically correct in terms of the search algorithm, it is also technically a "regression" in behavior for test bean overrides, and as you mentioned, users may not find it readily apparent how an enclosing class can be visited twice by the search algorithm. In light of that, I am reopening this issue with the plan to not search in the enclosing class hierarchy of a supertype of a |
We stumbled across a circumstance for which the problem is still there. Do you want me to open a new issue or should we discuss it here ? |
@aykborstelmann, if you have discovered a bug that is still present in Spring Framework 6.2.6, please open a new issue with a reproducer. Thanks |
Alright, done in #34844. |
Prior to this commit, bean overrides (such as @MockitoBean, etc.) were discovered multiple times if they were declared: - at the type-level on an interface that is implemented at more than one level in the type hierarchy, the enclosing class hierarchy, or a combination of the type and enclosing class hierarchies. or - on a field declared in a class which can be reached multiple times while traversing the type and enclosing class hierarchies in scenarios such as the following: the class (X) in which the field is declared is a supertype of an enclosing type of the test class, and X is also an enclosing type of a supertype of the test class. Such scenarios resulted in an IllegalStateException stating that a duplicate BeanOverrideHandler was discovered. To address that, this commit revises the search algorithm in BeanOverrideHandler so that all types (superclasses, enclosing classes, and implemented interfaces) are only visited once while traversing the type and enclosing class hierarchies in search of bean override handlers. See gh-33925 See gh-34324 Closes gh-34844
Consider the following test with nested test classes:
When upgrading Spring Boot 3.4.1 to 3.4.2 (which upgrades Spring from 6.2.1 to 6.2.2), the test starts to fail with:
I tried to do a search to find if this issue was already reported. I found #34204 which could be related to this issue.
The text was updated successfully, but these errors were encountered: