|
Status: Incomplete Weakness ID: 596 (Weakness Base)Description Summary The software does not correctly compare two objects based on their conceptual content. Detection Factors Requires domain-specific knowledge to determine if the comparison is incorrect. Demonstrative Examples 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. Java Example: 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
Time of Introduction ImplementationContent History Modifications Sean Eidemiller. Cigital. 2008-07-01. (External) added/updated demonstrative examples Eric Dalci. Cigital. 2008-07-01. (External) updated Time_of_Introduction CWE Content Team. MITRE. 2008-09-08. (Internal) updated Description, Detection_Factors, Relationships Previous Entry Names Incorrect Object Comparison: Semantic (changed 2008-04-11) |
|
|
|||