Different namespaces of CancellationException point to the same thing in JVM

There are two CancellationException:

kotlinx.coroutines.CancellationException
kotlin.coroutines.cancellation.CancellationException

In kotlin JVM they both point to the same thing:

public actual typealias CancellationException = java.util.concurrent.CancellationException

And hence both are seen as type of the class when cancellation exception is thrown.

GT-Sandbox-Snapshot

Code

package com.glassthought.sandbox

import com.glassthought.sandbox.util.out.impl.out
import kotlinx.coroutines.*
import java.lang.Exception
import kotlin.time.Duration.Companion.milliseconds

fun main(): kotlin.Unit = runBlocking {

  supervisorScope {
    val job = launch {

      try {
        out.delay(1000.milliseconds)
      } catch (e: Exception) {
        out.info("Got exception: ${e::class.simpleName}: ${e.message}")

        // public actual typealias CancellationException = java.util.concurrent.CancellationException
        if (e is kotlinx.coroutines.CancellationException){
          out.infoBlue("it is kotlinx.coroutines.CancellationException")
        }
        // @SinceKotlin("1.4")
        //public actual typealias CancellationException = java.util.concurrent.CancellationException
        if (e is kotlin.coroutines.cancellation.CancellationException){
          out.infoBlue("it is kotlin.coroutines.cancellation.CancellationException")
        }

        throw e
      }
    }

    delay(50.milliseconds)
    job.cancel()
  }


}

Command to reproduce:

gt.sandbox.checkout.commit 661fdc95cea8d9b181f8 \
&& cd "${GT_SANDBOX_REPO}" \
&& cmd.run.announce "./gradlew run --quiet"

Recorded output of command:

Picked up JAVA_TOOL_OPTIONS: -Dkotlinx.coroutines.debug
Picked up JAVA_TOOL_OPTIONS: -Dkotlinx.coroutines.debug
[INFO][elapsed:   15ms][①][coroutname:@coroutine#2] [🐢] Delaying for [1s]
[WARN][elapsed:   88ms][①][coroutname:@coroutine#2] 🫡 I have caught [JobCancellationException/StandaloneCoroutine was cancelled], and rethrowing it 🫡
[INFO][elapsed:   89ms][①][coroutname:@coroutine#2] Got exception: JobCancellationException: StandaloneCoroutine was cancelled
[elapsed:   89ms][①][coroutname:@coroutine#2] it is kotlinx.coroutines.CancellationException
[elapsed:   89ms][①][coroutname:@coroutine#2] it is kotlin.coroutines.cancellation.CancellationException

Backlinks