[CSHARP-2979] Builders<T>.Filter.And(filters) does not handle null values in filters Created: 26/Feb/20 Updated: 31/Mar/22 |
|
| Status: | Backlog |
| Project: | C# Driver |
| Component/s: | Builders |
| Affects Version/s: | 2.10.0 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Lealand Vettleson | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
asp net core 3.1 |
||
| Backwards Compatibility: | Minor Change |
| Description |
|
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) If we look at the Render a little further down in the FilterDefinitionBuilder.cs, we see _filters iterated over: foreach (var filter in _filters) If _filters contains a null, this will trigger a NullReferenceException. |
| Comments |
| Comment by Lealand Vettleson [ 26/Feb/20 ] |
|
The workaround here is to just make sure no nulls go into our filter collection before we add them to the builder. |