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

ObjectId equals(...) broken

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Critical - P2 Critical - P2
    • 3.0.0
    • 2.7.3
    • API
    • None

    Description

      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

      Attachments

        Activity

          People

            jeff.yemin@mongodb.com Jeffrey Yemin
            oliver.gierke Oliver Gierke
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: