ObjectId equals(...) broken

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Critical - P2
    • 3.0.0
    • Affects Version/s: 2.7.3
    • Component/s: API
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      ObjectId's equals(...) method is implemented invalidly. equals(...) methods need to be symmetrical, which means if A.equals(B) is true, B.equals(A) needs to be true as well. This is not the case as the implementation massages String values into ObjectId instances and thus surprisingly the following code succeeds:

      ObjectId left = new ObjectId();
      String right = left.toString();
      
      assertThat(left, is(right)); // succeeds
      

      This breaks once you test for symmetry:

      assertThat(right, is(left)); // fails
      

            Assignee:
            Jeffrey Yemin
            Reporter:
            Oliver Gierke
            None
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: