Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Pending Closed
-
None
-
None
Description
correct equals method implementation should start with
if (this == other) { return true; } if (other == null || getClass() != other.getClass()) { return false; }
DecimalTypeInfo, PrimitiveTypeInfo, VarcharTypeInfo, CharTypeInfo, HiveDecimalWritable equals method implementation starts with
if (other == null || !(other instanceof <class_name>)) { return false }
- first of all check for null is redundant
- the second issue is that "other instanceof <class_name>" check is not symmetric.
contract of equals() implies that, a.equals(b) is true if and only if b.equals(a) is true
Current implementation violates this contract.
e.g.
DecimalTypeInfo instanceof PrimitiveTypeInfo is true
but
PrimitiveTypeInfo instanceof DecimalTypeInfo is false
See more details here http://stackoverflow.com/questions/6518534/equals-method-overrides-equals-in-superclass-and-may-not-be-symmetric