Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.

Commit fdce928

Browse files
committed
Protect all SingleResultCallback observables from NPE
SCALA-555
1 parent ca878d3 commit fdce928

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

driver/src/it/scala/org/mongodb/scala/SmokeTestISpec.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ class SmokeTestISpec extends RequiresMongoDBISpec with FuturesSpec {
4949
info("find first should return null if no documents")
5050
collection.find().first().futureValue shouldBe null // scalastyle:ignore
5151

52+
info("find should return an empty list")
53+
collection.find().futureValue shouldBe empty
54+
5255
info("Insert a document")
5356
collection.insertOne(document).futureValue should equal(Completed())
5457

driver/src/main/scala/org/mongodb/scala/ObservableImplicits.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,10 @@ trait ObservableImplicits {
442442
subscription.request(1)
443443
}
444444

445-
override def onError(throwable: Throwable): Unit = completeWith("onError", () => observer.onError(throwable))
445+
override def onError(throwable: Throwable): Unit = throwable match {
446+
case npe: NullPointerException => onComplete()
447+
case _ => completeWith("onError", () => observer.onError(throwable))
448+
}
446449

447450
override def onComplete(): Unit = {
448451
completeWith("onComplete", { () =>

0 commit comments

Comments
 (0)