https://kotlinlang.org logo
Title
m

Martin Devillers

12/18/2018, 3:13 PM
Me again 🙂 This time I’m confused by some behavior involving
withContext
and
CompletableDeferred
.
This test fails because of the
[Failed]
exception which is thrown by the exception handler (which mimicks the default behavior on the Android platform by causing a crash). By completing a
CompletableDeferred
exceptionally after a timeout waiting for it, the exception gets propagated to the uncaught exception handler. I wouldn’t expect this, given the documentation of
CompletableDeferred.completeExceptionally
Actually, I find it especially strange that the `CompletableDeferred`’s handling of the exception passed in
completeExceptionally
changes simply due to the fact that
await
has been called on it, then cancelled. If
await
isn’t called, then there isn’t any failure.
This is particularly vicious because I don’t see any way to work around this issue. There’s no way to catch it when it’s thrown by the call to
completeExceptionally
, and there’s no way to know whether a crash will be caused when calling this method. I suspect a bug. If anybody can provide more insight on this, it would be greatly appreciated.
In case anyone is interested by this, it seems to be the same issue as https://github.com/Kotlin/kotlinx.coroutines/issues/893 (confirmed by testing on the
develop
branch)