<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:36:52 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CSHARP-447] 1.4.1 &quot;QueryBuilder.In&quot; fails when BsonArray argument is cast to IEnumerable&lt;BsonValue&gt;</title>
                <link>https://jira.mongodb.org/browse/CSHARP-447</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;\Driver\Builders\QueryBuilder.cs(1015):&lt;br/&gt;
public QueryConditionList In(IEnumerable&amp;lt;BsonValue&amp;gt; values)&lt;/p&gt;

&lt;p&gt;It calls `if (values.Contains(null)) ...` with a null argument. At the same time in&lt;/p&gt;

&lt;p&gt;\Bson\ObjectModel\BsonArray.cs(648):&lt;br/&gt;
public bool Contains(BsonValue value)&lt;/p&gt;

&lt;p&gt;.. there is:&lt;br/&gt;
if (value == null)&lt;br/&gt;
{&lt;br/&gt;
throw new ArgumentNullException(&quot;value&quot;);&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;Thus, `In` seems to be always throwing an exception in 1.4.1&lt;/p&gt;</description>
                <environment></environment>
        <key id="36556">CSHARP-447</key>
            <summary>1.4.1 &quot;QueryBuilder.In&quot; fails when BsonArray argument is cast to IEnumerable&lt;BsonValue&gt;</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="1" iconUrl="https://jira.mongodb.org/images/icons/priorities/blocker.svg">Blocker - P1</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="robert@mongodb.com">Robert Stam</assignee>
                                    <reporter username="nightroman">Roman Kuzmin</reporter>
                        <labels>
                    </labels>
                <created>Wed, 18 Apr 2012 06:30:20 +0000</created>
                <updated>Thu, 2 Apr 2015 18:28:12 +0000</updated>
                            <resolved>Sat, 21 Apr 2012 15:55:14 +0000</resolved>
                                    <version>1.4.1</version>
                                    <fixVersion>1.4.2</fixVersion>
                                                        <votes>0</votes>
                                    <watches>0</watches>
                                                                                                                <comments>
                            <comment id="112277" author="rstam" created="Sat, 21 Apr 2012 15:55:00 +0000"  >&lt;p&gt;The fix includes the following changes:&lt;/p&gt;

&lt;p&gt;1. BsonArray.Contains now returns false instead of throwing ArgumentNullException when called with null argument&lt;br/&gt;
2. Query.All, Query.In and Query.NotIn now handle nulls in the list of values according to functional construction semantics and therefore just skip them&lt;/p&gt;</comment>
                            <comment id="112275" author="rstam" created="Sat, 21 Apr 2012 15:39:11 +0000"  >&lt;p&gt;Note that this same issue applies to Query.All and Query.NotIn as well as Query.In.&lt;/p&gt;</comment>
                            <comment id="112272" author="rstam" created="Sat, 21 Apr 2012 15:20:14 +0000"  >&lt;p&gt;Changed the summary description of the issue to clarify that it doesn&apos;t always fail, it only fails when a BsonArray argument is cast to IEnumerable&amp;lt;BsonValue&amp;gt;.&lt;/p&gt;</comment>
                            <comment id="111182" author="rstam" created="Wed, 18 Apr 2012 15:34:20 +0000"  >&lt;p&gt;Yes it would only be a temporary workaround. This issue will be resolved in the next release (and sooner than that of course in the master branch).&lt;/p&gt;</comment>
                            <comment id="111152" author="nightroman" created="Wed, 18 Apr 2012 15:02:30 +0000"  >&lt;p&gt;&amp;gt; Can you work around this issue by not casting?&lt;br/&gt;
As a workaround - yes, indeed. But I would not like to use this always. In fact I do not do any explicit casting in my code. It is done implicitly in a chain of functions at some point.&lt;/p&gt;</comment>
                            <comment id="111150" author="nightroman" created="Wed, 18 Apr 2012 14:59:38 +0000"  >&lt;p&gt;I am glad that you can repro. So far it&apos;s just my tests failed, not something in use (yet). Hopefully it goes this way until the fix. Thank you for taking a look at this.&lt;/p&gt;

&lt;p&gt;When you get any changes done I will rerun my Mdbc tests. There are not so many tests there but they work &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/smile.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;
</comment>
                            <comment id="111149" author="rstam" created="Wed, 18 Apr 2012 14:59:15 +0000"  >&lt;p&gt;It&apos;s the casting of a BsonArray that triggers this issue. See:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;var array = new BsonArray { 1 };&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;var query1 = Query.In(&quot;x&quot;, array); // works&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;var query2 = Query.In(&quot;x&quot;, (IEnumerable&amp;lt;BsonValue&amp;gt;)array); // throws exception&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;BsonArray.Contains probably shouldn&apos;t check whether the value argument is null. It should just return false (it will always return false because a BsonArray can&apos;t possibly contain a null, the Add methods prevent it).&lt;/p&gt;

&lt;p&gt;Can you work around this issue by not casting?&lt;/p&gt;</comment>
                            <comment id="111145" author="craiggwilson" created="Wed, 18 Apr 2012 14:53:05 +0000"  >&lt;p&gt;Ok.  I can reproduce.  The actual callstack is below:&lt;/p&gt;

&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;QueryConditionList:In(IEnumerable&amp;lt;BsonValue&amp;gt; values)&lt;/li&gt;
	&lt;li&gt;Enumerable.Contains(IEnumerable&amp;lt;BsonValue&amp;gt; source, BsonValue value)&lt;/li&gt;
	&lt;li&gt;BsonArray.Contains(BsonValue value) &amp;lt;--- this one gets called (and throws) because BsonArray implements ICollection&amp;lt;BsonArray&amp;gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;I have also confirmed this is a breaking change in 1.4.1, although I can&apos;t find the commit that introduced this piece.  I&apos;m sorry you hit this issue.  Let us figure out next steps and we&apos;ll get back.&lt;/p&gt;</comment>
                            <comment id="111127" author="nightroman" created="Wed, 18 Apr 2012 14:31:59 +0000"  >&lt;p&gt;As for the test script he it is. Grab the Mdbc package (zip) from github, put it into posh module folder, replace your dlls there with newer and run this script:&lt;/p&gt;

&lt;p&gt;Import-Module Mdbc&lt;br/&gt;
query Foo -In Bar&lt;/p&gt;

&lt;p&gt;It fails:&lt;br/&gt;
New-MdbcQuery : Value cannot be null.&lt;br/&gt;
Parameter name: value&lt;br/&gt;
At C:\ROM\DEV\Mdbc\Test.ps1:3 char:1&lt;br/&gt;
+ query Foo -In Bar&lt;/p&gt;</comment>
                            <comment id="111120" author="nightroman" created="Wed, 18 Apr 2012 14:21:24 +0000"  >&lt;p&gt;Yes, it worked before. My test cases in the Mdbc module fail with the new version.&lt;/p&gt;</comment>
                            <comment id="111119" author="nightroman" created="Wed, 18 Apr 2012 14:20:00 +0000"  >&lt;p&gt;Yes, I created a snippet. This code (valid, I guess?) always fail:&lt;/p&gt;

&lt;p&gt;			var list1 = new QueryConditionList(&quot;name&quot;);&lt;br/&gt;
			var arr1 = new BsonArray();&lt;br/&gt;
			arr1.Add(1);&lt;br/&gt;
			System.Collections.Generic.IEnumerable&amp;lt;BsonValue&amp;gt; enum1 = arr1;&lt;br/&gt;
			list1.In(enum1);&lt;/p&gt;</comment>
                            <comment id="111118" author="craiggwilson" created="Wed, 18 Apr 2012 14:19:26 +0000"  >&lt;p&gt;No, they don&apos;t contain a test case for BsonArray because code you referenced never goes into the BsonArray code.  The values.Contains code you are referencing on line 1015 does not refer to a BsonArray.Contains call, but rather the Enumerable.Contains method call.&lt;/p&gt;

&lt;p&gt;The values.Contains call in this code was changed in commit: &lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/8ef88b3acd50ba641bfddcb542a1438147c5f241#diff-1&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/8ef88b3acd50ba641bfddcb542a1438147c5f241#diff-1&lt;/a&gt;.  This commit happened for the 1.4 release, meaning it did not change for 1.4.1.&lt;/p&gt;

&lt;p&gt;So, my question is this: was this working before and is failing now? If it used to be working and now isn&apos;t, then definitely provide the code you mentioned above (the Mdbc posh module) and I&apos;ll try and reproduce to figure it out.&lt;/p&gt;</comment>
                            <comment id="111114" author="rstam" created="Wed, 18 Apr 2012 14:16:52 +0000"  >&lt;p&gt;Can you provide the code snippet that calls Query.In and the stack trace? Thanks.&lt;/p&gt;</comment>
                            <comment id="111106" author="nightroman" created="Wed, 18 Apr 2012 14:08:49 +0000"  >&lt;p&gt;BTW, the test cases above do not contain a case with BsonArray (or I just do not see?)&lt;/p&gt;</comment>
                            <comment id="111105" author="nightroman" created="Wed, 18 Apr 2012 14:06:24 +0000"  >&lt;p&gt;Craig, I got this information not from code analysis but from the debugger at the moment of failure. So it is the right overload.&lt;/p&gt;

&lt;p&gt;The code is called from a PowerShell script via Mdbc module (available at github). Is it possible for you to use it? Then I will provide the details.&lt;/p&gt;</comment>
                            <comment id="111074" author="craiggwilson" created="Wed, 18 Apr 2012 13:07:33 +0000"  >&lt;p&gt;While this does look suspicious, it is in fact valid.  The overload you are referring to (IEnumerable&amp;lt;BsonValue&amp;gt; values) is not a BsonArray.  Hence, the Contains call you are referring to is no the BsonArray.Contains, but rather the Enumerable.Contains extension method. I wrote the following assertions in a test and they all pass correctly.&lt;/p&gt;


&lt;p&gt;  Assert.Throws&amp;lt;ArgumentOutOfRangeException&amp;gt;(() =&amp;gt; Query.In(&quot;j&quot;, 2, null, 3));&lt;br/&gt;
  Assert.Throws&amp;lt;ArgumentOutOfRangeException&amp;gt;(() =&amp;gt; Query.In(&quot;j&quot;, new List&amp;lt;BsonValue&amp;gt; &lt;/p&gt;
{2, null, 3 }
&lt;p&gt;));&lt;/p&gt;

&lt;p&gt;  Assert.Throws&amp;lt;ArgumentOutOfRangeException&amp;gt;(() =&amp;gt; Query.In(&quot;j&quot;, BsonValue.Create(2), BsonValue.Create(null), BsonValue.Create(3)));&lt;br/&gt;
  Assert.Throws&amp;lt;ArgumentOutOfRangeException&amp;gt;(() =&amp;gt; Query.In(&quot;j&quot;, new List&amp;lt;BsonValue&amp;gt; &lt;/p&gt;
{BsonValue.Create(2), BsonValue.Create(null), BsonValue.Create(3) }
&lt;p&gt;));&lt;/p&gt;


&lt;p&gt;Would you mind posting the code that used to work that doesn&apos;t anymore so I can take a more specific look at the issue?&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hrh7of:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>14043</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>