-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Ensure that all coroutines throwables in core are serializable #3337
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e32aa78
Ensure that all coroutines throwables in core are serializable
qwwdfsad 188ab3d
Move ListAllCoroutineThrowableSubclassesTest to integration-testing a…
qwwdfsad 0f7bbfe
Get rid of LinkageError completely as it's no longer relevant
qwwdfsad 7b264ac
Update integration-testing/src/test/kotlin/ListAllCoroutineThrowableS…
qwwdfsad 4ff0411
Update integration-testing/src/test/kotlin/ListAllCoroutineThrowableS…
qwwdfsad 2d61ee7
Update integration-testing/src/test/kotlin/ListAllCoroutineThrowableS…
dkhalanskyjb 45fe8b8
Update ListAllCoroutineThrowableSubclassesTest.kt
dkhalanskyjb da1ffd6
Rename test to withGuavaTest to avoid classpath pollution
qwwdfsad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
integration-testing/src/test/kotlin/ListAllCoroutineThrowableSubclassesTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2016-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.coroutines | ||
|
||
import com.google.common.reflect.* | ||
import kotlinx.coroutines.* | ||
import org.junit.Test | ||
import kotlin.test.* | ||
|
||
class ListAllCoroutineThrowableSubclassesTest { | ||
|
||
/* | ||
* These are all known throwables in kotlinx.coroutines. | ||
* If you have added one, this test will fail to make | ||
* you ensure your exception type is java.io.Serializable. | ||
qwwdfsad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* We do not have means to check it automatically, so checks are delegated to humans. | ||
* | ||
* 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() { | ||
var throwables = 0 | ||
val classes = ClassPath.from(this.javaClass.classLoader) | ||
.getTopLevelClassesRecursive("kotlinx.coroutines"); | ||
classes.forEach { | ||
if (Throwable::class.java.isAssignableFrom(it.load())) { | ||
++throwables | ||
// println(""""$it",""") | ||
assertTrue(knownThrowables.contains(it.toString())) | ||
qwwdfsad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
assertEquals(knownThrowables.size, throwables) | ||
qwwdfsad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
kotlinx-coroutines-core/jvm/test/JobCancellationExceptionSerializerTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2016-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.coroutines | ||
|
||
import org.junit.* | ||
import java.io.* | ||
|
||
|
||
@Suppress("BlockingMethodInNonBlockingContext") | ||
class JobCancellationExceptionSerializerTest : TestBase() { | ||
|
||
@Test | ||
fun testSerialization() = runTest { | ||
try { | ||
coroutineScope { | ||
expect(1) | ||
|
||
launch { | ||
expect(2) | ||
try { | ||
hang {} | ||
} catch (e: CancellationException) { | ||
throw RuntimeException("RE2", e) | ||
} | ||
} | ||
|
||
launch { | ||
expect(3) | ||
throw RuntimeException("RE1") | ||
} | ||
} | ||
} catch (e: Throwable) { | ||
// Should not fail | ||
ObjectOutputStream(ByteArrayOutputStream()).use { | ||
it.writeObject(e) | ||
} | ||
finish(4) | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling this source set
test
pollutes the other source sets withguava
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name it
withGuavaTest
.I like
testWithGuava
more but it breaks our naming convention