-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 2.4, 2.5
-
Component/s: Cluster Management
-
None
-
Environment:OS X 10.6.6, Java driver. 3-node replica set with user authentication (--auth) (and replica authentication --keyFile)
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 )
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"))
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)