Avoid ConcurrentModificationException

#KT-26384 Fixed
This commit is contained in:
Mikhael Bogdanov
2019-01-07 16:46:22 +01:00
parent 8ce7112123
commit 6a19e45e27
9 changed files with 146 additions and 3 deletions
@@ -0,0 +1,36 @@
// IGNORE_BACKEND: JVM_IR
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
package test
public inline fun <T> T.myapply(block: T.() -> Unit): T {
block()
return this
}
// FILE: 2.kt
import test.*
class Test(val value: () -> String) {
fun test(): String {
try {
myapply {
try {
return value()
} catch (e: Exception) {
} catch (e: Throwable) {
}
}
} finally {
}
return "fail"
}
}
fun box(): String {
return Test { "OK" }.test()
}
@@ -0,0 +1,55 @@
// IGNORE_BACKEND: JVM_IR
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
package test
public inline fun <T> T.myapply(block: T.() -> Unit): T {
block()
return this
}
// FILE: 2.kt
import test.*
var globalResult = ""
class Test(val value: () -> String) {
fun test(): String {
globalResult = ""
try {
myapply {
try {
return value()
} catch (e: Exception) {
globalResult += "Exception"
} catch (e: Throwable) {
globalResult += "Throwable"
}
}
} finally {
globalResult += " Finally"
}
return globalResult
}
}
fun box(): String {
Test { throw RuntimeException("123")}.test()
if (globalResult != "Exception Finally") {
return "fail 1: $globalResult"
}
Test { throw Throwable("123") }.test()
if (globalResult != "Throwable Finally") {
return "fail 2: $globalResult"
}
val result = Test { "OK" }.test()
if (globalResult != " Finally") {
return "fail 3: $globalResult"
}
return result
}