CWE Database
/

CWE-595

Back to CWE list

CWE-595

Comparison of Object References Instead of Object Contents

Variant
Incomplete

Description

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.

Common Consequences

Scope

Other

Impact

Varies by Context

Potential Mitigations

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.

Applicable Platforms

Java
JavaScript
PHP
Not Language-Specific

Security Training

Train your team to recognize and prevent security threats with our comprehensive security awareness program.

Start Training

Vulnerability Scanning

Discover vulnerabilities in your applications and infrastructure before attackers do.

Scan Now