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

Non-transitive equals passes #75

GoogleCodeExporter opened this issue Mar 29, 2015 · 1 comment


None yet
1 participant
Copy link

commented Mar 29, 2015

Consider this class:

public final class School {
    private final String name;
    private final String nickname;

    public School(String name, String nickname) { = name;
        this.nickname = nickname;

    public boolean equals(Object obj) {
        if (!(obj instanceof School)) {
            return false;
        School other = (School)obj;
        return nullSafeEqual(name, ||
                nullSafeEqual(nickname, other.nickname);

    private boolean nullSafeEqual(String a, String b) {
        return a == null ? b == null : a.equals(b);

    public int hashCode() {
        return 42;

    public String toString() {
        return "School: name=" + name + ", nickname=" + nickname;

This equals method is non-transitive, as the following code demonstrates:

School red = new School("A", "1");
School green = new School("A", "2");
School blue = new School("B", "2");

assertTrue(red.equals(blue)); // fails

However, EqualsVerifier doesn't fail on this.

Original issue reported on by on 16 Feb 2013 at 7:45


This comment has been minimized.

Copy link

commented Mar 29, 2015

This has been fixed in version 1.2. Also, I've blogged about the solution:


Original comment by on 26 Mar 2013 at 6:57

  • Changed state: Fixed
  • Added labels: ****
  • Removed labels: ****
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.