CWE-581 - Object Model Violation: Just One of Equals and Hashcode Defined
- 摘要:Variant
- 结构:Simple
- 状态:Draft
- 发布日期:2006-12-15
- 更新日期:2025-12-11
名称
Object Model Violation: Just One of Equals and Hashcode Defined
描述
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().
常见后果
范围:Integrity, Other
影响:Other
注释: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.