Skip to content

Inconsistent implementation of equals() and hashCode() #4936

@Nadahar

Description

@Nadahar

Java requires that equals() and hashCode() must be consistent, two objects that are "equal" must always produce the same hash code.

Failing to respect this will make things go wrong with HashMap, HashTable etc., i.e. some of the core Java building blocks that many other things build upon.

I've seen that this is implemented wrong in some of the Yaml classes, e.g:

@Override
public int hashCode() {
return Objects.hash(getValue());
}
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
} else if (obj == null || getClass() != obj.getClass()) {
return false;
}
YamlMetadataDTO other = (YamlMetadataDTO) obj;
return Objects.equals(getValue(), other.getValue()) && YamlElementUtils.equalsConfig(config, other.config);
}
}

Similar errors exist in YamlChannelDTO and YamlThingDTO.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn unexpected problem or unintended behavior of the Core

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions