[JAVA-382] NPE in ReplicaSetStatus.ensureMaster Created: 16/Jun/11  Updated: 10/Aug/11  Resolved: 23/Jun/11

Status: Closed
Project: Java Driver
Component/s: Cluster Management
Affects Version/s: 2.5.3
Fix Version/s: 2.6.4

Type: Bug Priority: Major - P3
Reporter: Jon Ivmark Assignee: Antoine Girbal
Resolution: Done Votes: 0
Labels: concurrency, replication
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File JAVA-382.patch    

 Description   

After initializing a Mongo object I sometimes get a NPE when I first try to use that instance.

java.lang.NullPointerException
at
com.mongodb.ReplicaSetStatus.ensureMaster(ReplicaSetStatus.java:301)
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:
383)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:192)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:
295)
at com.mongodb.DB.getCollectionNames(DB.java:259)
at com.mongodb.DB.collectionExists(DB.java:300)
at
net.avail.db.mongodb.MongoHourlyMetricsAggregator.ensureCollectionsExists(MongoHourlyMetricsAggregator.java:
43)

Expected:

Better concurrency handling and on an unexpected error such as no master found a more descriptive exception than a NPE.



 Comments   
Comment by auto [ 23/Jun/11 ]

Author:

{u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}

Message: JAVA-382: NPE in ReplicaSetStatus.ensureMaster
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/719b6b7851f9b50b918f232027e1c55f9c33772c

Comment by Jon Ivmark [ 22/Jun/11 ]

I got the same exception using 2.6.3:

java.lang.NullPointerException
at com.mongodb.ReplicaSetStatus.ensureMaster(ReplicaSetStatus.java:318)
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:393)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:198)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:296)
at com.mongodb.DB.getCollectionNames(DB.java:259)
at com.mongodb.DB.collectionExists(DB.java:300)
at net.avail.db.mongodb.MongoHourlyMetricsAggregator.ensureCollectionsExists(MongoHourlyMetricsAggregator.java:43)

The patch solves the NPE (and now a MongoException will be thrown insterad?), but why is there no master node found initially? How are you supposed to handle this on the client, catch MongoException and retry can't really be the recommended way?

Jon

Comment by Testo [ 20/Jun/11 ]

add the patch

Generated at Thu Feb 08 08:52:09 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.