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

NPE on createIndex when the database name contains a "."

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.4.0
    • Affects Version/s: 2.13.0
    • Component/s: Command Operations
    • None

      I'm getting a NPE from the Mongo Java driver when calling createIndex on a DBCollection in a database which has a full stop (aka period, ".") in its name. Here's the exception ...

      java.lang.NullPointerException
      	at com.mongodb.DBCollectionImpl.createIndex(DBCollectionImpl.java:399)
      	at com.mongodb.DBCollection.createIndex(DBCollection.java:597)
      	at com.mongodb.DBCollection.createIndex(DBCollection.java:585)
      

      Here's a reproduction test case:

          @Test(expected = NullPointerException.class)
          public void reproduceIssueWithNamesContainingAFullStop() {
              String databaseName = "dbname-v1.1";
              String collectionName = "whatever";
      
              DB db = mongo.getDB(databaseName);
              DBCollection dbCollection = db.getCollection(collectionName);
      
              DBObject indexKeys = new BasicDBObject("aField", 1);
              DBObject indexOptions = new BasicDBObject("unique", true);
              
              dbCollection.createIndex(indexKeys);
              Assert.fail("Expected Mongo Java driver to throw a NPE here ...");
          }
      

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            colmmcd Colm McDonnell
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: