Skip to content

Commit 54617b7

Browse files
committed
Fixed JDK16 tests & links in guide
Fixes #625
1 parent 8339511 commit 54617b7

14 files changed

+51
-49
lines changed

core/kotlinx-coroutines-core/build.gradle

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,18 @@ task jdk16Test(type: Test, dependsOn: [testClasses, checkJdk16]) {
4646
executable = "$System.env.JDK_16/bin/java"
4747
exclude '**/*LinearizabilityTest.*'
4848
exclude '**/*LFTest.*'
49-
exclude '**/exceptions/.*'
49+
exclude '**/exceptions/**'
50+
exclude '**/ExceptionsGuideTest.*'
5051
}
5152

52-
// Always run those tests
53-
task moreTest(dependsOn: [lockFreedomTest])
54-
5553
// Run these tests only during nightly stress test
56-
task extraTest(dependsOn: [jdk16Test])
54+
jdk16Test.onlyIf { project.properties['stressTest'] != null }
5755

56+
// Always run those tests
57+
task moreTest(dependsOn: [lockFreedomTest, jdk16Test])
5858

5959
build.dependsOn moreTest
6060

61-
extraTest.onlyIf { project.properties['stressTest'] != null }
62-
6361
task testsJar(type: Jar, dependsOn: testClasses) {
6462
classifier = 'tests'
6563
from sourceSets.test.output

core/kotlinx-coroutines-core/test/exceptions/CoroutineExceptionHandlerJvmTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class CoroutineExceptionHandlerJvmTest : TestBase() {
3535
job.join()
3636
assertTrue(caughtException is RuntimeException)
3737
assertTrue(caughtException.cause is AssertionError)
38-
assertTrue(caughtException.suppressed()[0] is TestException)
38+
assertTrue(caughtException.suppressed[0] is TestException)
3939

4040
finish(3)
4141
}

core/kotlinx-coroutines-core/test/exceptions/Exceptions.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ import kotlin.test.*
1414
* Proxy for [Throwable.getSuppressed] for tests, which are compiled for both JDK 1.6 and JDK 1.8,
1515
* but run only under JDK 1.8
1616
*/
17-
fun Throwable.suppressed(): Array<Throwable> {
17+
@Suppress("ConflictingExtensionProperty")
18+
val Throwable.suppressed: Array<Throwable> get() {
1819
val method = this::class.java.getMethod("getSuppressed") ?: error("This test can only be run using JDK 1.7")
1920
@Suppress("UNCHECKED_CAST")
2021
return method.invoke(this) as Array<Throwable>
2122
}
2223

2324
internal inline fun <reified T : Throwable> checkException(exception: Throwable): Boolean {
2425
assertTrue(exception is T)
25-
assertTrue(exception.suppressed().isEmpty())
26+
assertTrue(exception.suppressed.isEmpty())
2627
assertNull(exception.cause)
2728
return true
2829
}

core/kotlinx-coroutines-core/test/exceptions/JobBasicCancellationTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,6 @@ class JobBasicCancellationTest : TestBase() {
152152
val cause = deferred.getCancellationException().cause!!
153153
assertTrue(cause is IndexOutOfBoundsException)
154154
assertNull(cause.cause)
155-
assertTrue(cause.suppressed().isEmpty())
155+
assertTrue(cause.suppressed.isEmpty())
156156
}
157157
}

core/kotlinx-coroutines-core/test/exceptions/JobExceptionHandlingTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class JobExceptionHandlingTest : TestBase() {
4848
deferred.await()
4949
expectUnreached()
5050
} catch (e: IOException) {
51-
assertTrue(e.suppressed().isEmpty())
51+
assertTrue(e.suppressed.isEmpty())
5252
finish(3)
5353
}
5454
}
@@ -68,7 +68,7 @@ class JobExceptionHandlingTest : TestBase() {
6868
deferred.await()
6969
expectUnreached()
7070
} catch (e: IOException) {
71-
assertTrue(e.suppressed().isEmpty())
71+
assertTrue(e.suppressed.isEmpty())
7272
finish(3)
7373
}
7474
}
@@ -122,7 +122,7 @@ class JobExceptionHandlingTest : TestBase() {
122122
}
123123

124124
assertTrue(exception is ArithmeticException)
125-
val suppressed = exception.suppressed()
125+
val suppressed = exception.suppressed
126126
assertEquals(2, suppressed.size)
127127
checkException<NullPointerException>(suppressed[0])
128128
checkException<IOException>(suppressed[1])
@@ -225,7 +225,7 @@ class JobExceptionHandlingTest : TestBase() {
225225

226226
assertTrue(exception is IOException)
227227
assertNull(exception.cause)
228-
val suppressed = exception.suppressed()
228+
val suppressed = exception.suppressed
229229
assertEquals(1, suppressed.size)
230230
checkException<ArithmeticException>(suppressed[0])
231231
}
@@ -266,7 +266,7 @@ class JobExceptionHandlingTest : TestBase() {
266266
}
267267

268268
assertTrue(exception is ArithmeticException)
269-
val suppressed = exception.suppressed()
269+
val suppressed = exception.suppressed
270270
assertEquals(2, suppressed.size)
271271
assertTrue(suppressed[0] is IOException)
272272
assertTrue(suppressed[1] is IllegalArgumentException)
@@ -303,7 +303,7 @@ class JobExceptionHandlingTest : TestBase() {
303303
}
304304

305305
assertTrue(exception is AssertionError)
306-
val suppressed = exception.suppressed()
306+
val suppressed = exception.suppressed
307307
assertEquals(2, suppressed.size)
308308
assertTrue(suppressed[0] is IOException)
309309
assertTrue(suppressed[1] is IllegalArgumentException)

core/kotlinx-coroutines-core/test/exceptions/JobExceptionsStressTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class JobExceptionsStressTest : TestBase() {
5353
TestException2::class,
5454
TestException3::class
5555
)
56-
val suppressedExceptions = exception.suppressed().toSet()
56+
val suppressedExceptions = exception.suppressed.toSet()
5757
assertTrue(classes.remove(exception::class),
5858
"Failed to remove ${exception::class} from $suppressedExceptions"
5959
)

core/kotlinx-coroutines-core/test/exceptions/JobNestedExceptionsTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class JobNestedExceptionsTest : TestBase() {
8181
finish(5)
8282
}
8383
assertTrue(exception is ArithmeticException, "Found $exception")
84-
checkException<IOException>(exception.suppressed()[0])
84+
checkException<IOException>(exception.suppressed[0])
8585
}
8686

8787
@Test
@@ -111,10 +111,10 @@ class JobNestedExceptionsTest : TestBase() {
111111
assertEquals(1, exceptions.size, "Found $exceptions")
112112
val exception = exceptions[0]
113113
assertTrue(exception is ArithmeticException, "Exception is $exception")
114-
val suppressed = exception.suppressed()
114+
val suppressed = exception.suppressed
115115
val ioe = suppressed[0]
116116
assertTrue(ioe is IOException)
117-
checkException<NullPointerException>(ioe.suppressed()[0])
117+
checkException<NullPointerException>(ioe.suppressed[0])
118118
checkCycles(exception)
119119
}
120120
}

