Support for null in mapAsync and fromCompletionStage #25475

This commit is contained in:
mszczygiel 2019-04-16 09:08:05 +02:00 committed by Johan Andrén
parent 549ccb78a6
commit d4813b91c3
9 changed files with 134 additions and 48 deletions

View file

@ -1208,10 +1208,7 @@ private[stream] object Collect {
}
def setElem(t: Try[T]): Unit = {
elem = t match {
case Success(null) => Failure[T](ReactiveStreamsCompliance.elementMustNotBeNullException)
case other => other
}
elem = t
}
override def apply(t: Try[T]): Unit = {
@ -1297,10 +1294,14 @@ private[stream] object Collect {
else if (isAvailable(out)) {
val holder = buffer.dequeue()
holder.elem match {
case Success(elem) =>
case Success(elem) if elem != null =>
push(out, elem)
pullIfNeeded()
case Success(null) =>
pullIfNeeded()
pushNextIfPossible()
case Failure(NonFatal(ex)) =>
holder.supervisionDirectiveFor(decider, ex) match {
// this could happen if we are looping in pushNextIfPossible and end up on a failed future before the
@ -1356,11 +1357,10 @@ private[stream] object Collect {
if (!hasBeenPulled(in)) tryPull(in)
push(out, elem)
} else buffer.enqueue(elem)
case other =>
val ex = other match {
case Failure(t) => t
case Success(s) if s == null => ReactiveStreamsCompliance.elementMustNotBeNullException
}
case Success(null) =>
if (isClosed(in) && todo == 0) completeStage()
else if (!hasBeenPulled(in)) tryPull(in)
case Failure(ex) =>
if (decider(ex) == Supervision.Stop) failStage(ex)
else if (isClosed(in) && todo == 0) completeStage()
else if (!hasBeenPulled(in)) tryPull(in)