Skip to content
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

Fix class cast exception during undispatched resume of cancellable co… #1967

Merged
merged 1 commit into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ internal fun <T> DispatchedTask<T>.resume(delegate: Continuation<T>, useMode: In
// slow-path - use delegate
val state = takeState()
val exception = getExceptionalResult(state)?.let { recoverStackTrace(it, delegate) }
val result = if (exception != null) Result.failure(exception) else Result.success(state as T)
val result = if (exception != null) Result.failure(exception) else Result.success(getSuccessfulResult<T>(state))
when (useMode) {
MODE_ATOMIC_DEFAULT -> delegate.resumeWith(result)
MODE_CANCELLABLE -> delegate.resumeCancellableWith(result)
Expand Down
12 changes: 12 additions & 0 deletions kotlinx-coroutines-core/common/test/CancellableResumeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,16 @@ class CancellableResumeTest : TestBase() {
yield() // to coroutine -- throws cancellation exception
finish(9)
}


@Test
fun testResumeUnconfined() = runTest {
qwwdfsad marked this conversation as resolved.
Show resolved Hide resolved
val outerScope = this
withContext(Dispatchers.Unconfined) {
val result = suspendCancellableCoroutine<String> {
outerScope.launch { it.resume("OK", {}) }
}
assertEquals("OK", result)
}
}
}