Katalog CWE

CWE-581 · Słabość

Object Model Violation: Just One of Equals and Hashcode Defined

Abstrakcja
Wariant
Status
Szkic
Dodano
15 grudnia 2006
Ostatnia zmiana
11 grudnia 2025

Podatności CVE z tą słabościąPełny wpis na cwe.mitre.org ↗

Opis

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

Skutki

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

Zapobieganie

  • Implementation

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

Słabość nadrzędna

Kiedy powstaje

Dotyczy

Java

Wpis z katalogu CWE 4.20.