Skip to content

Commit 8b244c2

Browse files
committed
KT-37232 workaround
1 parent 2ae053d commit 8b244c2

File tree

7 files changed

+26
-5
lines changed

7 files changed

+26
-5
lines changed

kotlinx-coroutines-core/common/src/CompletedExceptionally.kt

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ internal open class CompletedExceptionally(
3131
@JvmField public val cause: Throwable,
3232
handled: Boolean = false
3333
) {
34+
init { cause.fixupForSharing() } // KT-37232 workaround
35+
3436
private val _handled = atomic(handled)
3537
val handled: Boolean get() = _handled.value
3638
fun makeHandled(): Boolean = _handled.compareAndSet(false, true)

kotlinx-coroutines-core/common/src/JobSupport.kt

+3
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,8 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
10921092
isCompleting: Boolean,
10931093
rootCause: Throwable?
10941094
) : SynchronizedObject(), Incomplete {
1095+
init { rootCause.fixupForSharing() } // KT-37232 workaround
1096+
10951097
private val _isCompleting = atomic(isCompleting)
10961098
var isCompleting: Boolean
10971099
get() = _isCompleting.value
@@ -1135,6 +1137,7 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
11351137

11361138
// guarded by `synchronized(this)`
11371139
fun addExceptionLocked(exception: Throwable) {
1140+
exception.fixupForSharing() // KT-37232 workaround
11381141
val rootCause = this.rootCause // volatile read
11391142
if (rootCause == null) {
11401143
this.rootCause = exception

kotlinx-coroutines-core/common/src/channels/AbstractChannel.kt

+2
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,8 @@ internal class SendElement(
10671067
internal class Closed<in E>(
10681068
@JvmField val closeCause: Throwable?
10691069
) : Send(), ReceiveOrClosed<E> {
1070+
init { closeCause.fixupForSharing() } // KT-37232 workaround
1071+
10701072
val sendException: Throwable get() = closeCause ?: ClosedSendChannelException(DEFAULT_CLOSE_MESSAGE)
10711073
val receiveException: Throwable get() = closeCause ?: ClosedReceiveChannelException(DEFAULT_CLOSE_MESSAGE)
10721074

kotlinx-coroutines-core/common/src/internal/Sharing.common.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package kotlinx.coroutines.internal
@@ -24,3 +24,4 @@ internal expect fun <T> ArrayList<T>.addOrUpdate(element: T, update: (ArrayList<
2424
internal expect fun <T> ArrayList<T>.addOrUpdate(index: Int, element: T, update: (ArrayList<T>) -> Unit)
2525
internal expect fun Any.weakRef(): Any
2626
internal expect fun Any?.unweakRef(): Any?
27+
internal expect fun Throwable?.fixupForSharing() // KT-37232 workaround

kotlinx-coroutines-core/js/src/internal/Sharing.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package kotlinx.coroutines.internal
@@ -65,3 +65,6 @@ internal actual inline fun Any.weakRef(): Any = this
6565

6666
@Suppress("NOTHING_TO_INLINE") // Should be NOP
6767
internal actual inline fun Any?.unweakRef(): Any? = this
68+
69+
@Suppress("NOTHING_TO_INLINE") // Should be NOP
70+
internal actual inline fun Throwable?.fixupForSharing() {} // KT-37232 workaround

kotlinx-coroutines-core/jvm/src/internal/Sharing.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
@@ -83,3 +83,7 @@ internal actual inline fun Any.weakRef(): Any = this
8383
@InlineOnly
8484
@Suppress("NOTHING_TO_INLINE") // Should be NOP
8585
internal actual inline fun Any?.unweakRef(): Any? = this
86+
87+
@InlineOnly
88+
@Suppress("NOTHING_TO_INLINE") // Should be NOP
89+
internal actual inline fun Throwable?.fixupForSharing() {} // KT-37232 workaround

kotlinx-coroutines-core/native/src/internal/Sharing.kt

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package kotlinx.coroutines.internal
@@ -112,7 +112,13 @@ internal actual inline fun <T> ArrayList<T>.addOrUpdate(index: Int, element: T,
112112
@Suppress("NOTHING_TO_INLINE")
113113
internal actual inline fun Any.weakRef(): Any = WeakReference(this)
114114

115-
internal actual fun Any?.unweakRef(): Any? = (this as WeakReference<Any>?)?.get()
115+
@Suppress("NOTHING_TO_INLINE")
116+
internal actual inline fun Any?.unweakRef(): Any? = (this as WeakReference<Any>?)?.get()
117+
118+
@Suppress("NOTHING_TO_INLINE")
119+
internal actual inline fun Throwable?.fixupForSharing() {
120+
this?.getStackTrace() // KT-37232 workaround
121+
}
116122

117123
internal open class ShareableObject<T : Any>(obj: T) {
118124
val thread: Thread = currentThread()

0 commit comments

Comments
 (0)