[JAVA-2386] Exception when a null value is included in the results of the distinct command Created: 16/Nov/16 Updated: 21/Nov/16 Resolved: 21/Nov/16 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Query Operations |
| Affects Version/s: | 3.3.0 |
| Fix Version/s: | 3.4.0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Jim Dunne | Assignee: | Ross Lawley |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
MongoDB server 3.2.8 Windows 7 x64 |
||
| Description |
|
Using the async Java driver and running a `distinct` query over a string-typed field that may contain null values results in `org.bson.BsonInvalidOperationException` being thrown. Example code using the `distinct` query operation, sanitized and simplified:
A workaround is available to filter out null values:
Exception:
|
| Comments |
| Comment by Ross Lawley [ 21/Nov/16 ] |
|
Thanks for the ticket jim.dunne, this is fixed in master and will be released as part of 3.4.0 |
| Comment by Githook User [ 21/Nov/16 ] |
|
Author: {u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}Message: Explicitly handle null values in the CommandResultArrayCodec Allows null values to be handled when using distinct |
| Comment by Jeffrey Yemin [ 17/Nov/16 ] |
|
Yes, you could use the BsonValue class, in which case you will get back a series of BsonString instances plus one BsonNull instance. |
| Comment by Jim Dunne [ 17/Nov/16 ] |
|
I get the same error when resultClass is BsonString.class. Is there a resultClass that would make this work without the not-null filter query? |
| Comment by Ross Lawley [ 17/Nov/16 ] |
|
Hi jim.dunne, Thats an interesting corner case for distinct as the results returned are strictly typed according to the resultClass and variants to that type are expected to fail. However, as always `null` is exceptional in Java! We'll look into a fix for the distinct method. Ross |