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 for HASHCHODE_HAS_MORE_FIELDS_THAN_EQUALS #20

Open
boris-petrov opened this issue Jun 15, 2017 · 0 comments
Open

False positive for HASHCHODE_HAS_MORE_FIELDS_THAN_EQUALS #20

boris-petrov opened this issue Jun 15, 2017 · 0 comments

Comments

@boris-petrov
Copy link

boris-petrov commented Jun 15, 2017

Something like:

import java.util.Objects;

import com.google.common.collect.ComparisonChain;

public class Version implements Comparable<Version> {
	private final int major;
	private final int minor;
	private final int build;

	public Version(int major, int minor, int build) {
		this.major = major;
		this.minor = minor;
		this.build = build;
	}

	@Override
	public boolean equals(Object object) {
		return object instanceof Version && compareTo((Version) object) == 0;
	}

	@Override
	public int hashCode() {
		return Objects.hash(major, minor, build);
	}

	@Override
	public int compareTo(Version other) {
		return ComparisonChain.start()
			.compare(major, other.major)
			.compare(minor, other.minor)
			.compare(build, other.build)
			.result();
	}
}

Gives a HASHCHODE_HAS_MORE_FIELDS_THAN_EQUALS warning which is not correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant