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

Space in Database Name Should Be Considered Invalid

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Minor - P4 Minor - P4
    • 2.12.0, 3.0.0
    • None
    • API
    • None

    Description

      Per this documentation, database names should not include the space character. However, the driver will submit a database command that includes space and return a dubious response.

      Reproduction code against mongos:

      import com.mongodb.*;
       
      public class Test {
      	public static final String DBNAME = "test asdfasdf";
      	
      	public static void main( String[] args ) throws Exception {
      		Mongo mongo = new Mongo( "localhost", 27020 );
      		DB db = mongo.getDB( DBNAME );
      		db.getCollection( "test").insert(new BasicDBObject("a",1));
      	
      		try {
      		    db.requestStart();
      		    db.requestEnsureConnection();
      		    while (true) {
      		        try {
      		            mongo.dropDatabase( DBNAME );
      		            break;
      		        } catch (MongoException ex) {
      		        	ex.printStackTrace();
      		          // Do error handling, omitted for shortness here.
      		        }
      		    }
      		} finally {
      		    db.requestDone();
      		}
      	}
      }

      This will trigger a "ok should never be null" exception.

      Attachments

        Activity

          People

            Unassigned Unassigned
            stephen.lee Stephen Lee
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: