Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-609

ObjectId equals(...) broken

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • 3.0.0
    • Affects Version/s: 2.7.3
    • Component/s: API
    • Labels:
      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:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            oliver.gierke Oliver Gierke
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: