VariantDraft

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

Category: other

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· 1

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

Potential mitigations· 1

  • [Implementation]Both Equals() and Hashcode() should be defined.

References

  1. https://cwe.mitre.org/data/definitions/581.html

Related by meaning· 6

Nearest entities by semantic similarity across the cs-graph corpus.

CWE
Comparison of Object References Instead of Object Contents
CWE
clone() Method Without super.clone()
CWE
finalize() Method Without super.finalize()
CWE
Use of Wrong Operator in String Comparison
CWE
Incorrect Use of Autoboxing and Unboxing for Performance Critical Operations
CWE
Explicit Call to Finalize()
Sourced from MITRE CWE 4.20. Curated for EU compliance use cases by Adam Lundqvist, Founder at SQUR.