Details
-
Bug
-
Resolution: Done
-
Major - P3
-
None
-
2.2
-
None
-
Minor Change
Description
equals() in Java must be symmetric, but an ObjectId might compare equal to a String, but (obviously) not the other way around.
ObjectId obj = new ObjectId();
String str = obj.toString();
assertEquals(obj.equals(str), str.equals(obj);
obj.equals(str) => true
str.equals(obj) => false
This is because ObjectId.equals() calls massageToObjectId which will turn the String into an ObjectId (if it isValid); but String.equals() doesn't turn "any object" to its String representation.
The fix is fortunately easy: implement equals() without calling massageToObjectId:
public boolean equals( Object o ){
if ( this == o )
return true;
if ( o instanceof ObjectId )
{ ObjectId other = (ObjectId)o; return _time == other._time && _machine == other._machine && _inc == other._inc; } return false;
}