-
Type: Bug
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: Async, Query Operations
-
None
-
Environment:mongo-scala-driver 2.6.0
mongoDB 4.0
Calling `.distinct` on a collection with a non-sparse index on a field, that is missing from at least one document, results in a NullPointerException. The reason is that due to the index not being sparse, null is added to the distinct values for the missing field. `AbstractSubscription` checks if the entire returned array is null (which it isn't), but not the individual elements. `resultsQueue.addAll(results)` then fails with an NPE.
Steps to reproduce:
```scala
val db = client.getDatabase("foo")
val coll = db.getCollection[Document]("bar")
for
yield dist should contain theSameElementsAs Seq(null)
```
```
10:27:42.110 [zio-default-async-6-352707738] DEBUG o.m.d.p.command - Sending command '{"distinct": "bar", "key": "a", "$db": "foo", "$readPreference": {"mode": "primaryPreferred"}}' with request id 10 to database foo on connection [connectionId
] to server localhost:12345
10:27:42.111 [Thread-20] DEBUG o.m.d.p.command - Execution of command with request id 10 completed successfully in 1.78 ms on connection [connectionId
] to server localhost:12345
10:27:42.115 [Thread-20] ERROR o.m.d.client - Callback onResult call produced an error
java.lang.NullPointerException: null
at java.util.concurrent.ConcurrentLinkedQueue.checkNotNull(ConcurrentLinkedQueue.java:920)
at java.util.concurrent.ConcurrentLinkedQueue.addAll(ConcurrentLinkedQueue.java:531)
at com.mongodb.async.client.AbstractSubscription.addToQueue(AbstractSubscription.java:116)
at com.mongodb.async.client.MongoIterableSubscription$2.onResult(MongoIterableSubscription.java:95)
at com.mongodb.async.client.MongoIterableSubscription$2.onResult(MongoIterableSubscription.java:85)
...
```
- related to
-
JAVA-3382 Observables should filter null values
- Closed