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

Do not load a CoroutineExceptionHandler SL eagerly on Android as it c… #3190

Merged
merged 1 commit into from Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
@@ -1,19 +1,13 @@
/*
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.coroutines

import kotlin.coroutines.*
import kotlin.jvm.*

internal expect fun handleCoroutineExceptionImpl(context: CoroutineContext, exception: Throwable)

/**
* JVM kludge: trigger loading of all the classes and service loading
* **before** any exception occur because it may be OOM, SOE or VerifyError
*/
internal expect fun initializeDefaultExceptionHandlers()

/**
* Helper function for coroutine builder implementations to handle uncaught and unexpected exceptions in coroutines,
* that could not be otherwise handled in a normal way through structured concurrency, saving them to a future, and
Expand Down
8 changes: 1 addition & 7 deletions kotlinx-coroutines-core/common/src/Job.kt
Expand Up @@ -113,13 +113,7 @@ public interface Job : CoroutineContext.Element {
/**
* Key for [Job] instance in the coroutine context.
*/
public companion object Key : CoroutineContext.Key<Job> {
init {
// `Job` will necessarily be accessed early, so this is as good a place as any for the
// initialization logic that we want to happen as soon as possible
initializeDefaultExceptionHandlers()
}
}
public companion object Key : CoroutineContext.Key<Job>

// ------------ state query ------------

Expand Down
Expand Up @@ -6,10 +6,6 @@ package kotlinx.coroutines

import kotlin.coroutines.*

internal actual fun initializeDefaultExceptionHandlers() {
// Do nothing
}

internal actual fun handleCoroutineExceptionImpl(context: CoroutineContext, exception: Throwable) {
// log exception
console.error(exception)
Expand Down
Expand Up @@ -22,11 +22,6 @@ private val handlers: List<CoroutineExceptionHandler> = ServiceLoader.load(
CoroutineExceptionHandler::class.java.classLoader
).iterator().asSequence().toList()

internal actual fun initializeDefaultExceptionHandlers() {
// Load CEH and handlers
CoroutineExceptionHandler
}

/**
* Private exception without stacktrace that is added to suppressed exceptions of the original exception
* when it is reported to the last-ditch current thread 'uncaughtExceptionHandler'.
Expand Down
Expand Up @@ -7,10 +7,6 @@ package kotlinx.coroutines
import kotlin.coroutines.*
import kotlin.native.*

internal actual fun initializeDefaultExceptionHandlers() {
// Do nothing
}

@OptIn(ExperimentalStdlibApi::class)
internal actual fun handleCoroutineExceptionImpl(context: CoroutineContext, exception: Throwable) {
// log exception
Expand Down