Difference between revisions of "Object Model Violation: Just One of equals() and hashCode() Defined"

From OWASP
Jump to: navigation, search
Line 2: Line 2:
 
{{Template:Fortify}}
 
{{Template:Fortify}}
  
__TOC__
 
  
 
[[ASDR Table of Contents]]
 
[[ASDR Table of Contents]]
Line 12: Line 11:
  
 
==Description==
 
==Description==
 
 
This class overrides only one of equals() and hashCode().
 
This class overrides only one of equals() and hashCode().
  

Revision as of 08:26, 19 February 2009

This is a Vulnerability. To view all vulnerabilities, please see the Vulnerability Category page.


This article includes content generously donated to OWASP by Fortify.JPG.


ASDR Table of Contents

Last revision (mm/dd/yy): 02/19/2009

Description

This class overrides only one of equals() and hashCode().

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

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.


Risk Factors

  • Talk about the factors that make this vulnerability likely or unlikely to actually happen
  • Discuss the technical impact of a successful exploit of this vulnerability
  • Consider the likely [business impacts] of a successful attack


Examples

The following class overrides equals() but not hashCode().

 public class halfway() {
   public boolean equals(Object obj) {
 	...
   }
 }

Related Attacks


Related Vulnerabilities

Related Controls


Related Technical Impacts


References

Note: A reference to related CWE or CAPEC article should be added when exists. Eg: