diff --git a/src/jvm/main/org/jetbrains/kotlinx/lincheck/transformation/LincheckJavaAgent.kt b/src/jvm/main/org/jetbrains/kotlinx/lincheck/transformation/LincheckJavaAgent.kt index 0038f4977..bff4751a4 100644 --- a/src/jvm/main/org/jetbrains/kotlinx/lincheck/transformation/LincheckJavaAgent.kt +++ b/src/jvm/main/org/jetbrains/kotlinx/lincheck/transformation/LincheckJavaAgent.kt @@ -252,6 +252,11 @@ internal object LincheckJavaAgent { * @param processedObjects A set of processed objects to avoid infinite recursion. */ private fun ensureObjectIsTransformed(obj: Any, processedObjects: MutableSet) { + if (obj is Array<*>) { + obj.filterNotNull().forEach { ensureObjectIsTransformed(it, processedObjects) } + return + } + if (!instrumentation.isModifiableClass(obj.javaClass) || !shouldTransform(obj.javaClass.name, instrumentationMode)) { return } diff --git a/src/jvm/test/org/jetbrains/kotlinx/lincheck_test/verifier/linearizability/CounterTests.kt b/src/jvm/test/org/jetbrains/kotlinx/lincheck_test/verifier/linearizability/CounterTests.kt index 415561228..0a4685c43 100644 --- a/src/jvm/test/org/jetbrains/kotlinx/lincheck_test/verifier/linearizability/CounterTests.kt +++ b/src/jvm/test/org/jetbrains/kotlinx/lincheck_test/verifier/linearizability/CounterTests.kt @@ -27,6 +27,7 @@ class CounterCorrectTest : AbstractCounterTest(CounterCorrect()) class CounterWrong0Test : AbstractCounterTest(CounterWrong0(), IncorrectResultsFailure::class) class CounterWrong1Test : AbstractCounterTest(CounterWrong1(), IncorrectResultsFailure::class) class CounterWrong2Test : AbstractCounterTest(CounterWrong2(), IncorrectResultsFailure::class) +class CounterWithArrayWrongTest : AbstractCounterTest(CounterWithArrayWrong(), IncorrectResultsFailure::class) interface Counter { fun incAndGet(): Int @@ -58,6 +59,20 @@ private class CounterWrong2 : Counter { override fun get(): Int = c } +private class CounterWithArrayWrong : Counter { + private var counter = arrayOf(CounterImpl()) + + override fun incAndGet(): Int = counter[0].incAndGet() + override fun get(): Int = counter[0].get() + + private class CounterImpl { + private var c: Int = 0 + + fun incAndGet(): Int = ++c + fun get(): Int = c + } +} + private class CounterCorrect : Counter { private val c = AtomicInteger()