New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Future.failed(th).failure returns incorrect value #10034

Closed
scabug opened this Issue Nov 8, 2016 · 5 comments

Comments

Projects
None yet
2 participants
@scabug
Copy link

scabug commented Nov 8, 2016

Regression:

Future.failure(new Exception()).failed does not return a successful future containing the failure, in contrast to Future(new Exception()).failed, which does—the latter being the expected behavior.

{code}scala-core $ sbt console
[info] Starting scala interpreter...
Welcome to Scala 2.12.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_74).
Type in expressions for evaluation. Or try :help.

scala> import scala.concurrent._
import scala.concurrent._

scala> import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.ExecutionContext.Implicits.global

scala> val f = Future.failed(new Exception("error"))
f: scala.concurrent.Future[Nothing] = Future(Failure(java.lang.Exception: error))

scala> f.failed
res0: scala.concurrent.Future[Throwable] = Future(Failure(java.lang.Exception: error))

scala> val f = Future(throw new Exception("error"))
f: scala.concurrent.Future[Nothing] = Future()

scala> f
res1: scala.concurrent.Future[Nothing] = Future(Failure(java.lang.Exception: error))

scala> f.failed
res2: scala.concurrent.Future[Throwable] = Future(Success(java.lang.Exception: error)){code}

Note how res2 differs from res0, even though they both operate on what look like equivalent failed futures (f and res1)

This is because the offending line (https://github.com/scala/scala/blob/2.12.x/src/library/scala/concurrent/impl/Promise.scala#L387)
casts the future without switching the Failure to a Success.

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Nov 8, 2016

Imported From: https://issues.scala-lang.org/browse/SI-10034?orig=1
Reporter: Jeff Reinecke (paploo)
Affected Versions: 2.12.0

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Nov 8, 2016

Viktor Klang (viktorklang) said:
Thank you so much for finding, diagnosing and reporting this issue.
Apologies for the inconvenience, it was a combination of a bad test case with a non-happy-path value.

https://github.com/scala/scala/pull/5507/files

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Nov 8, 2016

Jeff Reinecke (paploo) said:
I think that was the fastest bug ticket response I've ever had! Looks perfect; hopefully this will make it into 2.12.1.

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Nov 8, 2016

Viktor Klang (viktorklang) said:
I believe that it is not as much the mistakes we make, but how we handle them, which defines us.

I apologize for the inconvenience, and thank you for the report. I'd be very much surprised if it doesn't make it into 2.12.1.

@scabug scabug closed this Nov 10, 2016

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Nov 10, 2016

@scabug scabug added this to the 2.12.1 milestone Apr 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment