Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark context in DiagnosticCoroutineContextException as transient #3370

Merged
merged 2 commits into from Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -7,6 +7,8 @@ package kotlinx.coroutines
import com.google.common.reflect.*
import kotlinx.coroutines.*
import org.junit.Test
import java.io.Serializable
import java.lang.reflect.Modifier
import kotlin.test.*

class ListAllCoroutineThrowableSubclassesTest {
Expand All @@ -31,13 +33,21 @@ class ListAllCoroutineThrowableSubclassesTest {
"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")
qwwdfsad marked this conversation as resolved.
Show resolved Hide resolved
}
}
assertEquals(knownThrowables.sorted(), throwables.sorted())
}
}
Expand Up @@ -29,7 +29,7 @@ private val handlers: List<CoroutineExceptionHandler> = ServiceLoader.load(
* The purpose of this exception is to add an otherwise inaccessible diagnostic information and to
* be able to poke the failing coroutine context in the debugger.
*/
private class DiagnosticCoroutineContextException(private val context: CoroutineContext) : RuntimeException() {
private class DiagnosticCoroutineContextException(@Transient private val context: CoroutineContext) : RuntimeException() {
override fun getLocalizedMessage(): String {
return context.toString()
}
Expand Down