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

Apply field predicate before searching type hierarchy #3533

Commits on Nov 4, 2023

  1. Apply field predicate before searching type hierarchy

    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 committed Nov 4, 2023
    Configuration menu
    Copy the full SHA
    e36637a View commit details
    Browse the repository at this point in the history