-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Apply field predicate before searching type hierarchy #3533
Closed
sbrannen
wants to merge
1
commit into
junit-team:main
from
sbrannen:issues/3532-apply-field-predicate-before-searching-hierarchy
Closed
Apply field predicate before searching type hierarchy #3533
sbrannen
wants to merge
1
commit into
junit-team:main
from
sbrannen:issues/3532-apply-field-predicate-before-searching-hierarchy
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Closed
1 task
Closed
1 task
sbrannen
force-pushed
the
issues/3532-apply-field-predicate-before-searching-hierarchy
branch
2 times, most recently
from
November 4, 2023 11:54
b088d99
to
7c30fd3
Compare
Prior to this commit, findFields() and streamFields() in ReflectionSupport as well as findAnnotatedFields() and findAnnotatedFieldValues() in AnnotationSupport first searched for all fields in the type hierarchy and then applied the user-supplied predicate (or "is annotated?" predicate) afterwards. This resulted in fields in subclasses incorrectly "shadowing" package-private fields in superclasses (in a different package) even if the predicate would otherwise exclude the field in such a subclass. For example, given a superclass that declares a package-private static @TempDir "tempDir" field and a subclass (in a different package) that declares a @TempDir "tempDir" field, when JUnit Jupiter looked up @TempDir fields for the subclass, the @TempDir "tempDir" field in the superclass was not found because the @TempDir "tempDir" field shadowed it based solely on the field signature, ignoring the type of annotation sought. To address that, this commit modifies the internal search algorithms in ReflectionUtils so that field predicates are applied while searching the hierarchy for fields. See junit-team#3498 Closes junit-team#3532 Closes junit-team#3533
sbrannen
force-pushed
the
issues/3532-apply-field-predicate-before-searching-hierarchy
branch
from
November 4, 2023 12:06
7c30fd3
to
e36637a
Compare
sbrannen
added a commit
that referenced
this pull request
Nov 4, 2023
Prior to this commit, findFields() and streamFields() in ReflectionSupport as well as findAnnotatedFields() and findAnnotatedFieldValues() in AnnotationSupport first searched for all fields in the type hierarchy and then applied the user-supplied predicate (or "is annotated?" predicate) afterwards. This resulted in fields in subclasses incorrectly "shadowing" package-private fields in superclasses (in a different package) even if the predicate would otherwise exclude the field in such a subclass. For example, given a superclass that declares a package-private static @TempDir "tempDir" field and a subclass (in a different package) that declares a @TempDir "tempDir" field, when JUnit Jupiter looked up @TempDir fields for the subclass, the @TempDir "tempDir" field in the superclass was not found because the @TempDir "tempDir" field shadowed it based solely on the field signature, ignoring the type of annotation sought. To address that, this commit modifies the internal search algorithms in ReflectionUtils so that field predicates are applied while searching the hierarchy for fields. See #3498 Closes #3532 Closes #3533 (cherry picked from commit f30a8d5)
marcphilipp
reviewed
Nov 4, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR includes a fix for #3532 with two simple test classes that demonstrate the issue.
Related Issues
@BeforeAll
method in super class skipped when it has same name as a@BeforeEach
method in subclass #3498@TempDir
field in super class skipped when it has same name as a@TempDir
field in subclass #3532Deliverables
ReflectionUtilsTests
andAnnotationUtilsTests