core/kotlinx-coroutines-core/test/exceptions/ProduceExceptionsTest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ProduceExceptionsTest : TestBase() {
3333

3434
@Test
3535
fun testSuppressedExceptionUncaught() =
36-
runTest(unhandled = listOf({ e -> e is TestException && e.suppressed()[0] is TestException2 })) {
36+
runTest(unhandled = listOf({ e -> e is TestException && e.suppressed[0] is TestException2 })) {
3737
val produce = produce<Int>(Job()) {
3838
launch(start = CoroutineStart.ATOMIC) {
3939
throw TestException()
@@ -66,7 +66,7 @@ class ProduceExceptionsTest : TestBase() {
6666
produce.receive()
6767
expectUnreached()
6868
} catch (e: TestException) {
69-
assertTrue(e.suppressed()[0] is TestException2)
69+
assertTrue(e.suppressed[0] is TestException2)
7070
}
7171
}
7272

@@ -89,7 +89,7 @@ class ProduceExceptionsTest : TestBase() {
8989
try {
9090
channel.receive()
9191
} catch (e: ClosedReceiveChannelException) {
92-
assertTrue(e.suppressed().isEmpty())
92+
assertTrue(e.suppressed.isEmpty())
9393
finish(4)
9494
}
9595
}
@@ -114,7 +114,7 @@ class ProduceExceptionsTest : TestBase() {
114114
try {
115115
channel.receive()
116116
} catch (e: TestException) {
117-
assertTrue(e.suppressed().isEmpty())
117+
assertTrue(e.suppressed.isEmpty())
118118
finish(4)
119119
}
120120
}
@@ -138,7 +138,7 @@ class ProduceExceptionsTest : TestBase() {
138138
try {
139139
channel.receive()
140140
} catch (e: CancellationException) {
141-
assertTrue(e.suppressed().isEmpty())
141+
assertTrue(e.suppressed.isEmpty())
142142
finish(4)
143143
}
144144
}

core/kotlinx-coroutines-core/test/exceptions/SuppresionTests.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class SuppresionTests : TestBase() {
2626
try {
2727
deferred.await()
2828
} catch (e: IOException) {
29-
checkException<ArithmeticException>(e.suppressed()[0])
29+
checkException<ArithmeticException>(e.suppressed[0])
3030
finish(3)
3131
}
3232
}
@@ -42,7 +42,7 @@ class SuppresionTests : TestBase() {
4242

4343
override fun onCancellation(cause: Throwable?) {
4444
assertTrue(cause is ArithmeticException)
45-
assertTrue(cause!!.suppressed().isEmpty())
45+
assertTrue(cause!!.suppressed.isEmpty())
4646
expect(5)
4747
}
4848

@@ -52,20 +52,20 @@ class SuppresionTests : TestBase() {
5252

5353
override fun onCompletedExceptionally(exception: Throwable) {
5454
assertTrue(exception is ArithmeticException)
55-
checkException<IOException>(exception.suppressed()[0])
55+
checkException<IOException>(exception.suppressed[0])
5656
expect(9)
5757
}
5858
}
5959

6060
coroutine.invokeOnCompletion(onCancelling = true) {
6161
assertTrue(it is ArithmeticException)
62-
assertTrue(it!!.suppressed().isEmpty())
62+
assertTrue(it!!.suppressed.isEmpty())
6363
expect(6)
6464
}
6565

6666
coroutine.invokeOnCompletion {
6767
assertTrue(it is ArithmeticException)
68-
checkException<IOException>(it!!.suppressed()[0])
68+
checkException<IOException>(it!!.suppressed[0])
6969
expect(8)
7070
}
7171

core/kotlinx-coroutines-core/test/WithContextCancellationStressTest.kt renamed to core/kotlinx-coroutines-core/test/exceptions/WithContextCancellationStressTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5-
package kotlinx.coroutines.experimental
5+
package kotlinx.coroutines.experimental.exceptions
66

7-
import kotlinx.coroutines.experimental.exceptions.*
7+
import kotlinx.coroutines.experimental.*
88
import org.junit.*
99
import org.junit.Test
1010
import java.io.*
@@ -92,7 +92,7 @@ class WithContextCancellationStressTest : TestBase() {
9292
aeException: Boolean = false,
9393
aioobException: Boolean = false
9494
) {
95-
val suppressed = suppressed()
95+
val suppressed: Array<Throwable> = suppressed
9696

9797
try {
9898
if (ioException) {

core/kotlinx-coroutines-core/test/exceptions/WithContextExceptionHandlingTest.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class WithContextExceptionHandlingTest(private val withContext: Boolean) : TestB
3030
runCancellation(null, IllegalStateException()) { e ->
3131
assertTrue(e is IllegalStateException)
3232
assertNull(e.cause)
33-
val suppressed = e.suppressed()
33+
val suppressed = e.suppressed
3434
assertTrue(suppressed.isEmpty())
3535
}
3636
}
@@ -46,7 +46,7 @@ class WithContextExceptionHandlingTest(private val withContext: Boolean) : TestB
4646
runCancellation(cancellationCause, IllegalStateException()) { e ->
4747
assertTrue(e is IOException)
4848
assertNull(e.cause)
49-
val suppressed = e.suppressed()
49+
val suppressed = e.suppressed
5050
assertEquals(suppressed.size, 1)
5151
assertTrue(suppressed[0] is IllegalStateException)
5252
}
@@ -63,7 +63,7 @@ class WithContextExceptionHandlingTest(private val withContext: Boolean) : TestB
6363
runCancellation(cancellationCause, cancellationCause) { e ->
6464
assertTrue(e is IllegalStateException)
6565
assertNull(e.cause)
66-
val suppressed = e.suppressed()
66+
val suppressed = e.suppressed
6767
assertTrue(suppressed.isEmpty())
6868
}
6969
}
@@ -79,7 +79,7 @@ class WithContextExceptionHandlingTest(private val withContext: Boolean) : TestB
7979
runCancellation(cancellationCause, cancellationCause) { e ->
8080
assertSame(e, cancellationCause)
8181
assertNull(e.cause)
82-
val suppressed = e.suppressed()
82+
val suppressed = e.suppressed
8383
assertTrue(suppressed.isEmpty())
8484
}
8585
}
@@ -97,7 +97,7 @@ class WithContextExceptionHandlingTest(private val withContext: Boolean) : TestB
9797
runCancellation(cancellationCause, exception) { e ->
9898
assertSame(exception, e)
9999
assertNull(e.cause)
100-
assertTrue(e.suppressed().isEmpty())
100+
assertTrue(e.suppressed.isEmpty())
101101
}
102102
}
103103

@@ -113,7 +113,7 @@ class WithContextExceptionHandlingTest(private val withContext: Boolean) : TestB
113113
thrown.initCause(IOException())
114114
runCancellation(cancellationCause, thrown) { e ->
115115
assertSame(cancellationCause, e)
116-
val suppressed = e.suppressed()
116+
val suppressed = e.suppressed
117117
assertEquals(1, suppressed.size)
118118
assertTrue(suppressed[0] is IOException)
119119
}
@@ -130,7 +130,7 @@ class WithContextExceptionHandlingTest(private val withContext: Boolean) : TestB
130130
val thrown = CancellationException()
131131
runCancellation(cancellationCause, thrown) { e ->
132132
assertSame(cancellationCause, e)
133-
val suppressed = e.suppressed()
133+
val suppressed = e.suppressed
134134
assertTrue(suppressed.isEmpty())
135135
}
136136
}
@@ -147,7 +147,7 @@ class WithContextExceptionHandlingTest(private val withContext: Boolean) : TestB
147147
runCancellation(cancellationCause, thrown) { e ->
148148
assertSame(cancellationCause, e)
149149
assertNull(e.cause)
150-
assertTrue(e.suppressed().isEmpty())
150+
assertTrue(e.suppressed.isEmpty())
151151
}
152152
}
153153

@@ -172,7 +172,7 @@ class WithContextExceptionHandlingTest(private val withContext: Boolean) : TestB
172172
fun testCancel() = runTest {
173173
runOnlyCancellation(null) { e ->
174174
assertNull(e.cause)
175-
assertTrue(e.suppressed().isEmpty())
175+
assertTrue(e.suppressed.isEmpty())
176176
}
177177
}
178178

@@ -181,7 +181,7 @@ class WithContextExceptionHandlingTest(private val withContext: Boolean) : TestB
181181
val cause = IOException()
182182
runOnlyCancellation(cause) { e ->
183183
assertSame(cause, e)
184-
assertTrue(e.suppressed().isEmpty())
184+
assertTrue(e.suppressed.isEmpty())
185185
}
186186
}
187187

@@ -191,7 +191,7 @@ class WithContextExceptionHandlingTest(private val withContext: Boolean) : TestB
191191
runThrowing(cause) { e ->
192192
assertSame(cause, e)
193193
assertNull(e.cause)
194-
assertTrue(e.suppressed().isEmpty())
194+
assertTrue(e.suppressed.isEmpty())
195195
}
196196
}
197197

