Builders<T>.Filter.And(filters) does not handle null values in filters

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Works as Designed
    • Priority: Minor - P4
    • None
    • Affects Version/s: 2.10.0
    • Component/s: Builders
    • None
    • Environment:
      asp net core 3.1
    • None
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Our team has been working on building a collection of filter definitions to query against and we noticed in our tests that when adding a null value to the collection, we end up getting a NullReferenceException.

      It appears that, while the collection is being Ensured that it's not null, the entities get no validation pass and are assumed to be correct.

      public AndFilterDefinition(IEnumerable<FilterDefinition<TDocument>> filters)
      {{ {}}
      {{     _filters = Ensure.IsNotNull(filters, nameof(filters)).ToList();}}
      {{ }}}

      (https://github.com/mongodb/mongo-csharp-driver/blob/master/src/MongoDB.Driver/FilterDefinitionBuilder.cs#L1500)

      If we look at the Render a little further down in the FilterDefinitionBuilder.cs, we see _filters iterated over:

      foreach (var filter in _filters)
      {{ {}}
      {{ var renderedFilter = filter.Render(documentSerializer, serializerRegistry);}}

      If _filters contains a null, this will trigger a NullReferenceException.

              Assignee:
              Unassigned
              Reporter:
              Lealand Vettleson
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: