Endless NullPointerException at com.mongodb.OutMessage.reset using mongo-java-driver

119 views
Skip to first unread message

Gregory Lee

unread,
May 12, 2011, 10:35:33 AM5/12/11
to mongod...@googlegroups.com
Hi all,

I'm using mongodb 1.8.1 (installed in local  win7),  and mongo-java-driver-2.5.3.jar.
I had redeployed spring web application onto glassfish 3.1, I got endless NullPointerException at at com.mongodb.OutMessage.reset(OutMessage.java:73).

Here is server log:
[#|2011-05-12T01:05:37.251+0900|SEVERE|glassfish3.1|com.mongodb.ReplicaSetStatus|_ThreadID=27;_ThreadName=Thread-1;|unexpected error getting config from node: localhost:10001
java.lang.NullPointerException
at com.mongodb.OutMessage.reset(OutMessage.java:73)
at com.mongodb.OutMessage.<init>(OutMessage.java:51)
at com.mongodb.OutMessage.query(OutMessage.java:38)
at com.mongodb.DBPort.findOne(DBPort.java:142)
at com.mongodb.ReplicaSetStatus$Node.update(ReplicaSetStatus.java:156)
at com.mongodb.ReplicaSetStatus.updateAll(ReplicaSetStatus.java:277)
at com.mongodb.ReplicaSetStatus$Updater.run(ReplicaSetStatus.java:238)
|#]
Plus, I inject MongoDB Connecter as spring bean.
<bean id="MongoConnector" class="jwdm.core.bean.MongoConnector" 
p:host="localhost" p:port="10001">
</bean>


Temporary, I put some null check code to avoid exception before ID.getAndIncrement.
ID is static declared and looks it should not be null ...

class OutMessage extends BSONEncoder {

    static AtomicInteger ID = new AtomicInteger(1);
    ...
private void reset( int op ){
        done();
        _buffer.reset();
        set( _buffer );
        
        if(ID == null) ID = new AtomicInteger(1); <== Here I added
        _id = ID.getAndIncrement(); <= exception point

        writeInt( 0 ); // length: will set this later
        writeInt( _id );
        writeInt( 0 ); // response to
        writeInt( op );
    }


Anyone what does the "ID.getAndIncrement()" means and how to solve this problem?
Thank you!


Greg

Brendan W. McAdams

unread,
May 12, 2011, 11:55:15 AM5/12/11
to mongod...@googlegroups.com
ID is an AtomicInteger, to allow multiple threads in the system to generate an ID that is guaranteed unique across all threads.  getAndIncrement is an Operation on AtomicInteger that basically says "give me the current value and then increment it".  Semantically, more or less like ++

DId you try restarting Glassfish completely?  This is happening only when you redeploy a running application, correct?
--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.

Gregory Lee

unread,
May 12, 2011, 9:14:46 PM5/12/11
to mongod...@googlegroups.com
Hi Brendan,
Thank you for reply,

Yes, you're right.
If I restart Glassfish completely, It's gone.

But, is there any way to prevent it?
It's always happens in every task(redeploy, undeploy, disable), and if I restart Glassfish completely always in deploy task,
my customer will not like it ...
and makes hard to do test works in Web Application Server.

So if possible, I want to keep Glassfish on.


I understand it's not only Mongodb's problem but also WAS and maybe OS. (Am I right?)
But still, It would be grateful if we can redeploy without complete restart.
Thank you for your help!


Greg

2011-05-13 오전 12:55, Brendan W. McAdams 쓴 글:

Nat

unread,
May 12, 2011, 9:17:40 PM5/12/11
to mongod...@googlegroups.com
One way you can workaround this at the moment is to put mongo jar as part of your application server library instead of package it.
From: Gregory Lee <leew...@gmail.com>
Date: Fri, 13 May 2011 10:14:46 +0900
Subject: Re: [mongodb-user] Endless NullPointerException at com.mongodb.OutMessage.reset using mongo-java-driver

Brendan W. McAdams

unread,
May 13, 2011, 12:18:35 PM5/13/11
to mongodb-user
I'm not as familiar with Glassfish as other servers, and not entirely
clear if it is happening in Glassfish or Spring.

It looks like, when the server restarts it may not be fully freeing up
the running MongoDB driver. I'm going to need to dig into this a bit
to see if there's a Java driver bug causing it.

Otherwise for now I'd suggest not relying on the redeploy mechanisms.
I know others have successfully used redeploys in Play, for example
with both Casbah (our Scala driver which wraps the java one) and the
Java Driver without seeing similar issues.

On May 12, 9:14 pm, Gregory Lee <leewi...@gmail.com> wrote:
> Hi Brendan,
> Thank you for reply,
>
> Yes, you're right.
> If I restart Glassfish completely, It's gone.
>
> But, is there any way to prevent it?
> It's always happens in every task(redeploy, undeploy, disable), and if I
> restart Glassfish completely always in deploy task,
> my customer will not like it ...
> and makes hard to do test works in Web Application Server.
>
> So if possible, I want to keep Glassfish on.
>
> I understand it's not only Mongodb's problem but also WAS and maybe OS.
> (Am I right?)
> But still, It would be grateful if we can redeploy without complete restart.
> Thank you for your help!
>
> Greg
>
> 2011-05-13 ?? 12:55, Brendan W. McAdams ? ?:
>
>
>
>
>
>
>
> > ID is an AtomicInteger, to allow multiple threads in the system to
> > generate an ID that is guaranteed unique across all threads.
> >  getAndIncrement is an Operation on AtomicInteger that basically says
> > "give me the current value and then increment it".  Semantically, more
> > or less like ++
>
> > DId you try restarting Glassfish completely?  This is happening only
> > when you redeploy a running application, correct?
>
> > On Thursday, May 12, 2011 at 10:35 AM, Gregory Lee wrote:
>
> >> Hi all,
>
> >> I'm using mongodb 1.8.1 (installed in local  win7),  and
> >> mongo-java-driver-2.5.3.jar.
> >> I had redeployed spring web application onto glassfish 3.1, I got
> >> endless NullPointerException at at
> >> com.mongodb.OutMessage.reset(OutMessage.java:73).
>
> >> Here is server log:
> >>> [#|2011-05-12T01:05:37.251+0900|SEVERE|glassfish3.1|com.mongodb.ReplicaSetS tatus|_ThreadID=27;_ThreadName=Thread-1;|unexpected
> >>> error getting config from node: localhost:10001
> >>> java.lang.NullPointerException
> >>> at com.mongodb.OutMessage.reset(OutMessage.java:73)
> >>> at com.mongodb.OutMessage.<init>(OutMessage.java:51)
> >>> at com.mongodb.OutMessage.query(OutMessage.java:38)
> >>> at com.mongodb.DBPort.findOne(DBPort.java:142)
> >>> at com.mongodb.ReplicaSetStatus$Node.update(ReplicaSetStatus.java:156)
> >>> at com.mongodb.ReplicaSetStatus.updateAll(ReplicaSetStatus.java:277)
> >>> at com.mongodb.ReplicaSetStatus$Updater.run(ReplicaSetStatus.java:238)
> >>> |#]
> >> Plus, I inject MongoDB Connecter as spring bean.
> >>> <bean id="MongoConnector" class="jwdm.core.bean.MongoConnector"
> >>> p:host="localhost" p:port="10001">
> >>> </bean>
>
> >> Temporary, I put some null check code to avoid exception before
> >> ID.getAndIncrement.
> >> ID is static declared and looks it should not be null ...
>
> >> class OutMessage extends BSONEncoder {
>
> >>     static AtomicInteger ID = new AtomicInteger(1);
> >>     ...
> >> private void reset( int op ){
> >>         done();
> >>         _buffer.reset();
> >>         set( _buffer );
> >> *if(ID == null) ID = new AtomicInteger(1); <== Here I added*
> >> *_id = ID.getAndIncrement(); <= exception point*
>
> >>         writeInt( 0 ); // length: will set this later
> >>         writeInt( _id );
> >>         writeInt( 0 ); // response to
> >>         writeInt( op );
> >>     }
>
> >> Anyone what does the "ID.getAndIncrement()" means and how to solve
> >> this problem?
> >> Thank you!
>
> >> Greg
>
> >> --
> >> You received this message because you are subscribed to the Google
> >> Groups "mongodb-user" group.
> >> To post to this group, send email to mongod...@googlegroups.com
> >> <mailto:mongod...@googlegroups.com>.
> >> To unsubscribe from this group, send email to
> >> mongodb-user...@googlegroups.com
> >> <mailto:mongodb-user...@googlegroups.com>.

Scott Hernandez

unread,
May 14, 2011, 3:48:52 PM5/14/11
to mongod...@googlegroups.com
Can you tell us a bit more about your MongoConnector?

This smells like a class-loader issue. Can you reproduce this without spring or any other frameworks?

Gregory Lee

unread,
May 16, 2011, 4:56:51 AM5/16/11
to mongodb-user
Sorry for late response.

Nat / Okay, I will try your advise, Thank you!

Brendan / Thank you for your concern about this matter.

Scott / I had thought like you, so I changed to Spring bean from
static factory style without spring.
But could not get rid of that exception.

Here is full code of MongoConnector (as Spring bean):

public class MongoConnector {

private Mongo mongoDB;

private String host;
private String port;

// Return an instance of Mongo
public Mongo getMongo() {
logger.debug("Retrieving MongoDB");
if (mongoDB == null) {
try {
List<ServerAddress> addrs = new ArrayList<ServerAddress>();

addrs.add(new ServerAddress(host, Integer.parseInt(port)));

mongoDB = new Mongo(addrs);

} catch (UnknownHostException e) {
logger.error(e.toString());
} catch (MongoException e) {
logger.error(e.toString());
}
}

return mongoDB;
}

// Retrieve a db
public DB getDB(String dbname) {
logger.debug("Retrieving db: " + dbname);
return getMongo().getDB(dbname);
}

// Retrieve a collection
public DBCollection getCollection(String dbname, String collection) {
logger.debug("Retrieving collection: " + collection);
return getDB(dbname).getCollection(collection);
}

... getter , setter ...
> > [#|2011-05-12T01:05:37.251+0900|SEVERE|glassfish3.1|com.mongodb.ReplicaSetS tatus|_ThreadID=27;_ThreadName=Thread-1;|unexpected
> > error getting config from node: localhost:10001
> > java.lang.NullPointerException
> >  at com.mongodb.OutMessage.reset(OutMessage.java:73)
> >  at com.mongodb.OutMessage.<init>(OutMessage.java:51)
> >  at com.mongodb.OutMessage.query(OutMessage.java:38)
> >  at com.mongodb.DBPort.findOne(DBPort.java:142)
> >  at com.mongodb.ReplicaSetStatus$Node.update(ReplicaSetStatus.java:156)
> >  at com.mongodb.ReplicaSetStatus.updateAll(ReplicaSetStatus.java:277)
> >  at com.mongodb.ReplicaSetStatus$Updater.run(ReplicaSetStatus.java:238)
> > |#]
>
> >  Plus, I inject MongoDB Connecter as spring bean.
>
> > <bean id="MongoConnector" class="jwdm.core.bean.MongoConnector"
> >  p:host="localhost" p:port="10001">
> >  </bean>
>
> >  Temporary, I put some null check code to avoid exception before
> > ID.getAndIncrement.
> > ID is static declared and looks it should not be null ...
>
> >  class OutMessage extends BSONEncoder {
>
> >      static AtomicInteger ID = new AtomicInteger(1);
> >      ...
> >  private void reset( int op ){
> >         done();
> >         _buffer.reset();
> >         set( _buffer );
>
> >         *if(ID == null) ID = new AtomicInteger(1); <== Here I added*
> >         *_id = ID.getAndIncrement(); <= exception point*
>

Scott Hernandez

unread,
May 16, 2011, 2:38:59 PM5/16/11
to mongod...@googlegroups.com
Yeah, doesn't look like that code.

It is very strange as the ID is a static and initialized at static construction (which is specified to happen before any method invocation -- static or instance).

class OutMessage extends BSONEncoder {


    static AtomicInteger ID = new AtomicInteger(1);

...


Can you create a jira issue and we can see if we can reproduce it. Please specify as much about your environment as possible in the jira issue.

2011/5/16 Gregory Lee <leew...@gmail.com>
Reply all
Reply to author
Forward
0 new messages