<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 09:01:47 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>[JAVA-4322] Observable&lt;T&gt; toFuture() implicit returns a future with a null value</title>
                <link>https://jira.mongodb.org/browse/JAVA-4322</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;&lt;b&gt;Background&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;While Integrating with the scala mongo driver we discovered &lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/blob/r4.3.3/driver-scala/src/main/scala/org/mongodb/scala/Observable.scala#L366-L376&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/blob/r4.3.3/driver-scala/src/main/scala/org/mongodb/scala/Observable.scala#L366-L376&lt;/a&gt;]&#160;&lt;/p&gt;

&lt;p&gt;the .head method hides a null underneath, as this is not documented nor is it defended against codebases can become vulnerable to null pointer exceptions or invalid responses in an API service, the fallback is to make use of .toFutureOption however as the risk isn&apos;t documented teams may only discover this when they hit it.&#160;&lt;/p&gt;

&lt;p&gt;If this is undefended against the code above continues to pass, Until someone tries to access something in the desired object.&#160;&lt;/p&gt;


&lt;p&gt;&lt;b&gt;Solutions&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;1.&#160;**&#160;Document the behaviour and offer more guidance in handling&#160;&lt;/p&gt;

&lt;p&gt;2. Throw NoSuchElementException instead of null.asInstanceOf&lt;/p&gt;

&lt;p&gt;3. Create a custom Exception to indicate what the null pointer means (the query returned nothing.)&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</description>
                <environment></environment>
        <key id="1886970">JAVA-4322</key>
            <summary>Observable&lt;T&gt; toFuture() implicit returns a future with a null value</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</type>
                                            <priority id="10300" iconUrl="https://jira.mongodb.org/images/icons/priorities/medium.svg">Unknown</priority>
                        <status id="10038" iconUrl="https://jira.mongodb.org/images/icons/subtask.gif" description="">Backlog</status>
                    <statusCategory id="2" key="new" colorName="default"/>
                                    <resolution id="-1">Unresolved</resolution>
                                        <assignee username="ross@mongodb.com">Ross Lawley</assignee>
                                    <reporter username="daniel.connelly@hotmail.co.uk">Daniel Connelly</reporter>
                        <labels>
                            <label>external-user</label>
                    </labels>
                <created>Thu, 30 Sep 2021 14:26:43 +0000</created>
                <updated>Wed, 4 May 2022 13:14:38 +0000</updated>
                                                                            <component>Scala</component>
                                        <votes>1</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="4135065" author="ross@10gen.com" created="Wed, 20 Oct 2021 13:23:47 +0000"  >&lt;p&gt;Opening and marking as a future improvement - when the whole API no longer uses &lt;tt&gt;Observable&amp;lt;Void&amp;gt;&lt;/tt&gt;.&lt;/p&gt;</comment>
                            <comment id="4131783" author="JIRAUSER1262661" created="Tue, 19 Oct 2021 10:19:42 +0000"  >&lt;p&gt;Hi Ross,&#160;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;I don&apos;t fully understand the need for null, when you could throw an exception here which could be transformed by other publishers and bubbled up when not transformed and cause errors in the code instead of null.&#160;&lt;/p&gt;</comment>
                            <comment id="4119173" author="ross@10gen.com" created="Tue, 12 Oct 2021 15:56:00 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=daniel.connelly%40hotmail.co.uk&quot; class=&quot;user-hover&quot; rel=&quot;daniel.connelly@hotmail.co.uk&quot;&gt;daniel.connelly@hotmail.co.uk&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;Since 4.0, the Scala code now lives in the same repo as the Java driver and reactive streams driver, so that is why we now use the JAVA jira project.&lt;/p&gt;

&lt;p&gt;Ross&lt;/p&gt;</comment>
                            <comment id="4119105" author="JIRAUSER1262661" created="Tue, 12 Oct 2021 15:40:24 +0000"  >&lt;p&gt;I would like to update the ticket as well with the correct link to the null occurrence &lt;a href=&quot;https://github.com/mongodb/mongo-scala-driver/blob/master/driver/src/main/scala/org/mongodb/scala/ObservableImplicits.scala#L347&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-scala-driver/blob/master/driver/src/main/scala/org/mongodb/scala/ObservableImplicits.scala#L347&lt;/a&gt;&#160;&lt;/p&gt;</comment>
                            <comment id="4118937" author="JIRAUSER1262661" created="Tue, 12 Oct 2021 15:03:47 +0000"  >&lt;p&gt;Hi Ross,&#160;&lt;/p&gt;

&lt;p&gt;Thanks for looking at this, just to confirm. as This is now a JAVA ticket, is the JAVA code automatically transformed into scala code?&#160;&lt;/p&gt;



&lt;p&gt;Daniel&#160;&lt;/p&gt;</comment>
                            <comment id="4118224" author="ross@10gen.com" created="Tue, 12 Oct 2021 11:55:31 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=daniel.connelly%40hotmail.co.uk&quot; class=&quot;user-hover&quot; rel=&quot;daniel.connelly@hotmail.co.uk&quot;&gt;daniel.connelly@hotmail.co.uk&lt;/a&gt; and &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=sunny.chotai%40digital.hmrc.gov.uk&quot; class=&quot;user-hover&quot; rel=&quot;sunny.chotai@digital.hmrc.gov.uk&quot;&gt;sunny.chotai@digital.hmrc.gov.uk&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;Thanks for your inputs. I think that the issue is the difference in paradigms between reactive stream style observables (Publishers) and Futures.  The Observable model has 0-n calls to &lt;tt&gt;onNext&lt;/tt&gt; and then a final state - &lt;tt&gt;success&lt;/tt&gt; or &lt;tt&gt;failure&lt;/tt&gt;.  Where as a &lt;tt&gt;Future&lt;/tt&gt; only has &lt;tt&gt;success&lt;/tt&gt; or &lt;tt&gt;failure&lt;/tt&gt; states.&lt;/p&gt;

&lt;p&gt;The fact that an &lt;tt&gt;Observable&lt;/tt&gt; completes without calling &lt;tt&gt;onNext&lt;/tt&gt; is not an error state and that is what requires the use of &lt;tt&gt;null&lt;/tt&gt;. &lt;/p&gt;

&lt;p&gt;I think this is more a side effect of the &lt;tt&gt;Observable&lt;span class=&quot;error&quot;&gt;&amp;#91;Void&amp;#93;&lt;/span&gt;&lt;/tt&gt; API (&lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-4303&quot; title=&quot;Improve map/flatmap of Publisher[Void]&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-4303&quot;&gt;&lt;del&gt;JAVA-4303&lt;/del&gt;&lt;/a&gt;) and if changed to &lt;tt&gt;Observable&lt;span class=&quot;error&quot;&gt;&amp;#91;Unit&amp;#93;&lt;/span&gt;&lt;/tt&gt; would produce more predictable Futures.&lt;/p&gt;

&lt;p&gt;Ross&lt;/p&gt;</comment>
                            <comment id="4096186" author="JIRAUSER1262413" created="Fri, 1 Oct 2021 11:11:05 +0000"  >&lt;p&gt;When .toFuture does not complete with a value, Future.Failed may be more appropriate than Future.successful(null). Especially given that .toFutureOption gives us Future.successful(None). ie if you use .toFuture over .toFutureOption then the value not being present is unexpected so this may be better represented using an exception in a Future.Failed.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                            <outwardlinks description="duplicates">
                                        <issuelink>
            <issuekey id="1883873">JAVA-4313</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="1875996">JAVA-4303</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <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|hzn73b:</customfieldvalue>

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