[JAVA-180] NullPointerException when calling Mongo.close() on unpaired server Created: 09/Oct/10  Updated: 29/Oct/10  Resolved: 09/Oct/10

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: 2.2
Fix Version/s: 2.3

Type: Bug Priority: Major - P3
Reporter: Robert Stewart Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

OS X 10.6



 Description   

A NullPointerException is thrown in DBTCPConnector.close() due to _rsStatus being null when _rsStatus.close() is called.

If you call the constructor

public Mongo( ServerAddress addr , MongoOptions options )

then, the constructor is called:

public DBTCPConnector( Mongo m , ServerAddress addr )

if the ServerAddress is not paired, then the following code sets _rsStatus to null:

if ( addr.isPaired() )

{ _allHosts = new ArrayList<ServerAddress>( addr.explode() ); _rsStatus = new ReplicaSetStatus( m , _allHosts ); _createLogger.info( "switching to replica set mode : " + _allHosts + " -> " + _curMaster ); }

else

{ _set( addr ); _allHosts = null; _rsStatus = null; }

when DBTCPConnector.close() is eventually called, _rsStatus.close() throws an NPE.

Although _portHolder should never be null, I think it is worth checking it before calling close() on it, as well.

I'll submit a pull request from my fork at http://github.com/RobertStewart/mongo-java-driver.



 Comments   
Comment by auto [ 09/Oct/10 ]

Author:

{'login': 'erh', 'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}

Message: fix possible NPE JAVA-180
http://github.com/mongodb/mongo-java-driver/commit/8aa710c343af52c96f2c225ce32fc601e3c9390c

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