Recursive datastructure error on private static final fields

458 views
Skip to first unread message

Pål Skjager Løberg

unread,
Mar 10, 2016, 10:59:27 AM3/10/16
to equalsverifier
Hi.

Testing 2.0 right now and some of my tests are failing. I wonder if something has changed with regards to private static final fields that earlier were ignored (http://www.jqno.nl/equalsverifier/2011/06/27/recursive-datastructure/).

I have an abstract class with a private static final field (a Jackson ObjectMapper) that is not included in any equals/hashCode.

When I test this I get:

java.lang.AssertionError: Recursive datastructure.
Add prefab values for one of the following types: ObjectMapper, JsonFactory, CharsToNameCanonicalizer.
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)

It seems like I can get around this by ignoring the specific field, but is this intended behavior?

public abstract class AbstractFoo {
    private static final ObjectMapper objectMapper = new ObjectMapper();
}

public final class Foo extends AbstractFoo implements BarInterface {
    ...

    public boolean equals(Object o) {
      ...
    }

    public int hashCode() {
      ...
    } 
}

public class FooTest {
    @Test
    public void equals_and_hashcode_contracts() {
        EqualsVerifier.forClass(Foo.class .verify();
    }
}



Thanks,

 -- Paul

Jan Ouwens

unread,
Mar 10, 2016, 11:04:25 AM3/10/16
to equalsv...@googlegroups.com, Pål Skjager Løberg
Hi Pål,

Not much has changed regarding private static final fields, but a lot has changed regarding generics. EqualsVerifier will try to instantiate all field, including the private static final ones, because they could be touched by equals or hashCode. Perhaps ObjectMapper does something with reflection that I missed when developing 2.0.

Can you tell me the specific library that has this ObjectMapper class? Also, which version are you using? That will help me to investigate this problem.

I’m already fixing some other bugs as well, so I anticipate a bugfix release relatively soon. Hopefully, I can fix this particular issue in that release, too.


Jan
--
You received this message because you are subscribed to the Google Groups "equalsverifier" group.
To unsubscribe from this group and stop receiving emails from it, send an email to equalsverifie...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages