Skip to content

Commit a47dce3

Browse files
committed
CSHARP-5154: Coverity analysis defect 138095: Dereference null return value.
1 parent 91222c9 commit a47dce3

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/UnionMethodToPipelineTranslator.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ public static AstPipeline Translate(TranslationContext context, MethodCallExpres
3939
if (secondValue is IMongoQueryable secondQueryable)
4040
{
4141
var secondProvider = (IMongoQueryProviderInternal)secondQueryable.Provider;
42-
var secondCollectionName = secondProvider.CollectionNamespace.CollectionName;
42+
var secondCollectionNamespace = secondProvider.CollectionNamespace;
43+
if (secondCollectionNamespace == null)
44+
{
45+
throw new ExpressionNotSupportedException(expression, because: "second argument must be an IMongoQueryable against a collection");
46+
}
47+
48+
var secondCollectionName = secondCollectionNamespace.CollectionName;
4349
var secondPipelineInputSerializer = secondProvider.PipelineInputSerializer;
4450
var secondContext = TranslationContext.Create(secondQueryable.Expression, secondPipelineInputSerializer);
4551
var secondPipeline = ExpressionToPipelineTranslator.Translate(secondContext, secondQueryable.Expression);

0 commit comments

Comments
 (0)