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

TypeTag.resolve does not return the same types in 2.0 #136

Closed
cheister opened this issue Mar 8, 2016 · 4 comments
Closed

TypeTag.resolve does not return the same types in 2.0 #136

cheister opened this issue Mar 8, 2016 · 4 comments
Labels

Comments

@cheister
Copy link

cheister commented Mar 8, 2016

What steps will reproduce the problem?

Upgrading to 2.0

What is the code that triggers this problem?

The following test passes in 1.x

    @Test
    public void succeed_withComparable() {
        EqualsVerifier.forClass(SubClass.class)
            .usingGetClass()
            .withPrefabValues(Comparable.class, "red", "black")
            .suppress(Warning.NULL_FIELDS)
            .verify();
    }

    public abstract class AbstractClass<I extends Comparable<? super I>> implements Comparable<AbstractClass<I>> {
        private final I id;

        protected AbstractClass(I id) {
            this.id = id;
        }

        @Override
        public int compareTo(AbstractClass<I> that) {
            return 1;
        }

        @Override
        public boolean equals(Object that) {
            return this == that ||
                (that != null &&
                    this.getClass().equals(that.getClass()) &&
                    id.equals(((AbstractClass<?>)that).id));
        }

        @Override
        public int hashCode() {
            return Objects.hashCode(id);
        }
    }

    public final class SubClass extends AbstractClass<String> {
        public SubClass(String id) {
            super(id);
        }
    }

but fails with the error

java.lang.AssertionError: IllegalArgumentException: Can not set final java.lang.Comparable field nl.jqno.equalsverifier.integration.extended_contract.TypeCheckTest$AbstractClass.id to nl.jqno.equalsverifier.internal.prefabvalues.TypeTag$TypeVariable
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)

in 2.0

Please provide any additional information below.

From a cursory look through the code it looks like the TypeTag code is not resolving the type of the id field anymore and sets it to the default of new TypeTag(TypeVariable.class)

@jqno
Copy link
Owner

jqno commented Mar 9, 2016

Hi,

Thanks for the detailed bug report. Actually, TypeTag was new in the 2.0. Before 2.0, EqualsVerifier would just put Object into anything that's a type variable, and hope to get away with it :). But obviously, I missed an important case, so thanks for letting me know. I will fix this for the next bugfix release.

@jqno jqno added the accepted label Mar 9, 2016
jqno added a commit that referenced this issue Mar 9, 2016
jqno added a commit that referenced this issue Mar 9, 2016
jqno added a commit that referenced this issue Mar 9, 2016
jqno added a commit that referenced this issue Mar 10, 2016
jqno added a commit that referenced this issue Mar 10, 2016
jqno added a commit that referenced this issue Mar 10, 2016
jqno added a commit that referenced this issue Mar 10, 2016
@jqno
Copy link
Owner

jqno commented Mar 13, 2016

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

@jqno jqno closed this as completed Mar 13, 2016
@cheister
Copy link
Author

2.0.1 is working great. Thanks for the fast turnaround on this fix.

@jqno
Copy link
Owner

jqno commented Mar 14, 2016

I'm happy to hear that!

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