Repository: Kotlin/kotlinx.coroutines
File: integration-testing/src/withGuavaTest/kotlin/ListAllCoroutineThrowableSubclassesTest.kt (Kotlin)

Code before:
     * See #3328 for serialization rationale.
     */
    private val knownThrowables = setOf(
        "kotlinx.coroutines.TimeoutCancellationException",
        "kotlinx.coroutines.JobCancellationException",
        "kotlinx.coroutines.internal.UndeliveredElementException",
        "kotlinx.coroutines.CompletionHandlerException",
        "kotlinx.coroutines.DiagnosticCoroutineContextException",
        "kotlinx.coroutines.CoroutinesInternalError",
        "kotlinx.coroutines.channels.ClosedSendChannelException",
        "kotlinx.coroutines.channels.ClosedReceiveChannelException",
        "kotlinx.coroutines.flow.internal.ChildCancelledException",
        "kotlinx.coroutines.flow.internal.AbortFlowException",
    )

    @Test
    fun testThrowableSubclassesAreSerializable() {
        val classes = ClassPath.from(this.javaClass.classLoader)
            .getTopLevelClassesRecursive("kotlinx.coroutines");
        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())
    }
}


Review comment (suggestion):
```suggestion
                    "Throwable $throwable has non-serializable field $field")
```
The indentation is misleading.

Code after:
     * See #3328 for serialization rationale.
     */
    private val knownThrowables = setOf(
        "kotlinx.coroutines.TimeoutCancellationException",
        "kotlinx.coroutines.JobCancellationException",
        "kotlinx.coroutines.internal.UndeliveredElementException",
        "kotlinx.coroutines.CompletionHandlerException",
        "kotlinx.coroutines.DiagnosticCoroutineContextException",
        "kotlinx.coroutines.CoroutinesInternalError",
        "kotlinx.coroutines.channels.ClosedSendChannelException",
        "kotlinx.coroutines.channels.ClosedReceiveChannelException",
        "kotlinx.coroutines.flow.internal.ChildCancelledException",
        "kotlinx.coroutines.flow.internal.AbortFlowException",
    )

    @Test
    fun testThrowableSubclassesAreSerializable() {
        val classes = ClassPath.from(this.javaClass.classLoader)
            .getTopLevelClassesRecursive("kotlinx.coroutines");
        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())
    }
}