[JAVA-415] collection.remove() may return null when it should return WriteResult or throw an exception Created: 15/Aug/11 Updated: 12/Aug/12 Resolved: 12/Aug/12 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | API |
| Affects Version/s: | 2.6.5 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Christian pesch | Assignee: | Jeffrey Yemin |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows 7, MongoDB 1.8.2, Java Driver 2.6.5 |
||
| Description |
|
I'm experiencing <<null>> results when calling collection.remove(...) where the contract says that either a WriteResult is returned or an exception is thrown. I've tracked this down to DBTCPConnector#_checkWriteError that ends with WriteResult _checkWriteError( DB db , MyPort mp , DBPort port , WriteConcern concern ) if e.throwOnError(); does not throw an exception ( ok() || !hasErr()) return null; is returned. |
| Comments |
| Comment by Jeffrey Yemin [ 12/Aug/12 ] |
|
This was fixed in commit 3d5458e5fbbedd2381f3c675fc140eae94ea2949 |
| Comment by Christian pesch [ 16/May/12 ] |
|
No, I've refactored my code to not rely on the result anymore. IIRC the bug is in the checks of e.throwOnError(): If has to throw an exception and not check for conditions. |
| Comment by Jeffrey Yemin [ 15/May/12 ] |
|
Christian, apologies for taking so long to respond to this. I'm looking at the code and I don't see how this could happen. If e.hasErr() is true, then e.throwOnError() will throw an exception. The return of null at the end of _checkWriteError is just there to avoid a compilation error. Do you still have a test case than demonstrates the bug? |