fun testThrowableSubclassesAreSerializable()

in integration-testing/src/jvmCoreTest/kotlin/ListAllCoroutineThrowableSubclassesTest.kt [38:54]


    fun testThrowableSubclassesAreSerializable() {
        val classes = ClassPath.from(this.javaClass.classLoader)
            .getTopLevelClassesRecursive("kotlinx.coroutines")
            // Not in the classpath: requires explicit dependency
            .filter { it.name != "kotlinx.coroutines.debug.CoroutinesBlockHoundIntegration"
                    && it.name != "kotlinx.coroutines.debug.junit5.CoroutinesTimeoutExtension" };
        val throwables = classes.filter { Throwable::class.java.isAssignableFrom(it.load()) }.map { it.toString() }
        for (throwable in throwables) {
            for (field in throwable.javaClass.declaredFields) {
                if (Modifier.isStatic(field.modifiers)) continue
                val type = field.type
                assertTrue(type.isPrimitive || Serializable::class.java.isAssignableFrom(type),
                    "Throwable $throwable has non-serializable field $field")
            }
        }
        assertEquals(knownThrowables.sorted(), throwables.sorted())
    }