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

FIELDS_ARE_NEVER_NULL doesn't work recursively #19

Closed
GoogleCodeExporter opened this issue Mar 29, 2015 · 1 comment
Closed

FIELDS_ARE_NEVER_NULL doesn't work recursively #19

GoogleCodeExporter opened this issue Mar 29, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

EqualsVerifier succeeds for ClassB, but not for ClassA. Apparently,
Feature.FIELDS_ARE_NEVER_NULL only works for the class that is verified,
and not for its fields.


final class ClassA {
    private final ClassB b;

    public ClassA(ClassB b) {
        if (b == null) {
            throw new NullPointerException("b");
        }

        this.b = b;
    }

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

    @Override
    public boolean equals(Object obj) {
        return (obj instanceof ClassA) && ((ClassA) obj).b.equals(b);
    }
}

final class ClassB {
    private final Object o;

    public ClassB(Object o) {
        if (o == null) {
            throw new NullPointerException("o");
        }

        this.o = o;
    }

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

    @Override
    public boolean equals(Object obj) {
        return (obj instanceof ClassB) && o.equals(((ClassB) obj).o);
    }
}

Original issue reported on code.google.com by jan.ouw...@gmail.com on 24 Jan 2010 at 8:07

@GoogleCodeExporter
Copy link
Author

Original comment by jan.ouw...@gmail.com on 24 Jan 2010 at 8:19

  • 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
Projects
None yet
Development

No branches or pull requests

1 participant