CWE
Home > CWE List > CWE- Individual Dictionary Definition (1.1)  
Search by ID:

CWE-581: Object Model Violation: Just One of Equals and Hashcode Defined

Individual Definition in a New Window
Object Model Violation: Just One of Equals and Hashcode Defined
Status: Draft
Weakness ID: 581 (Weakness Base)
Description
Summary

The software fails to maintain equal hashcodes for equal objects.

Common Consequences

Failure to uphold this invariant 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.

Potential Mitigations

Both Equals() and Hashcode() should be defined.

Other Notes

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().

Relationships
NatureTypeIDNameView(s) this relationship pertains toView(s)
ChildOfWeakness ClassWeakness ClassWeakness Class573Failure to Follow Specification
Development Concepts (primary)699
Research Concepts (primary)1000
Applicable Platforms
Languages
Java
Time of Introduction
* Implementation
Content History
Modifications
Eric Dalci. Cigital. 2008-07-01. (External)
updated Potential_Mitigations, Time_of_Introduction
CWE Content Team. MITRE. 2008-09-08. (Internal)
updated Common_Consequences, Relationships, Other_Notes
Previous Entry Names
* Object Model Violation: Just One of Equals and Haschode Defined (changed 2008-01-30)
Page Last Updated: November 24, 2008