Simplify JobNode.toString to reduce code and avoid potential StackOverflow (#2377)
Fixes #2371
diff --git a/kotlinx-coroutines-core/common/src/JobSupport.kt b/kotlinx-coroutines-core/common/src/JobSupport.kt
index 020d00a..5f21299 100644
--- a/kotlinx-coroutines-core/common/src/JobSupport.kt
+++ b/kotlinx-coroutines-core/common/src/JobSupport.kt
@@ -1151,8 +1151,6 @@
override fun invoke(cause: Throwable?) {
parent.continueCompleting(state, child, proposedUpdate)
}
- override fun toString(): String =
- "ChildCompletion[$child, $proposedUpdate]"
}
private class AwaitContinuation<T>(
@@ -1350,6 +1348,7 @@
override val isActive: Boolean get() = true
override val list: NodeList? get() = null
override fun dispose() = (job as JobSupport).removeNode(this)
+ override fun toString() = "$classSimpleName@$hexAddress[job@${job.hexAddress}]"
}
internal class NodeList : LockFreeLinkedListHead(), Incomplete {
@@ -1384,7 +1383,6 @@
private val handler: CompletionHandler
) : JobNode<Job>(job) {
override fun invoke(cause: Throwable?) = handler.invoke(cause)
- override fun toString() = "InvokeOnCompletion[$classSimpleName@$hexAddress]"
}
private class ResumeOnCompletion(
@@ -1392,7 +1390,6 @@
private val continuation: Continuation<Unit>
) : JobNode<Job>(job) {
override fun invoke(cause: Throwable?) = continuation.resume(Unit)
- override fun toString() = "ResumeOnCompletion[$continuation]"
}
private class ResumeAwaitOnCompletion<T>(
@@ -1411,7 +1408,6 @@
continuation.resume(state.unboxState() as T)
}
}
- override fun toString() = "ResumeAwaitOnCompletion[$continuation]"
}
internal class DisposeOnCompletion(
@@ -1419,7 +1415,6 @@
private val handle: DisposableHandle
) : JobNode<Job>(job) {
override fun invoke(cause: Throwable?) = handle.dispose()
- override fun toString(): String = "DisposeOnCompletion[$handle]"
}
private class SelectJoinOnCompletion<R>(
@@ -1431,7 +1426,6 @@
if (select.trySelect())
block.startCoroutineCancellable(select.completion)
}
- override fun toString(): String = "SelectJoinOnCompletion[$select]"
}
private class SelectAwaitOnCompletion<T, R>(
@@ -1443,7 +1437,6 @@
if (select.trySelect())
job.selectAwaitCompletion(select, block)
}
- override fun toString(): String = "SelectAwaitOnCompletion[$select]"
}
// -------- invokeOnCancellation nodes
@@ -1463,7 +1456,6 @@
override fun invoke(cause: Throwable?) {
if (_invoked.compareAndSet(0, 1)) handler.invoke(cause)
}
- override fun toString() = "InvokeOnCancelling[$classSimpleName@$hexAddress]"
}
internal class ChildHandleNode(
@@ -1472,7 +1464,6 @@
) : JobCancellingNode<JobSupport>(parent), ChildHandle {
override fun invoke(cause: Throwable?) = childJob.parentCancelled(job)
override fun childCancelled(cause: Throwable): Boolean = job.childCancelled(cause)
- override fun toString(): String = "ChildHandle[$childJob]"
}
// Same as ChildHandleNode, but for cancellable continuation
@@ -1483,7 +1474,5 @@
override fun invoke(cause: Throwable?) {
child.parentCancelled(child.getContinuationCancellationCause(job))
}
- override fun toString(): String =
- "ChildContinuation[$child]"
}
diff --git a/kotlinx-coroutines-core/common/src/selects/Select.kt b/kotlinx-coroutines-core/common/src/selects/Select.kt
index 99c54f8..81d3745 100644
--- a/kotlinx-coroutines-core/common/src/selects/Select.kt
+++ b/kotlinx-coroutines-core/common/src/selects/Select.kt
@@ -339,7 +339,6 @@
if (trySelect())
resumeSelectWithException(job.getCancellationException())
}
- override fun toString(): String = "SelectOnCancelling[${this@SelectBuilderImpl}]"
}
@PublishedApi
diff --git a/kotlinx-coroutines-core/jvm/src/Future.kt b/kotlinx-coroutines-core/jvm/src/Future.kt
index bd16f49..58792ce 100644
--- a/kotlinx-coroutines-core/jvm/src/Future.kt
+++ b/kotlinx-coroutines-core/jvm/src/Future.kt
@@ -41,7 +41,6 @@
// interruption flag and it will cause spurious failures elsewhere
future.cancel(false)
}
- override fun toString() = "CancelFutureOnCompletion[$future]"
}
private class CancelFutureOnCancel(private val future: Future<*>) : CancelHandler() {