Skip to content

Commit 2c3435c

Browse files
authored
Merge pull request #3232 from Kotlin/version-1.6.1
Version 1.6.1
2 parents 0d26d6c + 429b5d1 commit 2c3435c

File tree

81 files changed

+2646
-493
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+2646
-493
lines changed

CHANGES.md

+14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Change log for kotlinx.coroutines
22

3+
## Version 1.6.1
4+
5+
* Rollback of time-related functions dispatching on `Dispatchers.Main`.
6+
This behavior was introduced in 1.6.0 and then found inconvenient and erroneous (#3106, #3113).
7+
* Reworked the newly-introduced `CopyableThreadContextElement` to solve issues uncovered after the initial release (#3227).
8+
* Fixed a bug with `ThreadLocalElement` not being properly updated in racy scenarios (#2930).
9+
* Reverted eager loading of default `CoroutineExceptionHandler` that triggered ANR on some devices (#3180).
10+
* New API to convert a `CoroutineDispatcher` to a Rx scheduler (#968, #548). Thanks @recheej!
11+
* Fixed a memory leak with the very last element emitted from `flow` builder being retained in memory (#3197).
12+
* Fixed a bug with `limitedParallelism` on K/N with new memory model throwing `ClassCastException` (#3223).
13+
* `CoroutineContext` is added to the exception printed to the default `CoroutineExceptionHandler` to improve debuggability (#3153).
14+
* Static memory consumption of `Dispatchers.Default` was significantly reduced (#3137).
15+
* Updated slf4j version in `kotlinx-coroutines-slf4j` from 1.7.25 to 1.7.32.
16+
317
## Version 1.6.0
418

519
Note that this is a full changelog relative to the 1.5.2 version. Changelog relative to 1.6.0-RC3 can be found at the end.

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
[![official JetBrains project](https://jb.gg/badges/official.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub)
44
[![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](https://www.apache.org/licenses/LICENSE-2.0)
5-
[![Download](https://img.shields.io/maven-central/v/org.jetbrains.kotlinx/kotlinx-coroutines-core/1.6.0)](https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core/1.6.0/pom)
6-
[![Kotlin](https://img.shields.io/badge/kotlin-1.6.0-blue.svg?logo=kotlin)](http://kotlinlang.org)
5+
[![Download](https://img.shields.io/maven-central/v/org.jetbrains.kotlinx/kotlinx-coroutines-core/1.6.1)](https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core/1.6.1/pom)
6+
[![Kotlin](https://img.shields.io/badge/kotlin-1.6.1-blue.svg?logo=kotlin)](http://kotlinlang.org)
77
[![Slack channel](https://img.shields.io/badge/chat-slack-green.svg?logo=slack)](https://kotlinlang.slack.com/messages/coroutines/)
88

99
Library support for Kotlin coroutines with [multiplatform](#multiplatform) support.
10-
This is a companion version for the Kotlin `1.6.0` release.
10+
This is a companion version for the Kotlin `1.6.1` release.
1111

1212
```kotlin
1313
suspend fun main() = coroutineScope {
@@ -83,7 +83,7 @@ Add dependencies (you can also add other modules that you need):
8383
<dependency>
8484
<groupId>org.jetbrains.kotlinx</groupId>
8585
<artifactId>kotlinx-coroutines-core</artifactId>
86-
<version>1.6.0</version>
86+
<version>1.6.1</version>
8787
</dependency>
8888
```
8989

@@ -101,7 +101,7 @@ Add dependencies (you can also add other modules that you need):
101101

102102
```kotlin
103103
dependencies {
104-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
104+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1")
105105
}
106106
```
107107

@@ -131,7 +131,7 @@ Add [`kotlinx-coroutines-android`](ui/kotlinx-coroutines-android)
131131
module as a dependency when using `kotlinx.coroutines` on Android:
132132

133133
```kotlin
134-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0")
134+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1")
135135
```
136136

137137
This gives you access to the Android [Dispatchers.Main]
@@ -166,7 +166,7 @@ In common code that should get compiled for different platforms, you can add a d
166166
```kotlin
167167
commonMain {
168168
dependencies {
169-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
169+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1")
170170
}
171171
}
172172
```
@@ -178,7 +178,7 @@ Platform-specific dependencies are recommended to be used only for non-multiplat
178178
#### JS
179179

180180
Kotlin/JS version of `kotlinx.coroutines` is published as
181-
[`kotlinx-coroutines-core-js`](https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core-js/1.6.0/jar)
181+
[`kotlinx-coroutines-core-js`](https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core-js/1.6.1/jar)
182182
(follow the link to get the dependency declaration snippet) and as [`kotlinx-coroutines-core`](https://www.npmjs.com/package/kotlinx-coroutines-core) NPM package.
183183

184184
#### Native

build.gradle

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ buildscript {
4646
mavenCentral()
4747
maven { url "https://plugins.gradle.org/m2/" }
4848
maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
49-
maven { url 'https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev' }
5049
mavenLocal()
5150
}
5251

@@ -58,6 +57,7 @@ buildscript {
5857
classpath "com.moowork.gradle:gradle-node-plugin:$gradle_node_version"
5958
classpath "org.jetbrains.kotlinx:binary-compatibility-validator:$binary_compatibility_validator_version"
6059
classpath "ru.vyarus:gradle-animalsniffer-plugin:1.5.3" // Android API check
60+
classpath "org.jetbrains.kotlinx:kover:$kover_version"
6161

6262
// JMH plugins
6363
classpath "com.github.jengelman.gradle.plugins:shadow:5.1.0"
@@ -105,7 +105,8 @@ allprojects {
105105
}
106106

107107
apply plugin: "binary-compatibility-validator"
108-
apply plugin: 'base'
108+
apply plugin: "base"
109+
apply plugin: "kover-conventions"
109110

110111
apiValidation {
111112
ignoredProjects += unpublished + ["kotlinx-coroutines-bom"]
@@ -126,7 +127,6 @@ allprojects {
126127
google()
127128
mavenCentral()
128129
maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
129-
maven { url 'https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev' }
130130
}
131131
}
132132

@@ -303,7 +303,7 @@ def publishTasks = getTasksByName("publish", true) + getTasksByName("publishNpm"
303303

304304
task deploy(dependsOn: publishTasks)
305305

306-
apply plugin: 'animalsniffer-convention'
306+
apply plugin: "animalsniffer-conventions"
307307

308308
clean.dependsOn gradle.includedBuilds.collect { it.task(':clean') }
309309

buildSrc/build.gradle.kts

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ repositories {
1919
maven("https://plugins.gradle.org/m2")
2020
}
2121
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
22-
maven("https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev")
2322
if (buildSnapshotTrain) {
2423
mavenLocal()
2524
}
@@ -60,4 +59,9 @@ dependencies {
6059
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib")
6160
}
6261
implementation("ru.vyarus:gradle-animalsniffer-plugin:1.5.3") // Android API check
62+
implementation("org.jetbrains.kotlinx:kover:${version("kover")}") {
63+
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk8")
64+
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk7")
65+
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib")
66+
}
6367
}

buildSrc/settings.gradle.kts

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
pluginManagement {
55
val build_snapshot_train: String? by settings
66
repositories {
7-
maven(url = "https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev/")
87
val cacheRedirectorEnabled = System.getenv("CACHE_REDIRECTOR")?.toBoolean() == true
98
if (cacheRedirectorEnabled) {
109
println("Redirecting repositories for buildSrc buildscript")

buildSrc/src/main/kotlin/UnpackAar.kt

+32-1
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,49 @@
22
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5+
import org.gradle.api.*
56
import org.gradle.api.artifacts.transform.InputArtifact
67
import org.gradle.api.artifacts.transform.TransformAction
78
import org.gradle.api.artifacts.transform.TransformOutputs
89
import org.gradle.api.artifacts.transform.TransformParameters
10+
import org.gradle.api.attributes.*
911
import org.gradle.api.file.FileSystemLocation
1012
import org.gradle.api.provider.Provider
13+
import org.gradle.kotlin.dsl.*
1114
import java.io.File
1215
import java.nio.file.Files
1316
import java.util.zip.ZipEntry
1417
import java.util.zip.ZipFile
1518

16-
// TODO move back to kotlinx-coroutines-play-services when it's migrated to the kts
19+
// Attributes used by aar dependencies
20+
val artifactType = Attribute.of("artifactType", String::class.java)
21+
val unpackedAar = Attribute.of("unpackedAar", Boolean::class.javaObjectType)
22+
23+
fun Project.configureAar() = configurations.configureEach {
24+
afterEvaluate {
25+
if (isCanBeResolved && !isCanBeConsumed) {
26+
attributes.attribute(unpackedAar, true) // request all AARs to be unpacked
27+
}
28+
}
29+
}
30+
31+
fun DependencyHandlerScope.configureAarUnpacking() {
32+
attributesSchema {
33+
attribute(unpackedAar)
34+
}
35+
36+
artifactTypes {
37+
create("aar") {
38+
attributes.attribute(unpackedAar, false)
39+
}
40+
}
41+
42+
registerTransform(UnpackAar::class.java) {
43+
from.attribute(unpackedAar, false).attribute(artifactType, "aar")
44+
to.attribute(unpackedAar, true).attribute(artifactType, "jar")
45+
}
46+
}
47+
1748
@Suppress("UnstableApiUsage")
1849
abstract class UnpackAar : TransformAction<TransformParameters.None> {
1950
@get:InputArtifact
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import kotlinx.kover.api.*
2+
import kotlinx.kover.tasks.*
3+
4+
/*
5+
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
6+
*/
7+
apply(plugin = "kover")
8+
9+
val notCovered = sourceless + internal + unpublished
10+
11+
val expectedCoverage = mutableMapOf(
12+
// These have lower coverage in general, it can be eventually fixed
13+
"kotlinx-coroutines-swing" to 70, // awaitFrame is not tested
14+
"kotlinx-coroutines-javafx" to 39, // JavaFx is not tested on TC because its graphic subsystem cannot be initialized in headless mode
15+
16+
// Reactor has lower coverage in general due to various fatal error handling features
17+
"kotlinx-coroutines-reactor" to 75)
18+
19+
extensions.configure<KoverExtension> {
20+
disabledProjects = notCovered
21+
/*
22+
* Is explicitly enabled on TC in a separate build step.
23+
* Examples:
24+
* ./gradlew :p:check -- doesn't verify coverage
25+
* ./gradlew :p:check -Pkover.enabled=true -- verifies coverage
26+
* ./gradlew :p:koverReport -Pkover.enabled=true -- generates report
27+
*/
28+
isDisabled = !(properties["kover.enabled"]?.toString()?.toBoolean() ?: false)
29+
// TODO remove when updating Kover to version 0.5.x
30+
intellijEngineVersion.set("1.0.657")
31+
}
32+
33+
subprojects {
34+
val projectName = name
35+
if (projectName in notCovered) return@subprojects
36+
tasks.withType<KoverVerificationTask> {
37+
rule {
38+
bound {
39+
/*
40+
* 85 is our baseline that we aim to raise to 90+.
41+
* Missing coverage is typically due to bugs in the agent
42+
* (e.g. signatures deprecated with an error are counted),
43+
* sometimes it's various diagnostic `toString` or `catch` for OOMs/VerificationErrors,
44+
* but some places are definitely worth visiting.
45+
*/
46+
minValue = expectedCoverage[projectName] ?: 85 // COVERED_LINES_PERCENTAGE
47+
}
48+
}
49+
}
50+
51+
tasks.withType<KoverHtmlReportTask> {
52+
htmlReportDir.set(file(rootProject.buildDir.toString() + "/kover/" + project.name + "/html"))
53+
}
54+
}

docs/topics/coroutines-basics.md

+11-8
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,17 @@ Done
245245

246246
<!--- TEST -->
247247

248-
## Coroutines ARE light-weight
248+
## Coroutines are light-weight
249249

250-
Run the following code:
250+
Coroutines are less resource-intensive than JVM threads. Code that exhausts the
251+
JVM's available memory when using threads can be expressed using coroutines
252+
without hitting resource limits. For example, the following code launches
253+
100000 distinct coroutines that each wait 5 seconds and then print a period
254+
('.') while consuming very little memory:
251255

252256
```kotlin
253257
import kotlinx.coroutines.*
254258

255-
//sampleStart
256259
fun main() = runBlocking {
257260
repeat(100_000) { // launch a lot of coroutines
258261
launch {
@@ -261,19 +264,19 @@ fun main() = runBlocking {
261264
}
262265
}
263266
}
264-
//sampleEnd
265267
```
268+
<!-- While coroutines do have a smaller memory footprint than threads, this
269+
example will exhaust the playground's heap memory; don't make it runnable. -->
266270

267271
> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-basic-06.kt).
268272
>
269273
{type="note"}
270274

271275
<!--- TEST lines.size == 1 && lines[0] == ".".repeat(100_000) -->
272276

273-
It launches 100K coroutines and, after 5 seconds, each coroutine prints a dot.
274-
275-
Now, try that with threads (remove `runBlocking`, replace `launch` with `thread`, and replace `delay` with `Thread.sleep`).
276-
What would happen? (Most likely your code will produce some sort of out-of-memory error)
277+
If you write the same program using threads (remove `runBlocking`, replace
278+
`launch` with `thread`, and replace `delay` with `Thread.sleep`), it will
279+
likely consume too much memory and throw an out-of-memory error.
277280

278281
<!--- MODULE kotlinx-coroutines-core -->
279282
<!--- INDEX kotlinx.coroutines -->

docs/topics/exception-handling.md

-6
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@ You cannot recover from the exception in the `CoroutineExceptionHandler`. The co
7575
with the corresponding exception when the handler is called. Normally, the handler is used to
7676
log the exception, show some kind of error message, terminate, and/or restart the application.
7777

78-
On JVM it is possible to redefine global exception handler for all coroutines by registering [CoroutineExceptionHandler] via
79-
[`ServiceLoader`](https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html).
80-
Global exception handler is similar to
81-
[`Thread.defaultUncaughtExceptionHandler`](https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html#setDefaultUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler))
82-
which is used when no more specific handlers are registered.
83-
On Android, `uncaughtExceptionPreHandler` is installed as a global coroutine exception handler.
8478

8579
`CoroutineExceptionHandler` is invoked only on **uncaught** exceptions &mdash; exceptions that were not handled in any other way.
8680
In particular, all _children_ coroutines (coroutines created in the context of another [Job]) delegate handling of

gradle.properties

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44

55
# Kotlin
6-
version=1.6.0-SNAPSHOT
6+
version=1.6.1-SNAPSHOT
77
group=org.jetbrains.kotlinx
88
kotlin_version=1.6.0
99

@@ -14,22 +14,23 @@ atomicfu_version=0.17.0
1414
knit_version=0.3.0
1515
html_version=0.7.2
1616
lincheck_version=2.14
17-
dokka_version=1.6.0-dev-138
17+
dokka_version=1.6.10
1818
byte_buddy_version=1.10.9
1919
reactor_version=3.4.1
2020
reactive_streams_version=1.0.3
2121
rxjava2_version=2.2.8
2222
rxjava3_version=3.0.2
2323
javafx_version=11.0.2
2424
javafx_plugin_version=0.0.8
25-
binary_compatibility_validator_version=0.8.0-RC
25+
binary_compatibility_validator_version=0.8.0
26+
kover_version=0.5.0
2627
blockhound_version=1.0.2.RELEASE
2728
jna_version=5.9.0
2829

2930
# Android versions
3031
android_version=4.1.1.4
3132
androidx_annotation_version=1.1.0
32-
robolectric_version=4.0.2
33+
robolectric_version=4.4
3334
baksmali_version=2.2.7
3435

3536
# JS

gradle/dokka.gradle.kts

+1-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ tasks.withType(DokkaTaskPartial::class).configureEach {
3737
packageListUrl.set(rootProject.projectDir.toPath().resolve("site/stdlib.package.list").toUri().toURL())
3838
}
3939

40-
if (project.name != "kotlinx-coroutines-core" && project.name != "kotlinx-coroutines-test") {
40+
if (!project.isMultiplatform) {
4141
dependsOn(project.configurations["compileClasspath"])
4242
doFirst {
4343
// resolve classpath only during execution
@@ -66,10 +66,6 @@ if (project.name == "kotlinx-coroutines-core") {
6666
val jvmMain by getting {
6767
makeLinkMapping(project.file("jvm"))
6868
}
69-
70-
configureEach {
71-
classpath.from(project.configurations["jvmCompileClasspath"].files)
72-
}
7369
}
7470
}
7571
}

integration/kotlinx-coroutines-guava/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ Integration with Guava [ListenableFuture](https://github.com/google/guava/wiki/L
6262

6363
<!--- INDEX com.google.common.util.concurrent -->
6464

65-
[com.google.common.util.concurrent.ListenableFuture]: https://kotlin.github.io/kotlinx.coroutines/https://google.github.io/guava/releases/28.0-jre/api/docs/com/google/common/util/concurrent/ListenableFuture.html
65+
[com.google.common.util.concurrent.ListenableFuture]: https://kotlin.github.io/kotlinx.coroutines/https://google.github.io/guava/releases/31.0.1-jre/api/docs/com/google/common/util/concurrent/ListenableFuture.html
6666

6767
<!--- END -->

integration/kotlinx-coroutines-guava/build.gradle.kts

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5-
val guavaVersion = "28.0-jre"
5+
val guavaVersion = "31.0.1-jre"
66

77
dependencies {
88
compile("com.google.guava:guava:$guavaVersion")
99
}
1010

11+
java {
12+
targetCompatibility = JavaVersion.VERSION_1_8
13+
sourceCompatibility = JavaVersion.VERSION_1_8
14+
}
15+
1116
externalDocumentationLink(
1217
url = "https://google.github.io/guava/releases/$guavaVersion/api/docs/"
1318
)

0 commit comments

Comments
 (0)