Skip to content

Commit bb1b636

Browse files
authored
CSHARP-5145: Coverity analysis defect 127214: Dereference null return value (#1365)
1 parent 1902c76 commit bb1b636

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/MongoDB.Bson/Serialization/Serializers/BsonClassMapSerializer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,12 @@ private TClass CreateInstanceUsingCreator(Dictionary<string, object> values)
436436
var value = keyValuePair.Value;
437437

438438
var memberMap = _classMap.GetMemberMapForElement(elementName);
439+
440+
if (memberMap == null)
441+
{
442+
throw new FormatException($"Element '{elementName}' does not match any field or property of class {_classMap.ClassType.FullName}");
443+
}
444+
439445
if (!memberMap.IsReadOnly)
440446
{
441447
memberMap.Setter.Invoke(document, value);

0 commit comments

Comments
 (0)