Avoid ConcurrentModificationException
#KT-26384 Fixed
This commit is contained in:
+4
-2
@@ -20,6 +20,8 @@ import com.google.common.collect.LinkedListMultimap
|
||||
import org.jetbrains.kotlin.codegen.optimization.common.isMeaningful
|
||||
import org.jetbrains.org.objectweb.asm.tree.*
|
||||
import java.util.*
|
||||
import kotlin.collections.HashSet
|
||||
import kotlin.collections.LinkedHashSet
|
||||
|
||||
abstract class CoveringTryCatchNodeProcessor(parameterSize: Int) {
|
||||
val tryBlocksMetaInfo: IntervalMetaInfo<TryCatchBlockNodeInfo> = IntervalMetaInfo(this)
|
||||
@@ -114,7 +116,7 @@ class IntervalMetaInfo<T : SplittableInterval<T>>(private val processor: Coverin
|
||||
}
|
||||
|
||||
fun splitAndRemoveCurrentIntervals(by: Interval, keepStart: Boolean) {
|
||||
currentIntervals.map { splitAndRemoveInterval(it, by, keepStart) }
|
||||
currentIntervals.toList().forEach { splitAndRemoveIntervalFromCurrents(it, by, keepStart) }
|
||||
}
|
||||
|
||||
fun processCurrent(curIns: LabelNode, directOrder: Boolean) {
|
||||
@@ -140,7 +142,7 @@ class IntervalMetaInfo<T : SplittableInterval<T>>(private val processor: Coverin
|
||||
return split
|
||||
}
|
||||
|
||||
fun splitAndRemoveInterval(interval: T, by: Interval, keepStart: Boolean): SplitPair<T> {
|
||||
fun splitAndRemoveIntervalFromCurrents(interval: T, by: Interval, keepStart: Boolean): SplitPair<T> {
|
||||
val splitPair = split(interval, by, keepStart)
|
||||
val removed = currentIntervals.remove(splitPair.patchedPart)
|
||||
assert(removed) { "Wrong interval structure: $splitPair" }
|
||||
|
||||
+1
-1
@@ -391,7 +391,7 @@ public class InternalFinallyBlockInliner extends CoveringTryCatchNodeProcessor {
|
||||
// so we should split original interval by inserted finally one
|
||||
for (TryCatchBlockNodeInfo block : updatingClusterBlocks) {
|
||||
//update exception mapping
|
||||
SplitPair<TryCatchBlockNodeInfo> split = tryBlocksMetaInfo.splitAndRemoveInterval(block, splitBy, false);
|
||||
SplitPair<TryCatchBlockNodeInfo> split = tryBlocksMetaInfo.splitAndRemoveIntervalFromCurrents(block, splitBy, false);
|
||||
checkFinally(split.getNewPart());
|
||||
checkFinally(split.getPatchedPart());
|
||||
//block patched in split method
|
||||
|
||||
@@ -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
|
||||
}
|
||||
+10
@@ -2035,6 +2035,16 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
|
||||
runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt20433_void.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26384.kt")
|
||||
public void testKt26384() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt26384.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26384_2.kt")
|
||||
public void testKt26384_2() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt26384_2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt6956.kt")
|
||||
public void testKt6956() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt6956.kt");
|
||||
|
||||
Generated
+10
@@ -2035,6 +2035,16 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
|
||||
runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt20433_void.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26384.kt")
|
||||
public void testKt26384() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt26384.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26384_2.kt")
|
||||
public void testKt26384_2() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt26384_2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt6956.kt")
|
||||
public void testKt6956() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt6956.kt");
|
||||
|
||||
+10
@@ -2035,6 +2035,16 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli
|
||||
runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt20433_void.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26384.kt")
|
||||
public void testKt26384() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt26384.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26384_2.kt")
|
||||
public void testKt26384_2() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt26384_2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt6956.kt")
|
||||
public void testKt6956() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt6956.kt");
|
||||
|
||||
Generated
+10
@@ -149,6 +149,16 @@ public class IrNonLocalReturnsTestGenerated extends AbstractIrNonLocalReturnsTes
|
||||
runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt20433_void.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26384.kt")
|
||||
public void testKt26384() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt26384.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26384_2.kt")
|
||||
public void testKt26384_2() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt26384_2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt6956.kt")
|
||||
public void testKt6956() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt6956.kt");
|
||||
|
||||
+10
@@ -149,6 +149,16 @@ public class NonLocalReturnsTestGenerated extends AbstractNonLocalReturnsTest {
|
||||
runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt20433_void.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26384.kt")
|
||||
public void testKt26384() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt26384.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt26384_2.kt")
|
||||
public void testKt26384_2() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt26384_2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt6956.kt")
|
||||
public void testKt6956() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/kt6956.kt");
|
||||
|
||||
Reference in New Issue
Block a user