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

recursive datastructures where recursive field is ignored #155

Closed
chisui opened this issue Sep 23, 2016 · 1 comment
Closed

recursive datastructures where recursive field is ignored #155

chisui opened this issue Sep 23, 2016 · 1 comment

Comments

@chisui
Copy link

chisui commented Sep 23, 2016

What steps will reproduce the problem?

The EqualsVerifier expects prefab values for recursive datastructures even when the recursive fields are ignored.

What is the code that triggers this problem?

class A {
    A a;
    String b;

    @Override public boolean equals(Object obj) { ... }
    @Override public int hashCode() { ... }
}

EqualsVerifier.forClass(A.class)
        .withIgnoredFields("a")
        .verify();

The actual implementations of equals(Object) and hashCode() are irrelevant.

What error message or stack trace does EqualsVerifier give?

java.lang.AssertionError: Recursive datastructure.
Add prefab values for one of the following types: A.
For more information, go to: http://www.jqno.nl/equalsverifier/errormessages
  at nl.jqno.equalsverifier.EqualsVerifier.handleError(EqualsVerifier.java:381)
  at nl.jqno.equalsverifier.EqualsVerifier.verify(EqualsVerifier.java:367)

What did you expect?

The EqualsVerifier should not require prefab values for A.

Which version of EqualsVerifier are you using?

2.1.5

Please provide any additional information below.

This also happens if the recursive field is a Collection.

@jqno
Copy link
Owner

jqno commented Sep 23, 2016

Hi,

Unfortunately, it's still necessary to add prefab values for ignored fields if they're recursive. EqualsVerifier will ignore them for checking the equals contract, but it can't know if the fields aren't called in equals or hashCode anyway. For example, you class could theoretically contain a cache that is not part of the contract, but that's consulted in the equals method anyway.

I realize that it's not very intuitive, so I've added a short explanation to the website: http://jqno.nl/equalsverifier/errormessages/recursive-datastructure/

@jqno jqno closed this as completed Sep 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants