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

Multiple reads of BsonBinary UUID return different results

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.12.2, 4.0.0
    • Affects Version/s: 3.12.1
    • Component/s: BSON
    • Labels:
      None
    • Minor Change

      Issue

      If a BsonBinary object is read multiple times by the UUID codec it returns a different result each time. The first read returns the correct data, all reads after are incorrect. From looking at the UuidCodec code it looks like the codec does operations on the underlying BsonBinary byte array which is causing it to change.

      I originally found this issue in 3.8 and was able to reproduce it in 3.12.1. I also found that the issue only exists for the JAVA_LEGACY and C_SHARP_LEGACY UuidRepresentations.

       

      Expected Behavior

      When a UUID is read from a BsonBinary object, the BsonBinary object is left unchanged.

       

      Steps to Reproduce

      Simple test to recreate the issue. The second read's assert fails.

      @Test
       public void testMultiReadUuid()
       {
         String key = "key";
         UUID uuid = UUID.randomUUID();
         UuidRepresentation uuidRepresentation = UuidRepresentation.JAVA_LEGACY;
         BsonDocument doc = new BsonDocument().append(key, new BsonBinary(uuid, uuidRepresentation));
        try (BsonReader reader = new BsonDocumentReader(doc))
         {
           reader.readStartDocument();
           reader.readName(key);
           // First read success
           Assert.assertEquals(uuid, new UuidCodec(uuidRepresentation).decode(reader, DecoderContext.builder().build()));
           reader.readEndDocument();
         }
        try (BsonReader reader = new BsonDocumentReader(doc))
         {
           reader.readStartDocument();
           reader.readName(key);
           // Second read fail
           Assert.assertEquals(uuid, new UuidCodec(uuidRepresentation).decode(reader, DecoderContext.builder().build()));
           reader.readEndDocument();
         }
       }
      

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            mackenzie.aaron.524@gmail.com Aaron MacKenzie
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: