Incorrect filtered positional operator path

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Unknown
    • 5.5.1
    • Affects Version/s: 5.4.0
    • Component/s: Kotlin
    • None
    • None
    • Java Drivers
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      Issue is reproduced when using the 5.4.0 driver.

      When creating a mongo path to a property containing a filtered positional operator, the resulting path may be incorrect. The following snippet shows how to reproduce an incorrect path:

      import com.mongodb.kotlin.client.model.filteredPosOp
      import com.mongodb.kotlin.client.model.path
      import org.bson.types.ObjectId
      
      data class Document(
          val _id: ObjectId,
          val elements: List<String>,
      )
      
      fun main() {
          var incorrectPathFound = false
          var index = 0
      
          while (!incorrectPathFound) {
              val path = Document::elements.filteredPosOp("identifier$index").path()
              val expectedPath = "elements.$[identifier$index]"
      
              incorrectPathFound = path != expectedPath
      
              if (incorrectPathFound) {
                  println("Incorrect path for index $index: path is $path but should be $expectedPath")
              }
              index++
          }
      } 

      The snippet can be found this repo: https://github.com/brigondaud-betclic/mongo-java-driver-5.4.0-bug 

      A possible output of this snippet is: 

      Incorrect path for index 102115: path is elements.$[identifier58628] but should be elements.$[identifier102115]

      Issue seems related to instances of KPropertyPath.CustomProperty. When resolving a path using the com.mongodb.kotlin.client.model.path method, instances of this class are stored in the pathCache using the default toString method. A cache hit may happen in case of hashCode conflicts when resolving another path with a CustomProperty instance, producing an incorrect property name.

            Assignee:
            Ross Lawley
            Reporter:
            Baptiste RIGONDAUD
            Nabil Hachicha
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: