-
Notifications
You must be signed in to change notification settings - Fork 38.2k
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
Deprecate "enclosing classes" search strategy for MergedAnnotations #28079
Comments
@sbrannen We use this strategy in Spring Boot to find |
Hi @philwebb, I saw that you once used it in Boot's Where is |
We don't on |
Thanks for the link and explanation, @snicoll. If the search strategy is only used for |
I think so, yes. Our policy is to not rely on deprecated code unless absolutely necessary. Getting in this situation for the whole duration of the While I have the opportunity, I disagree with the opening statements. It may have been introduced for a very specific use case but once it becomes public API, we can't really argue that this is the only use. It sounds like an addition in TestContextAnnotationUtils is fixing the problem. It doesn't, at least for us. |
For the Instead, we will add notes to the documentation to increase awareness of how the search strategy behaves. In addition, we will reconsider deprecation/removal of the search strategy in |
…ations" This reverts commit 5689395. See spring-projectsgh-28079
Team Decision: we have decided to deprecate the |
This commit adds a warning to the Javadoc for the TYPE_HIERARCHY_AND_ENCLOSING_CLASSES search strategy in MergedAnnotations with regard to the scope of the search algorithm. See spring-projectsgh-28079
Due to the deprecation of the TYPE_HIERARCHY_AND_ENCLOSING_CLASSES search strategy (see spring-projectsgh-28079), this commit introduces a way for users to provide a Predicate<Class<?>> that is used to decide when the enclosing class for the class supplied to the predicate should be searched. This gives the user complete control over the "enclosing classes" aspect of the search algorithm in MergedAnnotations. - To achieve the same behavior as TYPE_HIERARCHY_AND_ENCLOSING_CLASSES, a user can provide `clazz -> true` as the predicate. - To limit the enclosing class search to inner classes, a user can provide `ClassUtils::isInnerClass` as the predicate. - To limit the enclosing class search to static nested classes, a user can provide `ClassUtils::isStaticClass` as the predicate. - For more advanced use cases, the user can provide a custom predicate. For example, the following performs a search on MyInnerClass within the entire type hierarchy and enclosing class hierarchy of that class. MergedAnnotations mergedAnnotations = MergedAnnotations.search(TYPE_HIERARCHY) .withEnclosingClasses(ClassUtils::isInnerClass) .from(MyInnerClass.class); In addition, TestContextAnnotationUtils in spring-test has been revised to use this new feature where feasible. Closes spring-projectsgh-28207
Overview
The
TYPE_HIERARCHY_AND_ENCLOSING_CLASSES
search strategy forMergedAnnotations
was originally introduced to support@Nested
test classes in JUnit Jupiter.However, while implementing #19930, we determined that the
TYPE_HIERARCHY_AND_ENCLOSING_CLASSES
search strategy unfortunately could not be used since it does not allow the user to control when to recurse up the enclosing class hierarchy. For example, this search strategy will automatically search on enclosing classes for static nested classes as well as for inner classes, when the user probably only wants one such category of "enclosing class" to be searched. Consequently,TestContextAnnotationUtils
was introduced in the Spring TestContext Framework to address the shortcomings of theTYPE_HIERARCHY_AND_ENCLOSING_CLASSES
search strategy.Since this search strategy is unlikely to be useful to general users, the team should consider deprecating this search strategy in Spring Framework 6.0.
Related Issues
The text was updated successfully, but these errors were encountered: