<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:51:53 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-269] NullPointerException when authentication used with replica sets not logged correctly</title>
                <link>https://jira.mongodb.org/browse/JAVA-269</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;If you try use the java driver to connect to a database that requires authentication, a NullPointerException is thrown and caught in Node.update(). This is because at the point the update is attempted, the java code has yet to call the DB.authenticate() method. Because the exception is already caught, it is not preventing anything from working. However the code should handle this better so as to not generate a NPE in the first place.&lt;/p&gt;

&lt;p&gt;                    String setName = config.get(&quot;_id&quot;).toString(); // &amp;lt;-- .toString() triggers NPE if DB.authenticate() hasn&apos;t yet been called.&lt;br/&gt;
                    if ( _setName == null )&lt;/p&gt;
{
                        _setName = setName;
                        _logger = Logger.getLogger( _rootLogger.getName() + &quot;.&quot; + setName );
                    }

&lt;p&gt;Inspecting config shows it has $err defined (unauthenticated message) as well as code (10057).  Suggest checking if null first, then checking if an error exists and if it&apos;s not authentication related, only then show the user. Another alternative would be to have DBPort check for the condition first and then throw a MongoInternalException.&lt;/p&gt;

&lt;p&gt;                    static final int UNAUTHENTICATED_ERROR_CODE = 10057;&lt;br/&gt;
...&lt;/p&gt;

&lt;p&gt;                    Object setNameObj = config.get(&quot;_id&quot;);&lt;br/&gt;
                    if (setNameObj == null) {&lt;br/&gt;
                        if (config.get(&quot;$err&quot;) != null &amp;amp;&amp;amp; UNAUTHENTICATED_ERROR_CODE != (Integer)config.get(&quot;code&quot;)) &lt;/p&gt;
{ 
                                _logger.log( Level.SEVERE, &quot;can&apos;t get set name from node: &quot; +_addr + &quot;. Error: &quot; + config.get(&quot;$err&quot;));
                        }
&lt;p&gt;                        return;&lt;br/&gt;
                    }&lt;br/&gt;
                    String setName = setNameObj.toString();&lt;/p&gt;


&lt;p&gt;Stack Trace (based on git head, commit a052b4f35af4069121cbf47adc88d6199563c4d4): &lt;/p&gt;

&lt;p&gt;Feb 10, 2011 3:53:17 PM com.mongodb.ReplicaSetStatus$Node update&lt;br/&gt;
SEVERE: unexpected error getting config from node: 10.211.55.23:23003&lt;br/&gt;
java.lang.NullPointerException&lt;br/&gt;
	at com.mongodb.ReplicaSetStatus$Node.update(ReplicaSetStatus.java:174)&lt;br/&gt;
	at com.mongodb.ReplicaSetStatus.updateAll(ReplicaSetStatus.java:287)&lt;br/&gt;
	at com.mongodb.ReplicaSetStatus$Updater.run(ReplicaSetStatus.java:248)&lt;br/&gt;
Feb 10, 2011 3:53:17 PM com.mongodb.ReplicaSetStatus$Node update&lt;br/&gt;
SEVERE: unexpected error getting config from node: 10.211.55.23:23003&lt;br/&gt;
java.lang.NullPointerException&lt;br/&gt;
	at com.mongodb.ReplicaSetStatus$Node.update(ReplicaSetStatus.java:174)&lt;br/&gt;
	at com.mongodb.ReplicaSetStatus.updateAll(ReplicaSetStatus.java:287)&lt;br/&gt;
	at com.mongodb.ReplicaSetStatus.ensureMaster(ReplicaSetStatus.java:280)&lt;br/&gt;
	at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:364)&lt;br/&gt;
	at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:206)&lt;br/&gt;
	at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:271)&lt;br/&gt;
	at com.mongodb.DB.command(DB.java:154)&lt;br/&gt;
	at com.mongodb.DB.command(DB.java:139)&lt;br/&gt;
	at com.mongodb.DB._doauth(DB.java:469)&lt;br/&gt;
	at com.mongodb.DB.authenticate(DB.java:434)&lt;/p&gt;</description>
                <environment>OS X 10.6.6, Java driver. 3-node replica set with user authentication (--auth) (and replica authentication --keyFile)</environment>
        <key id="14634">JAVA-269</key>
            <summary>NullPointerException when authentication used with replica sets not logged correctly</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</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="antoine">Antoine Girbal</assignee>
                                    <reporter username="mikec">Mike Copley</reporter>
                        <labels>
                    </labels>
                <created>Thu, 10 Feb 2011 16:01:32 +0000</created>
                <updated>Thu, 17 Mar 2011 19:13:55 +0000</updated>
                            <resolved>Fri, 11 Feb 2011 08:39:55 +0000</resolved>
                                    <version>2.4</version>
                    <version>2.5</version>
                                    <fixVersion>2.5</fixVersion>
                                    <component>Cluster Management</component>
                                        <votes>0</votes>
                                    <watches>0</watches>
                                                                                                                <comments>
                            <comment id="23679" author="auto" created="Fri, 11 Feb 2011 08:42:53 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;login&apos;: u&apos;agirbal&apos;, u&apos;name&apos;: u&apos;agirbal&apos;, u&apos;email&apos;: u&apos;antoine@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-269&quot; title=&quot;NullPointerException when authentication used with replica sets not logged correctly&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-269&quot;&gt;&lt;del&gt;JAVA-269&lt;/del&gt;&lt;/a&gt;: NullPointerException when authentication used with replica sets not logged correctly&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/eacd9a594bf2f5d4ffe5f237decca61b1721bc8f&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/eacd9a594bf2f5d4ffe5f237decca61b1721bc8f&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="23678" author="antoine" created="Fri, 11 Feb 2011 08:39:55 +0000"  >&lt;p&gt;final fix:&lt;br/&gt;
add a checkAuth for DB local before trying to get replset config in updater.&lt;br/&gt;
If the result is an error with a code that states needs auth, then driver logs a line telling user to auth against local or admin.&lt;/p&gt;</comment>
                            <comment id="23676" author="antoine" created="Fri, 11 Feb 2011 08:09:25 +0000"  >&lt;p&gt;the problem is slightly worse than that: even once authenticate is called by user, it will not stop the NPE.&lt;br/&gt;
The updater thread uses a dedicated port for each mongod, and calls methods directly on the port.&lt;br/&gt;
This means that checkAuth() is not called and most operations on it would fail.&lt;/p&gt;

&lt;p&gt;fortunately the isMaster command always succeeds&lt;br/&gt;
foo:SECONDARY&amp;gt; use admin&lt;br/&gt;
switched to db admin&lt;br/&gt;
foo:SECONDARY&amp;gt; show collections&lt;br/&gt;
Thu Feb 10 23:55:17 uncaught exception: error: {&lt;br/&gt;
	&quot;$err&quot; : &quot;unauthorized db:admin lock type:-1 client:127.0.0.1&quot;,&lt;br/&gt;
	&quot;code&quot; : 10057&lt;br/&gt;
}&lt;br/&gt;
foo:SECONDARY&amp;gt; db.runCommand(&quot;isMaster&quot;)&lt;br/&gt;
{&lt;br/&gt;
	&quot;setName&quot; : &quot;foo&quot;,&lt;br/&gt;
	&quot;ismaster&quot; : false,&lt;br/&gt;
	&quot;secondary&quot; : true,&lt;br/&gt;
	&quot;hosts&quot; : [&lt;br/&gt;
		&quot;localhost:27017&quot;,&lt;br/&gt;
		&quot;localhost:27018&quot;&lt;br/&gt;
	],&lt;br/&gt;
	&quot;passives&quot; : [&lt;br/&gt;
		&quot;localhost:27019&quot;&lt;br/&gt;
	],&lt;br/&gt;
	&quot;primary&quot; : &quot;localhost:27018&quot;,&lt;br/&gt;
	&quot;maxBsonObjectSize&quot; : 16777216,&lt;br/&gt;
	&quot;ok&quot; : 1&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;But getting the replset config will fail:&lt;br/&gt;
foo:SECONDARY&amp;gt; use local&lt;br/&gt;
switched to db local&lt;br/&gt;
foo:SECONDARY&amp;gt; db.system.replset.find()&lt;br/&gt;
error: {&lt;br/&gt;
	&quot;$err&quot; : &quot;unauthorized db:local lock type:-1 client:127.0.0.1&quot;,&lt;br/&gt;
	&quot;code&quot; : 10057&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;Right now the driver only needs that operation to obtain the setName from master node.&lt;br/&gt;
The setName is not actively used in driver, just to print out warning if it changes.&lt;/p&gt;

&lt;p&gt;Proposed fix:&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;add checkAuth to the direct port operations.&lt;/li&gt;
	&lt;li&gt;if we get error because not authenticated, print out warning that user should authenticate against admin or local.&lt;/li&gt;
&lt;/ul&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|hrgirj:</customfieldvalue>

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