[JAVA-4711] IllegalStateException when trying to create an existing collection Created: 22/Aug/22  Updated: 28/Oct/23  Resolved: 24/Aug/22

Status: Closed
Project: Java Driver
Component/s: Reactive Streams
Affects Version/s: 4.7.0
Fix Version/s: 4.7.2

Type: Bug Priority: Major - P3
Reporter: Romain N/A Assignee: Jeffrey Yemin
Resolution: Fixed Votes: 0
Labels: regression
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Documentation Changes: Not Needed

 Description   

Summary

Hello everyone,

When attempting to create a new collection when it already exists, an IllegalStateException is thrown, in addition to the usual MongoCommandException.

This is a bug since the sync driver only throws the MongoCommandException, and this problem appears with the reactive streams driver since version 4.7.0 only.

How to Reproduce

 

MongoClient mongoClient = MongoClients.create();
MongoDatabase exampleDatabase = mongoClient.getDatabase("foo");
 
SubscriberHelpers.ObservableSubscriber<Void> voidSubscriber = new SubscriberHelpers.OperationSubscriber<>();
exampleDatabase.createCollection("bar").subscribe(voidSubscriber);
voidSubscriber.await(); 

 

If the collection already exists, you should see this stack trace: https://gist.github.com/Romitou/f552416d07f9608e2ddbecfa5c03e309

Additional Background

As said before, this bug only appears from version 4.7.0 and only on the reactive streams driver, I think this is relevant information.



 Comments   
Comment by Githook User [ 24/Aug/22 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@mongodb.com', 'username': 'jyemin'}

Message: Fix double connection release on error for drop and create collection operations (#993)

JAVA-4711
Branch: 4.7.x
https://github.com/mongodb/mongo-java-driver/commit/eb22d740979717ad3d78139378db2c49f2341aee

Comment by Jeffrey Yemin [ 23/Aug/22 ]

Most likely introduced by this commit: https://github.com/mongodb/mongo-java-driver/commit/11484607b8d5f3888f4335f939e02ceb58952eae

Comment by Jeffrey Yemin [ 23/Aug/22 ]

Thanks for the report. I was able to reproduce it. It appears that the correct exception is still returned to the caller, but the IllegalStateException is thrown synchronously and logged. It appears to be functionally harmless, but will double-check that. Regardless, it should be fixed as it makes for confusing log messages.

Generated at Thu Feb 08 09:02:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.