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

Recursion comparison using properties ignores default interface methods. #3125

Closed
rpiterman opened this issue Jul 26, 2023 · 2 comments
Closed
Labels
theme: recursive comparison An issue related to the recursive comparison

Comments

@rpiterman
Copy link

If an Object has methods defined as default methods in an interface, these are not detected by the ComparingProperties() introspection strategy:

for example:

public interface Bar {
  default String getName() {
     return "bar";
  }
}

public class Foo implements Bar {
}

expected:

ComparingProperties should also detect properties defined in as default methods in interfaces implemented by the target object.

@amodolo
Copy link
Contributor

amodolo commented Aug 1, 2023

ComparingProperties collect the properties scanning the declared method for each class in the hierarchy.
In particular, the method gettersIncludingInheritedOf(Class) collect all the methods declared in the passed class object using the Class.getDeclaredMethods() API and iterate the process considering the superclass until the fundamental package java.lang.

In this way, this implementation takes into account only the properties inherited by the extension, and that's the reason why the default methods, declared in the interfaces, are ignored.

I think that collecting the properties using the getMethods API should be a better approach because:

  • it returns all public methods considering both superclasses and interfaces
  • there's no need to filter public methods
  • there's no need to iterate through the class hierarchy

I create a PR to let the AssertJ maintainers evaluate the fix proposal.

@joel-costigliola
Copy link
Member

Fixed by #3135

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: recursive comparison An issue related to the recursive comparison
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants