@@ -641,15 +641,16 @@ internal open class JobSupport constructor(active: Boolean) : Job, SelectClause0
641
641
private fun isCorrespondinglyCancelled (cancelled : Cancelled , proposedUpdate : Any? ): Boolean {
642
642
if (proposedUpdate !is Cancelled ) return false
643
643
// NOTE: equality comparison of causes is performed here by design, see equals of JobCancellationException
644
- return proposedUpdate.cause == cancelled.cause ||
645
- proposedUpdate.cause is JobCancellationException && cancelled.isCancelledWithoutCause()
644
+ return proposedUpdate.cause == cancelled.cause || proposedUpdate.cause is JobCancellationException
646
645
}
647
646
648
647
private fun createCancelled (cancelled : Cancelled , proposedUpdate : Any? ): Cancelled {
649
648
if (proposedUpdate !is CompletedExceptionally ) return cancelled // not exception -- just use original cancelled
650
- val exception = proposedUpdate.exception
651
- if (cancelled.exception == exception) return cancelled // that is the cancelled we need already!
652
- if (! cancelled.isCancelledWithoutCause()) {
649
+ val exception = proposedUpdate.cause
650
+ if (cancelled.cause == exception) return cancelled // that is the cancelled we need already!
651
+
652
+ // Do not spam with JCE in suppressed exceptions
653
+ if (cancelled.cause !is JobCancellationException ) {
653
654
exception.addSuppressedThrowable(cancelled.cause)
654
655
}
655
656
return Cancelled (this , exception)
@@ -752,11 +753,11 @@ internal open class JobSupport constructor(active: Boolean) : Job, SelectClause0
752
753
val state = this .state
753
754
return when {
754
755
state is Finishing && state.cancelled != null ->
755
- state.cancelled.exception .toCancellationException(" Job is being cancelled" )
756
+ state.cancelled.cause .toCancellationException(" Job is being cancelled" )
756
757
state is Incomplete ->
757
758
error(" Job was not completed or cancelled yet: $this " )
758
759
state is CompletedExceptionally ->
759
- state.exception .toCancellationException(" Job has failed" )
760
+ state.cause .toCancellationException(" Job has failed" )
760
761
else -> JobCancellationException (" Job has completed normally" , null , this )
761
762
}
762
763
}
@@ -766,21 +767,14 @@ internal open class JobSupport constructor(active: Boolean) : Job, SelectClause0
766
767
767
768
/* *
768
769
* Returns the cause that signals the completion of this job -- it returns the original
769
- * [cancel] cause or **`null` if this job had completed
770
- * normally or was cancelled without a cause**. This function throws
771
- * [IllegalStateException] when invoked for an job that has not [completed][isCompleted] nor
770
+ * [cancel] cause, [JobCancellationException] or **`null` if this job had completed normally**.
771
+ * This function throws [IllegalStateException] when invoked for an job that has not [completed][isCompleted] nor
772
772
* [isCancelled] yet.
773
773
*/
774
774
protected fun getCompletionCause (): Throwable ? {
775
775
val state = this .state
776
776
return when {
777
- state is Finishing && state.cancelled != null -> {
778
- if (state.cancelled.isCancelledWithoutCause()) {
779
- null
780
- } else {
781
- state.cancelled.cause
782
- }
783
- }
777
+ state is Finishing && state.cancelled != null -> state.cancelled.cause
784
778
state is Incomplete -> error(" Job was not completed or cancelled yet" )
785
779
state is CompletedExceptionally -> state.cause
786
780
else -> null
@@ -1060,7 +1054,7 @@ internal open class JobSupport constructor(active: Boolean) : Job, SelectClause0
1060
1054
}
1061
1055
// cancel all children in list on exceptional completion
1062
1056
if (proposedUpdate is CompletedExceptionally )
1063
- child?.cancelChildrenInternal(proposedUpdate.exception )
1057
+ child?.cancelChildrenInternal(proposedUpdate.cause )
1064
1058
// switch to completing state
1065
1059
val cancelled = (state as ? Finishing )?.cancelled ? : (proposedUpdate as ? Cancelled )
1066
1060
val completing = Finishing (list, cancelled, true )
@@ -1080,7 +1074,7 @@ internal open class JobSupport constructor(active: Boolean) : Job, SelectClause0
1080
1074
}
1081
1075
1082
1076
private val Any? .exceptionOrNull: Throwable ?
1083
- get() = (this as ? CompletedExceptionally )?.exception
1077
+ get() = (this as ? CompletedExceptionally )?.cause
1084
1078
1085
1079
private fun firstChild (state : Incomplete ) =
1086
1080
state as ? Child ? : state.list?.nextChild()
@@ -1232,7 +1226,7 @@ internal open class JobSupport constructor(active: Boolean) : Job, SelectClause0
1232
1226
internal fun getCompletedInternal (): Any? {
1233
1227
val state = this .state
1234
1228
check(state !is Incomplete ) { " This job has not completed yet" }
1235
- if (state is CompletedExceptionally ) throw state.exception
1229
+ if (state is CompletedExceptionally ) throw state.cause
1236
1230
return state
1237
1231
}
1238
1232
@@ -1245,7 +1239,7 @@ internal open class JobSupport constructor(active: Boolean) : Job, SelectClause0
1245
1239
val state = this .state
1246
1240
if (state !is Incomplete ) {
1247
1241
// already complete -- just return result
1248
- if (state is CompletedExceptionally ) throw state.exception
1242
+ if (state is CompletedExceptionally ) throw state.cause
1249
1243
return state
1250
1244
1251
1245
}
@@ -1259,7 +1253,7 @@ internal open class JobSupport constructor(active: Boolean) : Job, SelectClause0
1259
1253
val state = this .state
1260
1254
check(state !is Incomplete )
1261
1255
if (state is CompletedExceptionally )
1262
- cont.resumeWithException(state.exception )
1256
+ cont.resumeWithException(state.cause )
1263
1257
else
1264
1258
cont.resume(state)
1265
1259
})
@@ -1278,7 +1272,7 @@ internal open class JobSupport constructor(active: Boolean) : Job, SelectClause0
1278
1272
// already complete -- select result
1279
1273
if (select.trySelect(null )) {
1280
1274
if (state is CompletedExceptionally )
1281
- select.resumeSelectCancellableWithException(state.exception )
1275
+ select.resumeSelectCancellableWithException(state.cause )
1282
1276
else
1283
1277
block.startCoroutineUndispatched(state as T , select.completion)
1284
1278
}
@@ -1300,7 +1294,7 @@ internal open class JobSupport constructor(active: Boolean) : Job, SelectClause0
1300
1294
val state = this .state
1301
1295
// Note: await is non-atomic (can be cancelled while dispatched)
1302
1296
if (state is CompletedExceptionally )
1303
- select.resumeSelectCancellableWithException(state.exception )
1297
+ select.resumeSelectCancellableWithException(state.cause )
1304
1298
else
1305
1299
block.startCoroutineCancellable(state as T , select.completion)
1306
1300
}
0 commit comments