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

NullPointerException when calling Mongo.close() on unpaired server

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 2.3
    • 2.2
    • None
    • None
    • 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.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: