Skip to content

Commit 403d28d

Browse files
committed
[JAVA-263]: added NPE handling in rare edge case
1 parent dcfe3bd commit 403d28d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/main/com/mongodb/DBTCPConnector.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,12 @@ DBPort get( boolean keep , boolean slaveOk , ServerAddress hostNeeded ){
322322
}
323323
}
324324

325+
if (_masterPortPool == null) {
326+
// this should only happen in rare case that no master was ever found
327+
// may get here at startup if it's a read, slaveOk=true, and ALL servers are down
328+
throw new MongoException("Rare case where master=null, probably all servers are down");
329+
}
330+
325331
// use master
326332
DBPort p = _masterPortPool.get();
327333
if ( keep && _inRequest ) {

0 commit comments

Comments
 (0)