Skip to content

Commit 37b95a9

Browse files
authored
Simplify JobNode.toString to reduce code and avoid potential StackOverflow (#2377)
Fixes #2371
1 parent addff4b commit 37b95a9

File tree

3 files changed

+1
-14
lines changed

3 files changed

+1
-14
lines changed

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

+1-12
Original file line numberDiff line numberDiff line change
@@ -1151,8 +1151,6 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
11511151
override fun invoke(cause: Throwable?) {
11521152
parent.continueCompleting(state, child, proposedUpdate)
11531153
}
1154-
override fun toString(): String =
1155-
"ChildCompletion[$child, $proposedUpdate]"
11561154
}
11571155

11581156
private class AwaitContinuation<T>(
@@ -1350,6 +1348,7 @@ internal abstract class JobNode<out J : Job>(
13501348
override val isActive: Boolean get() = true
13511349
override val list: NodeList? get() = null
13521350
override fun dispose() = (job as JobSupport).removeNode(this)
1351+
override fun toString() = "$classSimpleName@$hexAddress[job@${job.hexAddress}]"
13531352
}
13541353

13551354
internal class NodeList : LockFreeLinkedListHead(), Incomplete {
@@ -1384,15 +1383,13 @@ private class InvokeOnCompletion(
13841383
private val handler: CompletionHandler
13851384
) : JobNode<Job>(job) {
13861385
override fun invoke(cause: Throwable?) = handler.invoke(cause)
1387-
override fun toString() = "InvokeOnCompletion[$classSimpleName@$hexAddress]"
13881386
}
13891387

13901388
private class ResumeOnCompletion(
13911389
job: Job,
13921390
private val continuation: Continuation<Unit>
13931391
) : JobNode<Job>(job) {
13941392
override fun invoke(cause: Throwable?) = continuation.resume(Unit)
1395-
override fun toString() = "ResumeOnCompletion[$continuation]"
13961393
}
13971394

13981395
private class ResumeAwaitOnCompletion<T>(
@@ -1411,15 +1408,13 @@ private class ResumeAwaitOnCompletion<T>(
14111408
continuation.resume(state.unboxState() as T)
14121409
}
14131410
}
1414-
override fun toString() = "ResumeAwaitOnCompletion[$continuation]"
14151411
}
14161412

14171413
internal class DisposeOnCompletion(
14181414
job: Job,
14191415
private val handle: DisposableHandle
14201416
) : JobNode<Job>(job) {
14211417
override fun invoke(cause: Throwable?) = handle.dispose()
1422-
override fun toString(): String = "DisposeOnCompletion[$handle]"
14231418
}
14241419

14251420
private class SelectJoinOnCompletion<R>(
@@ -1431,7 +1426,6 @@ private class SelectJoinOnCompletion<R>(
14311426
if (select.trySelect())
14321427
block.startCoroutineCancellable(select.completion)
14331428
}
1434-
override fun toString(): String = "SelectJoinOnCompletion[$select]"
14351429
}
14361430

14371431
private class SelectAwaitOnCompletion<T, R>(
@@ -1443,7 +1437,6 @@ private class SelectAwaitOnCompletion<T, R>(
14431437
if (select.trySelect())
14441438
job.selectAwaitCompletion(select, block)
14451439
}
1446-
override fun toString(): String = "SelectAwaitOnCompletion[$select]"
14471440
}
14481441

14491442
// -------- invokeOnCancellation nodes
@@ -1463,7 +1456,6 @@ private class InvokeOnCancelling(
14631456
override fun invoke(cause: Throwable?) {
14641457
if (_invoked.compareAndSet(0, 1)) handler.invoke(cause)
14651458
}
1466-
override fun toString() = "InvokeOnCancelling[$classSimpleName@$hexAddress]"
14671459
}
14681460

14691461
internal class ChildHandleNode(
@@ -1472,7 +1464,6 @@ internal class ChildHandleNode(
14721464
) : JobCancellingNode<JobSupport>(parent), ChildHandle {
14731465
override fun invoke(cause: Throwable?) = childJob.parentCancelled(job)
14741466
override fun childCancelled(cause: Throwable): Boolean = job.childCancelled(cause)
1475-
override fun toString(): String = "ChildHandle[$childJob]"
14761467
}
14771468

14781469
// Same as ChildHandleNode, but for cancellable continuation
@@ -1483,7 +1474,5 @@ internal class ChildContinuation(
14831474
override fun invoke(cause: Throwable?) {
14841475
child.parentCancelled(child.getContinuationCancellationCause(job))
14851476
}
1486-
override fun toString(): String =
1487-
"ChildContinuation[$child]"
14881477
}
14891478

kotlinx-coroutines-core/common/src/selects/Select.kt

-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ internal class SelectBuilderImpl<in R>(
339339
if (trySelect())
340340
resumeSelectWithException(job.getCancellationException())
341341
}
342-
override fun toString(): String = "SelectOnCancelling[${this@SelectBuilderImpl}]"
343342
}
344343

345344
@PublishedApi

kotlinx-coroutines-core/jvm/src/Future.kt

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ private class CancelFutureOnCompletion(
4141
// interruption flag and it will cause spurious failures elsewhere
4242
future.cancel(false)
4343
}
44-
override fun toString() = "CancelFutureOnCompletion[$future]"
4544
}
4645

4746
private class CancelFutureOnCancel(private val future: Future<*>) : CancelHandler() {

0 commit comments

Comments
 (0)