CWE-581 — Object Model Violation: Just One of Equals and Hashcode Defined
CWE-581: Object Model Violation: Just One of Equals and Hashcode Defined
MITRE CWE weakness
| Kind | Weakness |
| Abstraction | Variant |
| Status | Draft |
| Likelihood of exploit | — |
Description
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().
Common consequences
- Integrity, Other: Other
Mitigations
Implementation — Both Equals() and Hashcode() should be defined.
References
- CWE page: https://cwe.mitre.org/data/definitions/581.html
- CWE list: https://cwe.mitre.org/data/index.html