core/kotlinx-coroutines-core/test/guide/example-exceptions-05.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import java.io.*
1212

1313
fun main(args: Array<String>) = runBlocking {
1414
val handler = CoroutineExceptionHandler { _, exception ->
15-
println("Caught $exception with suppressed ${exception.suppressed().contentToString()}")
15+
println("Caught $exception with suppressed ${exception.suppressed.contentToString()}")
1616
}
1717
val job = GlobalScope.launch(handler) {
1818
launch {

docs/exception-handling.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ import java.io.*
268268
```kotlin
269269
fun main(args: Array<String>) = runBlocking {
270270
val handler = CoroutineExceptionHandler { _, exception ->
271-
println("Caught $exception with suppressed ${exception.suppressed().contentToString()}")
271+
println("Caught $exception with suppressed ${exception.suppressed.contentToString()}")
272272
}
273273
val job = GlobalScope.launch(handler) {
274274
launch {
@@ -292,6 +292,8 @@ fun main(args: Array<String>) = runBlocking {
292292

293293
> You can get full code [here](../core/kotlinx-coroutines-core/test/guide/example-exceptions-05.kt)
294294
295+
> Note: This above code will work properly only on JDK7+ that supports `suppressed` exceptions
296+
295297
The output of this code is:
296298

297299
```text
@@ -510,10 +512,11 @@ Scope is completed
510512
<!--- MODULE kotlinx-coroutines-core -->
511513
<!--- INDEX kotlinx.coroutines.experimental -->
512514
[CancellationException]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/-cancellation-exception/index.html
515+
[launch]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/launch.html
516+
[async]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/async.html
513517
[Deferred.await]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/-deferred/await.html
514518
[GlobalScope]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/-global-scope/index.html
515519
[CoroutineExceptionHandler]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/-coroutine-exception-handler/index.html
516-
[async]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/async.html
517520
[Job.cancel]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/-job/cancel.html
518521
[runBlocking]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/run-blocking.html
519522
[SupervisorJob()]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/-supervisor-job.html

0 commit comments

Comments
 (0)