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

AbstractMethodError with classes extending AbstractSet #161

Closed
don-vip opened this issue Nov 26, 2016 · 2 comments
Closed

AbstractMethodError with classes extending AbstractSet #161

don-vip opened this issue Nov 26, 2016 · 2 comments
Labels

Comments

@don-vip
Copy link
Contributor

don-vip commented Nov 26, 2016

What steps will reproduce the problem?

Test a class extending AbstractSet

What is the code that triggers this problem?

import java.util.AbstractSet;
import java.util.Iterator;

public class TestSet extends AbstractSet<Object> {

    private int field;

    @Override
    public Iterator<Object> iterator() {
        return new Iterator<Object>() {
            @Override
            public boolean hasNext() {
                return false;
            }

            @Override
            public Object next() {
                return null;
            }
        };
    }

    @Override
    public int size() {
        return 0;
    }

    @Override
    public int hashCode() {
        return 31 * super.hashCode() + field;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (!super.equals(obj))
            return false;
        if (getClass() != obj.getClass())
            return false;
        TestSet other = (TestSet) obj;
        if (field != other.field)
            return false;
        return true;
    }
}
    @Test
    public void testEqualsContract() {
        EqualsVerifier.forClass(TestSet.class).usingGetClass().verify();
    }

What error message or stack trace does EqualsVerifier give?

java.lang.AssertionError: AbstractMethodError: 
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:370)
	at org.openstreetmap.josm.data.osm.StorageTest.testEqualsContract2(StorageTest.java:29)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.openstreetmap.josm.testutils.JOSMTestRules$TimeoutThread.run(JOSMTestRules.java:348)
Caused by: java.lang.AbstractMethodError
	at java.util.AbstractSet.equals(AbstractSet.java:92)
	at org.openstreetmap.josm.data.osm.TestSet.equals(TestSet.java:40)
	at nl.jqno.equalsverifier.HierarchyChecker.checkSuperclass(HierarchyChecker.java:77)
	at nl.jqno.equalsverifier.HierarchyChecker.check(HierarchyChecker.java:56)
	at nl.jqno.equalsverifier.EqualsVerifier.verifyWithExamples(EqualsVerifier.java:431)
	at nl.jqno.equalsverifier.EqualsVerifier.performVerification(EqualsVerifier.java:393)
	at nl.jqno.equalsverifier.EqualsVerifier.verify(EqualsVerifier.java:364)
	... 10 more

Which version of EqualsVerifier are you using?

2.1.7

Please provide any additional information below.

This comes probably from the fact that AsbtractSet does not define size()

@jqno
Copy link
Owner

jqno commented Nov 29, 2016

I've reproduced the issue, and you're right, it's because AbstractSet doesn't define size().

I have a solution in mind for this, but you caught me in a busy period so it might be a little while before I get to it, unfortunately.

@jqno
Copy link
Owner

jqno commented Dec 13, 2016

I just released version 2.1.8 which contains a fix for this.

@jqno jqno closed this as completed Dec 13, 2016
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