Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2979

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

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.10.0
    • Component/s: Builders
    • None
    • Environment:
      asp net core 3.1
    • Minor Change

      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 Unassigned
            Reporter:
            lealandvettleson@gmail.com Lealand Vettleson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: