<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:52:05 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-357] Endless NullPointerException at com.mongodb.OutMessage.reset</title>
                <link>https://jira.mongodb.org/browse/JAVA-357</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;I had redeployed spring web application onto glassfish 3.1, I got endless NullPointerException at at com.mongodb.OutMessage.reset(OutMessage.java:73). &lt;br/&gt;
(you can also refer this page -   &lt;a href=&quot;http://groups.google.com/group/mongodb-user/browse_thread/thread/a51a1f5f3850ba46/74272391a3ee37ab?hl=en&amp;amp;lnk=gst&amp;amp;q=endless#74272391a3ee37ab&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://groups.google.com/group/mongodb-user/browse_thread/thread/a51a1f5f3850ba46/74272391a3ee37ab?hl=en&amp;amp;lnk=gst&amp;amp;q=endless#74272391a3ee37ab&lt;/a&gt;    )&lt;/p&gt;

&lt;p&gt;Here is server log: &lt;br/&gt;
[#|2011-05-12T01:05:37.251+0900|SEVERE|glassfish3.1|com.mongodb.ReplicaSetS tatus|_ThreadID=27;_ThreadName=Thread-1;|unexpected &lt;br/&gt;
error getting config from node: localhost:10001 &lt;br/&gt;
java.lang.NullPointerException &lt;br/&gt;
at com.mongodb.OutMessage.reset(OutMessage.java:73) &lt;br/&gt;
at com.mongodb.OutMessage.&amp;lt;init&amp;gt;(OutMessage.java:51) &lt;br/&gt;
at com.mongodb.OutMessage.query(OutMessage.java:38) &lt;br/&gt;
at com.mongodb.DBPort.findOne(DBPort.java:142) &lt;br/&gt;
at com.mongodb.ReplicaSetStatus$Node.update(ReplicaSetStatus.java:156) &lt;br/&gt;
at com.mongodb.ReplicaSetStatus.updateAll(ReplicaSetStatus.java:277) &lt;br/&gt;
at com.mongodb.ReplicaSetStatus$Updater.run(ReplicaSetStatus.java:238) &lt;/p&gt;
&lt;div class=&apos;table-wrap&apos;&gt;
&lt;table class=&apos;confluenceTable&apos;&gt;&lt;tbody&gt;
&lt;tr&gt;
&lt;td class=&apos;confluenceTd&apos;&gt;#]&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;


&lt;p&gt;How to reproduce this issue:&lt;br/&gt;
1. deploy application to glassfish&lt;br/&gt;
2. redeploy same application to glassfish (or, drop the application from the glassfish)&lt;br/&gt;
3. you can get that exception endless&lt;/p&gt;

&lt;p&gt;I inject MongoDB Connecter as spring bean.&lt;br/&gt;
&amp;lt;bean id=&quot;MongoConnector&quot; class=&quot;jwdm.core.bean.MongoConnector&quot; &lt;br/&gt;
p:host=&quot;localhost&quot; p:port=&quot;10001&quot;&amp;gt; &lt;/p&gt;

&lt;p&gt;Here is full code of MongoConnector (as Spring bean): &lt;br/&gt;
public class MongoConnector { &lt;br/&gt;
        private Mongo mongoDB; &lt;br/&gt;
        private String host; &lt;br/&gt;
        private String port; &lt;br/&gt;
        // Return an instance of Mongo &lt;br/&gt;
        public Mongo getMongo() { &lt;br/&gt;
                logger.debug(&quot;Retrieving MongoDB&quot;); &lt;br/&gt;
                if (mongoDB == null) { &lt;br/&gt;
                        try &lt;/p&gt;
{ 
                                List&amp;lt;ServerAddress&amp;gt;       addrs = new ArrayList&amp;lt;ServerAddress&amp;gt;(); 
                                addrs.add(new ServerAddress(host, Integer.parseInt(port))); 
                                mongoDB = new Mongo(addrs); 
                        }
&lt;p&gt; catch (UnknownHostException e) &lt;/p&gt;
{ 
                                logger.error(e.toString()); 
                        } catch (MongoException e) {                                 logger.error(e.toString());                         }
&lt;p&gt; &lt;br/&gt;
                } &lt;br/&gt;
                return mongoDB; &lt;br/&gt;
        } &lt;br/&gt;
        // Retrieve a db &lt;br/&gt;
        public DB getDB(String dbname) &lt;/p&gt;
{ 
                logger.debug(&quot;Retrieving db: &quot; + dbname); 
                return getMongo().getDB(dbname); 
        }
&lt;p&gt; &lt;br/&gt;
        // Retrieve a collection &lt;br/&gt;
        public DBCollection getCollection(String dbname, String collection) &lt;/p&gt;
{ 
                logger.debug(&quot;Retrieving collection: &quot; + collection); 
                return getDB(dbname).getCollection(collection); 
        }
&lt;p&gt; &lt;br/&gt;
        ... getter , setter ... &lt;br/&gt;
} &lt;br/&gt;
&amp;lt;/bean&amp;gt; &lt;/p&gt;

&lt;p&gt;Before using spring bean style, I was using static factory style without spring.&lt;br/&gt;
But it produces same exception.&lt;/p&gt;

&lt;p&gt;Here is static factory style code:&lt;/p&gt;

&lt;p&gt;public class MongoDBFactory {&lt;/p&gt;

&lt;p&gt;	protected static Logger logger = LoggerFactory.getLogger(MongoDBFactory.class);&lt;/p&gt;

&lt;p&gt;	private static Mongo mongoDB;&lt;/p&gt;

&lt;p&gt;	// Make sure no one can instantiate our factory&lt;br/&gt;
	private MongoDBFactory() {&lt;br/&gt;
	}&lt;/p&gt;

&lt;p&gt;	// Return an instance of Mongo&lt;br/&gt;
	public static Mongo getMongo() {&lt;br/&gt;
		logger.debug(&quot;Retrieving MongoDB&quot;);&lt;br/&gt;
		if (mongoDB == null) {&lt;br/&gt;
			try &lt;/p&gt;
{
				List&amp;lt;ServerAddress&amp;gt;	addrs = new ArrayList&amp;lt;ServerAddress&amp;gt;();
				
				addrs.add(new ServerAddress(&quot;localhost&quot;, 10001));
				//addrs.add(new ServerAddress(&quot;leewin12.cafe24.com&quot;, 10001));
				
				mongoDB = new Mongo(addrs);
				 
			}
&lt;p&gt; catch (UnknownHostException e) &lt;/p&gt;
{
				logger.error(e.toString());
			} catch (MongoException e) {				logger.error(e.toString());			}
&lt;p&gt;		}&lt;/p&gt;

&lt;p&gt;		return mongoDB;&lt;br/&gt;
	}&lt;/p&gt;

&lt;p&gt;	// Retrieve a db&lt;br/&gt;
	public static DB getDB(String dbname) &lt;/p&gt;
{
		logger.debug(&quot;Retrieving db: &quot; + dbname);
		return getMongo().getDB(dbname);
	}

&lt;p&gt;	// Retrieve a collection&lt;br/&gt;
	public static DBCollection getCollection(String dbname, String collection) &lt;/p&gt;
{
		logger.debug(&quot;Retrieving collection: &quot; + collection);
		return getDB(dbname).getCollection(collection);
	}
&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;Thank you for your helps,&lt;br/&gt;
Greg&lt;/p&gt;


</description>
                <environment>Window 7 SP1 32bit&lt;br/&gt;
Glassfish 3.1 + Spring 3.0.5 (Can be ignore it)&lt;br/&gt;
</environment>
        <key id="17380">JAVA-357</key>
            <summary>Endless NullPointerException at com.mongodb.OutMessage.reset</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="5">Cannot Reproduce</resolution>
                                        <assignee username="scotthernandez">Scott Hernandez</assignee>
                                    <reporter username="leewin12">Gregory DH Lee</reporter>
                        <labels>
                            <label>redeploy</label>
                    </labels>
                <created>Sun, 22 May 2011 04:08:10 +0000</created>
                <updated>Tue, 25 Jun 2013 16:49:42 +0000</updated>
                            <resolved>Mon, 24 Oct 2011 11:33:40 +0000</resolved>
                                    <version>2.5.3</version>
                                                    <component>Cluster Management</component>
                                        <votes>1</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="38583" author="mnorman" created="Tue, 21 Jun 2011 20:42:02 +0000"  >&lt;p&gt;I was wrong.  I have not been able to reproduce this with 2.6.3.  The version on the server wasn&apos;t updated properly so we were seeing the problem only with an older driver.&lt;/p&gt;</comment>
                            <comment id="38036" author="remonvv" created="Fri, 17 Jun 2011 12:55:42 +0000"  >&lt;p&gt;We have the same problem. Occurs when redeploying a war without restarting the app server in (at least) GlassFish 3, Tomcat 6 and Jetty 7 which makes me think it&apos;s not related to specific app servers.&lt;/p&gt;

&lt;p&gt;I&apos;m relatively sure it&apos;s a problem unique to dependency injection frameworks (we use Guice, but Spring should be implementing these things in a similar way). When you redeploy a WAR file in most app servers it will recreate the war  scoped classloader which may somehow interfere with using a singleton Mongo instance in your DI framework. If it indeed is a DI specific problem then technically you can&apos;t call this is a java driver bug in the mongo driver since the code is correct. I have been unable to find a decent workaround in Guice that still allows the Mongo instance to be a singleton though. Will update once I do.&lt;/p&gt;

&lt;p&gt;UPDATE 1 : Cannot reproduce the issue with simple redeploying, nor with redeploying using a DI framework to provide the Mongo instance. Not sure if it&apos;s relevant but on the systems where I can reproduce it it&apos;s always thrown on com.mongodb.DBCursor.hasNext()&lt;br/&gt;
UPDATE 2 : Confirmed that having live threads running that have a DI injected reference to Mongo will reset static fields upon redeploy. Happens for other things too so doesn&apos;t seem mongo driver specific. Pretty sure you&apos;ll be stuck with app-side workaround.&lt;/p&gt;</comment>
                            <comment id="37606" author="scotthernandez" created="Wed, 15 Jun 2011 03:13:27 +0000"  >&lt;p&gt;Can you provide a simple war/web-app to reproduce this on tomcat 6? It does seem like a strange class-loader issue.&lt;/p&gt;</comment>
                            <comment id="37605" author="mnorman" created="Wed, 15 Jun 2011 03:01:25 +0000"  >&lt;p&gt;I am running into the same exception, but I&apos;m using Tomcat 6. It looks like &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-227&quot; title=&quot;NPE when replica set is down&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-227&quot;&gt;&lt;del&gt;JAVA-227&lt;/del&gt;&lt;/a&gt; attempted to solve a similar problem with NPEs on this line, but that code never made it into a release. I&apos;m using the latest as of today, 2.6.3, and it appears to still have the same code in OutMessage. I&apos;d be surprised if the code change made a difference, but then again, the code in OutMessage doesn&apos;t actually look wrong, so something odd is going on in the classloaders.&lt;/p&gt;</comment>
                            <comment id="33821" author="leewin12" created="Sun, 22 May 2011 04:09:28 +0000"  >&lt;p&gt;Oops, I omitted mongodb info, I&apos;m using single mongodb without any replicaset&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|hrhc2v:</customfieldvalue>

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