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

NullPointerException when authentication used with replica sets not logged correctly

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.4, 2.5
    • Fix Version/s: 2.5
    • Component/s: Cluster Management
    • Labels:
      None
    • Environment:
      OS X 10.6.6, Java driver. 3-node replica set with user authentication (--auth) (and replica authentication --keyFile)
    • # Replies:
      3
    • Last comment by Customer:
      true

      Description

      If you try use the java driver to connect to a database that requires authentication, a NullPointerException is thrown and caught in Node.update(). This is because at the point the update is attempted, the java code has yet to call the DB.authenticate() method. Because the exception is already caught, it is not preventing anything from working. However the code should handle this better so as to not generate a NPE in the first place.

      String setName = config.get("_id").toString(); // <-- .toString() triggers NPE if DB.authenticate() hasn't yet been called.
      if ( _setName == null )

      { _setName = setName; _logger = Logger.getLogger( _rootLogger.getName() + "." + setName ); }

      Inspecting config shows it has $err defined (unauthenticated message) as well as code (10057). Suggest checking if null first, then checking if an error exists and if it's not authentication related, only then show the user. Another alternative would be to have DBPort check for the condition first and then throw a MongoInternalException.

      static final int UNAUTHENTICATED_ERROR_CODE = 10057;
      ...

      Object setNameObj = config.get("_id");
      if (setNameObj == null) {
      if (config.get("$err") != null && UNAUTHENTICATED_ERROR_CODE != (Integer)config.get("code"))

      { _logger.log( Level.SEVERE, "can't get set name from node: " +_addr + ". Error: " + config.get("$err")); }

      return;
      }
      String setName = setNameObj.toString();

      Stack Trace (based on git head, commit a052b4f35af4069121cbf47adc88d6199563c4d4):

      Feb 10, 2011 3:53:17 PM com.mongodb.ReplicaSetStatus$Node update
      SEVERE: unexpected error getting config from node: 10.211.55.23:23003
      java.lang.NullPointerException
      at com.mongodb.ReplicaSetStatus$Node.update(ReplicaSetStatus.java:174)
      at com.mongodb.ReplicaSetStatus.updateAll(ReplicaSetStatus.java:287)
      at com.mongodb.ReplicaSetStatus$Updater.run(ReplicaSetStatus.java:248)
      Feb 10, 2011 3:53:17 PM com.mongodb.ReplicaSetStatus$Node update
      SEVERE: unexpected error getting config from node: 10.211.55.23:23003
      java.lang.NullPointerException
      at com.mongodb.ReplicaSetStatus$Node.update(ReplicaSetStatus.java:174)
      at com.mongodb.ReplicaSetStatus.updateAll(ReplicaSetStatus.java:287)
      at com.mongodb.ReplicaSetStatus.ensureMaster(ReplicaSetStatus.java:280)
      at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:364)
      at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:206)
      at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:271)
      at com.mongodb.DB.command(DB.java:154)
      at com.mongodb.DB.command(DB.java:139)
      at com.mongodb.DB._doauth(DB.java:469)
      at com.mongodb.DB.authenticate(DB.java:434)

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since reply:
                6 years, 32 weeks, 6 days ago
                Date of 1st Reply: