Skip to content

Commit 092d75e

Browse files
committed
SI-7616 Avoid ClassCastException in scala.concurrent.impl.ExecutionContextImpl
Adds test to scala-concurrent-tck
1 parent cbd2e54 commit 092d75e

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/library/scala/concurrent/impl/ExecutionContextImpl.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private[concurrent] object ExecutionContextImpl {
115115

116116
def fromExecutorService(es: ExecutorService, reporter: Throwable => Unit = ExecutionContext.defaultReporter): ExecutionContextImpl with ExecutionContextExecutorService =
117117
new ExecutionContextImpl(es, reporter) with ExecutionContextExecutorService {
118-
final def asExecutorService: ExecutorService = executor.right.asInstanceOf[ExecutorService]
118+
final def asExecutorService: ExecutorService = executor.right.get.asInstanceOf[ExecutorService]
119119
override def execute(command: Runnable) = executor.right.get.execute(command)
120120
override def shutdown() { asExecutorService.shutdown() }
121121
override def shutdownNow() = asExecutorService.shutdownNow()

test/files/jvm/scala-concurrent-tck.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,26 @@ trait ExecutionContextPrepare extends TestBase {
10271027
testMap()
10281028
}
10291029

1030+
trait ExecutorServiceExecutionContext extends TestBase {
1031+
import java.util.concurrent.Executors
1032+
import scala.concurrent.duration._
1033+
1034+
def testExecutorServiceEC(): Unit =
1035+
once { done =>
1036+
val ec = ExecutionContext.fromExecutorService(Executors.newCachedThreadPool)
1037+
val p = Promise[Boolean]()
1038+
ec.execute(new Runnable {
1039+
def run(): Unit = p.success(true)
1040+
})
1041+
assert(Await.result(p.future, 2.seconds))
1042+
ec.shutdown()
1043+
assert(true)
1044+
done()
1045+
}
1046+
1047+
testExecutorServiceEC()
1048+
}
1049+
10301050
object Test
10311051
extends App
10321052
with FutureCallbacks
@@ -1037,6 +1057,7 @@ with BlockContexts
10371057
with Exceptions
10381058
with CustomExecutionContext
10391059
with ExecutionContextPrepare
1060+
with ExecutorServiceExecutionContext
10401061
{
10411062
System.exit(0)
10421063
}

0 commit comments

Comments
 (0)