Skip to content

Commit 2a59741

Browse files
qwwdfsadelizarov
authored andcommitted
Revert "System property to control BlockingChecker extension point for runBlocking"
This reverts commit 94bbe9f.
1 parent 7e0911a commit 2a59741

File tree

2 files changed

+4
-35
lines changed

2 files changed

+4
-35
lines changed

binary-compatibility-validator/reference-public-api/kotlinx-coroutines-core.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ public abstract interface class kotlinx/coroutines/experimental/BlockingChecker
2525
}
2626

2727
public final class kotlinx/coroutines/experimental/BuildersKt {
28-
public static final field BLOCKING_CHECKER_PROPERTY_NAME Ljava/lang/String;
29-
public static final field BLOCKING_CHECKER_VALUE_DISABLE Ljava/lang/String;
3028
public static final synthetic fun launch (Lkotlin/coroutines/experimental/CoroutineContext;Lkotlinx/coroutines/experimental/CoroutineStart;Lkotlin/jvm/functions/Function2;)Lkotlinx/coroutines/experimental/Job;
3129
public static final fun launch (Lkotlin/coroutines/experimental/CoroutineContext;Lkotlinx/coroutines/experimental/CoroutineStart;Lkotlinx/coroutines/experimental/Job;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Lkotlinx/coroutines/experimental/Job;
3230
public static final synthetic fun launch (Lkotlin/coroutines/experimental/CoroutineContext;Lkotlinx/coroutines/experimental/CoroutineStart;Lkotlinx/coroutines/experimental/Job;Lkotlin/jvm/functions/Function2;)Lkotlinx/coroutines/experimental/Job;

core/kotlinx-coroutines-core/src/Builders.kt

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ import kotlin.coroutines.experimental.*
3232
* See [newCoroutineContext] for a description of debugging facilities that are available for newly created coroutine.
3333
*
3434
* @throws IllegalStateException if blocking is not allowed in current thread.
35-
* Blocking is checked by [BlockingChecker] that is registered via [ServiceLoader],
36-
* unless [BLOCKING_CHECKER_PROPERTY_NAME] system property is set to [BLOCKING_CHECKER_VALUE_DISABLE].
35+
* Blocking is checked by [BlockingChecker] registered in [ServiceLoader]
3736
* @param context context of the coroutine. The default value is an implementation of [EventLoop].
3837
* @param block the coroutine code.
3938
*/
@@ -52,18 +51,6 @@ public fun <T> runBlocking(context: CoroutineContext = EmptyCoroutineContext, bl
5251
return coroutine.joinBlocking()
5352
}
5453

55-
/**
56-
* Name of the property to control whether [runBlocking] builder
57-
* is restricted via [BlockingChecker] extension points.
58-
*/
59-
public const val BLOCKING_CHECKER_PROPERTY_NAME = "kotlinx.coroutines.blocking.checker"
60-
61-
/**
62-
* Value of the [BLOCKING_CHECKER_PROPERTY_NAME] to disable installed
63-
* [BlockingChecker] and thus allow [runBlocking] in any thread.
64-
*/
65-
public const val BLOCKING_CHECKER_VALUE_DISABLE = "disable"
66-
6754
/**
6855
* Extension point which determines whether invoking [runBlocking] in the current thread is allowed.
6956
* [runBlocking] discovers all checkers via [ServiceLoader] and invokes [checkRunBlocking] on
@@ -77,9 +64,6 @@ public const val BLOCKING_CHECKER_VALUE_DISABLE = "disable"
7764
* check(!UiFramework.isInUiThread()) { "runBlocking is not allowed in UI thread" }
7865
* }
7966
* ```
80-
*
81-
* Installed checkers are ignored if "`kotlinx.coroutines.blocking.checker`" ([BLOCKING_CHECKER_PROPERTY_NAME])
82-
* system property is set to the value "`disable`" ([BLOCKING_CHECKER_VALUE_DISABLE]).
8367
*/
8468
public interface BlockingChecker {
8569
/**
@@ -88,24 +72,11 @@ public interface BlockingChecker {
8872
fun checkRunBlocking()
8973
}
9074

91-
private class BlockingCheckerList(private val checkers: Array<BlockingChecker>) : BlockingChecker {
92-
override fun checkRunBlocking() = checkers.forEach { it.checkRunBlocking() }
93-
}
94-
9575
// Nullable to enable DCE when no filters are present in classpath
9676
private val blockingChecker: BlockingChecker? = run {
97-
val value = systemProp(BLOCKING_CHECKER_PROPERTY_NAME)
98-
when (value) {
99-
BLOCKING_CHECKER_VALUE_DISABLE -> null
100-
null -> {
101-
val checkers = ServiceLoader.load(BlockingChecker::class.java).toList()
102-
when (checkers.size) {
103-
0 -> null
104-
1 -> checkers[0]
105-
else -> BlockingCheckerList(checkers.toTypedArray())
106-
}
107-
}
108-
else -> error("System property '$BLOCKING_CHECKER_PROPERTY_NAME' has unrecognized value '$value'")
77+
val filters = ServiceLoader.load(BlockingChecker::class.java).toList().toTypedArray()
78+
if (filters.isEmpty()) null else object : BlockingChecker {
79+
override fun checkRunBlocking() = filters.forEach { it.checkRunBlocking() }
10980
}
11081
}
11182

0 commit comments

Comments
 (0)