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

False positive Warning.REFERENCE_EQUALITY for class with Interface field if Interface defines equals() #130

Closed
tazle opened this issue Oct 16, 2015 · 2 comments
Labels

Comments

@tazle
Copy link

tazle commented Oct 16, 2015

Given following classes:

Interface that defines equals():

public interface Interface {
    long getValue();
    boolean equals(Object other);
}

A class using it: (standard IDEA boilerplate)

public final class Class {
    private final Interface f1;

    public Class(Interface f1) {
        this.f1 = f1;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Class aClass = (Class) o;

        return !(f1 != null ? !f1.equals(aClass.f1) : aClass.f1 != null);

    }

    @Override
    public int hashCode() {
        return f1 != null ? f1.hashCode() : 0;
    }
}

the following test fails with Warning.REFERENCE_EQUALITY:

import nl.jqno.equalsverifier.EqualsVerifier;
import org.junit.Test;


public class ClassTest {

    @Test
    public void testEq() {
        EqualsVerifier.forClass(Class.class).verify();
    }
}

Maybe this is related to #113 and #104?

@tazle tazle changed the title False positive Warning.REFERENCE_EQUALITY for interface field if interface defines equals() False positive Warning.REFERENCE_EQUALITY for class with Interface field if Interface defines equals() Oct 16, 2015
@jqno
Copy link
Owner

jqno commented Oct 19, 2015

Hi,

Thanks for reporting this. I've reproduced this, and I agree it's a bug. I'll fix it in the next release.

@jqno jqno added the accepted label Oct 19, 2015
@jqno
Copy link
Owner

jqno commented Dec 21, 2015

I've just released version 1.7.6, which fixes this.

@jqno jqno closed this as completed Dec 21, 2015
jqno pushed a commit that referenced this issue Aug 23, 2016
In Germany XING is more popular than LinkedIn, so I added a link to the XING profile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants