[JAVA-863] gridFs.remove((DBObject)null) removes all elements from bucket Created: 04/Jul/13  Updated: 27/Feb/14  Resolved: 05/Dec/13

Status: Closed
Project: Java Driver
Component/s: GridFS
Affects Version/s: 2.11.2
Fix Version/s: 2.12.0, 3.0.0

Type: Bug Priority: Major - P3
Reporter: Micha S. Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
Java HotSpot(TM) Client VM (build 23.25-b01, mixed mode, sharing)
Mongodb version: 2.0.6
Java driver version: 2.11.2


Attachments: Text File Main.java    

 Description   

When passing null to GridFS.remove(DBObject dbobject) all files of the current bucket are removed. This is inconsistent compared to the other remove() methods of GridFS:

gridFs.remove((String)null); // nothing happens
gridFs.remove((ObjectId)null); // nothing happens
gridFs.remove((DBObject)null); // all files from bucket are removed

If this is intended behavior it should be documented in the javadoc comment.



 Comments   
Comment by Jeffrey Yemin [ 27/Feb/14 ]

Hi Micha,

Would you mind testing with 2.12.0-rc0, available either on github or Maven Central?

Thanks,
Jeff

Comment by Jeffrey Yemin [ 05/Dec/13 ]

All three remove methods in GridFS now throw IllegalArgumentException if the parameter value is null.

Comment by Githook User [ 05/Dec/13 ]

Author:

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

Message: JAVA-863: Added null checks in remove methods for GridFS.
Branch: 3.0.x
https://github.com/mongodb/mongo-java-driver/commit/06d7d907d64d130bc84242c8c4fcbc3ca20afafe

Comment by Githook User [ 05/Dec/13 ]

Author:

{u'username': u'neerajbhatt', u'name': u'neerajbhatt', u'email': u'neerajbhatt2000@gmail.com'}

Message: https://jira.mongodb.org/browse/JAVA-863, fixed null checks in remove method
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/4ef307e7ad9174e2ee138b01dcb2424017b9822d

Comment by Githook User [ 05/Dec/13 ]

Author:

{u'username': u'neerajbhatt', u'name': u'neerajbhatt', u'email': u'neerajbhatt2000@gmail.com'}

Message: https://jira.mongodb.org/browse/JAVA-863, fixed null checks in reove method
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/6fad5e473d6f37a640d36926ff66c8460d386cf2

Comment by Neeraj Bhatt [ 05/Dec/13 ]

Hi Jeff
I have raised a pull request to fix this bug

Comment by Jeffrey Yemin [ 25/Nov/13 ]

My preference is to change (and Javadoc, of course) all three methods to throw IllegalArgumentException if the parameter is null. This would more closely match the behavior of DBCollection.remove, which also throws if the query is null (though it throws an NPE, which we should also change).

Comment by Jeffrey Yemin [ 25/Nov/13 ]

Hi Micha,

We're going to look into doing something about this in the next release.

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