[JAVA-2396] NullPointerException when dropping a collection Created: 24/Nov/16  Updated: 03/Jun/22  Resolved: 29/Nov/16

Status: Closed
Project: Java Driver
Component/s: Command Operations
Affects Version/s: 3.4.0-rc1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Francisco Alejandro Lozano López Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

JDK 1.8, Linux, Server is 3.2.4, client is 3.4.0-rc1


Issue Links:
Duplicate
duplicates JAVA-1644 NPE on createIndex when the database ... Closed

 Description   

```
Caused by: java.lang.NullPointerException
at com.mongodb.connection.ResponseBuffers.getBodyByteBuffer(ResponseBuffers.java:55)
at com.mongodb.connection.CommandProtocol.execute(CommandProtocol.java:113)
at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:168)
at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:289)
at com.mongodb.connection.DefaultServerConnection.command(DefaultServerConnection.java:176)
at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:216)
at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:207)
at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:146)
at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:139)
at com.mongodb.operation.DropCollectionOperation$1.call(DropCollectionOperation.java:94)
at com.mongodb.operation.DropCollectionOperation$1.call(DropCollectionOperation.java:90)
at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:422)
at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:413)
at com.mongodb.operation.DropCollectionOperation.execute(DropCollectionOperation.java:90)
at com.mongodb.operation.DropCollectionOperation.execute(DropCollectionOperation.java:51)
at com.mongodb.Mongo.execute(Mongo.java:844)
at com.mongodb.Mongo$2.execute(Mongo.java:827)
at com.mongodb.MongoCollectionImpl.drop(MongoCollectionImpl.java:448)
```



 Comments   
Comment by Jeffrey Yemin [ 29/Nov/16 ]

This has been fixed in the 3.4.0 release in scope of JAVA-1644. The driver now throws an IllegalArgumentException when the database name contains a space:

Exception in thread "main" java.lang.IllegalArgumentException: state should be: databaseName does not contain ' '
	at com.mongodb.assertions.Assertions.isTrueArgument(Assertions.java:99)
	at com.mongodb.MongoNamespace.checkDatabaseNameValidity(MongoNamespace.java:51)
	at com.mongodb.MongoDatabaseImpl.<init>(MongoDatabaseImpl.java:54)
	at com.mongodb.MongoClient.getDatabase(MongoClient.java:405)

Comment by Francisco Alejandro Lozano López [ 27/Nov/16 ]

Actually, we've checked and the database name contained a "space", which was wrong by itself (not sure it's even supported, but it wasn't intended in our side).

Comment by Jeffrey Yemin [ 25/Nov/16 ]

Thanks for the report.

What's the name of the database and collection that is being dropped when you get this exception?

Comment by Francisco Alejandro Lozano López [ 24/Nov/16 ]

we think the buffer is null because of this:

    private ResponseBuffers receiveResponseBuffers() throws IOException {
        ByteBuf headerByteBuffer = stream.read(REPLY_HEADER_LENGTH);
        ReplyHeader replyHeader;
        ByteBufferBsonInput headerInputBuffer = new ByteBufferBsonInput(headerByteBuffer);
        try {
            replyHeader = new ReplyHeader(headerInputBuffer, description.getMaxMessageSize());
        } finally {
            headerInputBuffer.close();
        }
 
        ByteBuf bodyByteBuffer = null;
 
        if (replyHeader.getNumberReturned() > 0) {
            bodyByteBuffer = stream.read(replyHeader.getMessageLength() - REPLY_HEADER_LENGTH);
        }
        return new ResponseBuffers(replyHeader, bodyByteBuffer);
    }

but no idea if this is expected or not, or if it's the server who's behaving incorrectly.

Generated at Thu Feb 08 08:57:06 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.