Skip to content

False positive for HASHCHODE_HAS_MORE_FIELDS_THAN_EQUALS #20

@boris-petrov

Description

@boris-petrov

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions