[CSHARP-4470] Missing null check in BsonClassMapSerializer Created: 01/Jan/23 Updated: 27/Oct/23 Resolved: 18/Jan/23 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | R B | Assignee: | Robert Stam |
| Resolution: | Gone away | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
SummaryAs I reviewed the source code to fill some gaps in the documentation, it appeared to me that a null check may be missing on this line to turn the code into the below (see the null check in the if statement)
For there may be situations in which there are leftover values for properties not having any memberMap defined. In these situations, with the current implementation the user would receive a NullReferenceException at runtime since GetMemberMapForElement will return null. If this situation is not allowed, a better approach would be throw a more specific exception but it seems to me that the ideal behavior would be to silently ignore the properties not having any memberMap. Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).Affects version 2.18 (latest release) and likely previous versions as well. How to Reproduce
Additional BackgroundPlease note that the ability to have leftover values for instances created using creators is extremely useful (and even essential in our case) so I am by no mean asking for this feature to be removed. |
| Comments |
| Comment by PM Bot [ 18/Jan/23 ] | |||||||||||||||||||||||||||
|
There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to comment on this if you're able to provide more information. | |||||||||||||||||||||||||||
| Comment by Robert Stam [ 03/Jan/23 ] | |||||||||||||||||||||||||||
|
You can see the full code I used to attempt to reproduce here: https://github.com/rstam/mongo-csharp-driver/commits/csharp4470 | |||||||||||||||||||||||||||
| Comment by Robert Stam [ 03/Jan/23 ] | |||||||||||||||||||||||||||
|
Thanks for this report. I am unable to reproduce the reported issue. I used this class:
And configured the class map (in code) using:
And wrote this test:
Even if I configure `IgnoreExtraElements` to `false` I still don't get a `NullReferenceException`. Instead I get a `FormatException` with an error message stating that `T` is an unmapped element.
Please let me know if I should be doing something different to reproduce what you are reporting. |