Handle null for StatusReply (#30728)

Fix specifically for Scala 2.12
This commit is contained in:
Justin Pihony 2021-10-07 11:46:31 -04:00 committed by GitHub
parent 0ebbaffe9b
commit c034d20993
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View file

@ -33,6 +33,13 @@ class StatusReplySpec extends AkkaSpec with ScalaFutures {
case _ => fail()
}
}
"not throw exception if null" in {
(null: StatusReply[_]) match {
case StatusReply.Success(_) => fail()
case StatusReply.Error(_) => fail()
case _ =>
}
}
"pattern match error with text" in {
StatusReply.Error("boho!") match {
case StatusReply.Error(_) =>

View file

@ -118,7 +118,7 @@ object StatusReply {
*/
def apply[T](value: T): StatusReply[T] = new StatusReply(ScalaSuccess(value))
def unapply(status: StatusReply[Any]): Option[Any] =
if (status.isSuccess) Some(status.getValue)
if (status != null && status.isSuccess) Some(status.getValue)
else None
}
@ -150,7 +150,7 @@ object StatusReply {
*/
def apply[T](exception: Throwable): StatusReply[T] = new StatusReply(ScalaFailure(exception))
def unapply(status: StatusReply[_]): Option[Throwable] =
if (status.isError) Some(status.getError)
if (status != null && status.isError) Some(status.getError)
else None
}