Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions kotlinx-coroutines-core/jvm/src/debug/internal/AgentPremain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ import java.security.*
@SuppressLint("all")
@IgnoreJRERequirement // Never touched on Android
internal object AgentPremain {
// This should be the first property to ensure the check happens first! Add new properties only below!
private val dummy = checkIfStdlibIsAvailable()

/**
* This check ensures that kotlin-stdlib classes are loaded by the time AgentPremain is initialized;
* otherwise the debug session would fail with `java.lang.NoClassDefFoundError: kotlin/Result`.
*/
private fun checkIfStdlibIsAvailable() {
try {
Result.success(42)
} catch (t: Throwable) {
error("kotlinx.coroutines debug agent failed to load.\n" +
"Please ensure that the Kotlin standard library is present in the classpath.\n" +
"Alternatively, you can disable kotlinx.coroutines debug agent by removing `-javaagent=/path/kotlinx-coroutines-core.jar` from your VM arguments.\n" +
t.cause)
}
}

private val enableCreationStackTraces = runCatching {
System.getProperty("kotlinx.coroutines.debug.enable.creation.stack.trace")?.toBoolean()
Expand Down