[JAVA-1970] Deferred collection creation throws NPE Created: 18/Sep/15  Updated: 12/Nov/15  Resolved: 03/Nov/15

Status: Closed
Project: Java Driver
Component/s: Command Operations
Affects Version/s: 3.0.3, 3.0.4
Fix Version/s: 3.1.1, 3.2.0

Type: Bug Priority: Minor - P4
Reporter: Gordon Syme Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

com.mongodb.DB.createCollection is documented as deferring the collection creation if the options parameter is null.

This was the behaviour in 2.x

3.0.x fail with a NullPointerException because the options parameter is accessed in com.mongodb.DB.getCreateCollectionOperation without a null-check.



 Comments   
Comment by Jeffrey Yemin [ 12/Nov/15 ]

Closing for 3.1.1 release.

Comment by Githook User [ 07/Nov/15 ]

Author:

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

Message: JAVA-1970: In DB.createCollection method, defer collection creation if options is null, as per documentation
Branch: 3.1.x
https://github.com/mongodb/mongo-java-driver/commit/ded790a2a516efc191da212d2a6947538bd5375b

Comment by Githook User [ 03/Nov/15 ]

Author:

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

Message: JAVA-1970: In DB.createCollection method, defer collection creation if options is null, as per documentation
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/34182ebd6fd2d00cac619ed5452a989a46014c03

Comment by Gordon Syme [ 18/Sep/15 ]

Thanks for the info Jeff,

I'd already implemented your second suggestion but the first is nicer. I'll go with that instead.

Comment by Jeffrey Yemin [ 18/Sep/15 ]

Hi Gordon,

Thanks for the report. This is indeed a regression. Until it's fixed, I can offer two workarounds:

  1. If you want creation to be deferred, call DB#getCollection instead
  2. If you don't want creation to be deferred, call DB#createCollection with an empty DBObject as the second parameter.
Generated at Thu Feb 08 08:56:00 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.