Object Model Violation: Just One of Equals and Hashcode Defined
Weakness ID: 581 (Weakness Base)Status: Draft
+ Description

Description Summary

The software fails to maintain equal hashcodes for equal objects.

Extended Description

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

+ Time of Introduction
  • Implementation
+ Applicable Platforms



+ 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.

+ Relationships
NatureTypeIDNameView(s) this relationship pertains toView(s)
ChildOfWeakness ClassWeakness Class573Failure to Follow Specification
Development Concepts (primary)699
Research Concepts (primary)1000
+ Content History
Modification DateModifierOrganizationSource
2008-07-01Eric DalciCigitalExternal
updated Potential Mitigations, Time of Introduction
2008-09-08CWE Content TeamMITREInternal
updated Common Consequences, Relationships, Other Notes
2009-10-29CWE Content TeamMITREInternal
updated Common Consequences, Description, Other Notes
Previous Entry Names
Change DatePrevious Entry Name
2008-01-30Object Model Violation: Just One of Equals and Haschode Defined