Incorrect Semantic Object Comparison
Weakness ID: 596 (Weakness Base)Status: Incomplete
+ Description

Description Summary

The software does not correctly compare two objects based on their conceptual content.
+ Time of Introduction
  • Implementation
+ Detection Methods

Manual Static Analysis

Requires domain-specific knowledge to determine if the comparison is incorrect.

+ Demonstrative Examples

Example 1

For example, let's say you have two truck objects that you want to compare for equality. Truck objects are defined to be the same if they have the same make, the same model, and were manufactured in the same year. A Semantic Incorrect Object Comparison would occur if only two of the three factors were checked for equality. So if only make and model are compared and the year is ignored, then you have an incorrect object comparison.

(Bad Code)
Example Language: Java 
public class Truck {
private String make;
private String model;
private int year;

public boolean equals(Object o) {
if (o == null) return false;
if (o == this) return true;
if (!(o instanceof Truck)) return false;

Truck t = (Truck) o;

return (this.make.equals(t.getMake()) && this.model.equals(t.getModel()));
}
}
+ Relationships
NatureTypeIDNameView(s) this relationship pertains toView(s)
ChildOfCategoryCategory171Cleansing, Canonicalization, and Comparison Errors
Development Concepts699
ChildOfCategoryCategory569Expression Issues
Development Concepts (primary)699
ChildOfWeakness ClassWeakness Class697Insufficient Comparison
Research Concepts (primary)1000
+ Content History
Modifications
Modification DateModifierOrganizationSource
2008-07-01Sean EidemillerCigitalExternal
added/updated demonstrative examples
2008-07-01Eric DalciCigitalExternal
updated Time of Introduction
2008-09-08CWE Content TeamMITREInternal
updated Description, Detection Factors, Relationships
Previous Entry Names
Change DatePrevious Entry Name
2008-04-11Incorrect Object Comparison: Semantic