Katalog CWE

CWE-595 · Słabość

Comparison of Object References Instead of Object Contents

Abstrakcja
Wariant
Status
Niekompletny
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 compares object references instead of the contents of the objects themselves, preventing it from detecting equivalent objects.

For example, in Java, comparing objects using == usually produces deceptive results, since the == operator compares object references rather than values; often, this means that using == for strings is actually comparing the strings' references, not their values.

Skutki

  • Other

    Varies by Context

    This weakness can lead to erroneous results that can cause unexpected application behaviors.

Zapobieganie

  • Implementation

    In Java, use the equals() method to compare objects instead of the == operator. If using ==, it is important for performance reasons that your objects are created by a static factory, not by a constructor.

Słabość nadrzędna

Słabości podrzędne

Kiedy powstaje

Dotyczy

Java, JavaScript, PHP, Not Language-Specific

Źródła

  1. Equality comparisons and sameness — Mozilla MDN

Wpis z katalogu CWE 4.20.