The product does not maintain equal hashcodes for equal objects.
View on MITREJava objects are expected to obey a number of invariants related to equality. One of these invariants is that equal objects must have equal hashcodes. In other words, if a.equals(b) == true then a.hashCode() == b.hashCode().
If this invariant is not upheld, it is likely to cause trouble if objects of this class are stored in a collection. If the objects of the class in question are used as a key in a Hashtable or if they are inserted into a Map or Set, it is critical that equal objects have equal hashcodes.
Both Equals() and Hashcode() should be defined.
No detection method information available for this CWE.
No examples or observed CVEs available for this CWE.
CWE-581: Object Model Violation: Just One of Equals and Hashcode Defined is a Common Weakness Enumeration (CWE) entry maintained by MITRE. The product does not maintain equal hashcodes for equal objects. Java objects are expected to obey a number of invariants related to equality. One of these invariants is that equal objects must have equal hashcodes. In other words, if a.equals(b) == true then a.hashCode() == b.hashCode().
If exploited, CWE-581 (Object Model Violation: Just One of Equals and Hashcode Defined) it can compromise Integrity and Other, leading to outcomes such as Other.
Recommended mitigations for CWE-581 include: Both Equals() and Hashcode() should be defined.
CWE-581 commonly affects Java. Note that weaknesses are often language-agnostic patterns, so secure coding practices apply broadly.
A CWE (Common Weakness Enumeration) like CWE-581 describes a category of software weakness — the underlying flaw type. A CVE (Common Vulnerabilities and Exposures) identifies a specific, real-world vulnerability in a particular product. In short, a CWE is the kind of mistake, and a CVE is an instance of that mistake being found in software.