Did EqualsVerifier give an error message that you didn’t understand? I try to make the error messages as clear as possible, but unfortunately Java’s stacktraces leave little room for explanation sometimes. This page should help make sense of some of EqualsVerifier’s error messages.
Before you continue, please check your class’s
toString method. Since EqualsVerifier relies on
toString when generating error messages, overriding it helps with getting better error messages. I recommend including the name of the class, and a summary of all the fields relevant to the equals contract. For example:
The error messages
This is not a complete list. I’ll add to it as needed, so if you need help with an error message, please file an issue or let me know on the discussion group, and I’ll add an explanation as soon as possible.
- Abstract delegation
- BigDecimal equality
- ClassCastException: java.lang.Object cannot be cast to …
- Class is not accessible via the Java Module system. Consider opening the module that contains it.
- Coverage is not 100%
- Double: equals doesn’t use Double.compare for field foo
- Field foo of type Bar is not accessible via the Java Module System.
- Float: equals doesn’t use Float.compare for field foo
- JPA Entity: direct reference to field foo used instead of getter
- Mutability: equals depends on mutable field
- Non-nullity: equals/hashCode/toString throws NullPointerException
- Precondition: two objects are equal to each other
- Record: failed to run constructor
- Recursive datastructure
- Redefined superclass: object should not equal superclass instance
- Significant fields: equals does not use foo, or it is stateless
- Significant fields: equals relies on foo, but hashCode does not
- Subclass: equals is not final
- Subclass: … equals subclass instance …
- Subclass: object is not equal to an instance of a trivial subclass with equal fields
- Symmetry: … does not equal superclass instance …
- Unable to make field foo accessible: module bar does not “opens bar” to baz
- Unsupported class file major version x