Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-180

NullPointerException when calling Mongo.close() on unpaired server

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.3
    • Affects Version/s: 2.2
    • Component/s: None
    • None
    • Environment:
      OS X 10.6

      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.

            Assignee:
            eliot Eliot Horowitz (Inactive)
            Reporter:
            robertstewart Robert Stewart
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: