Skip to content

Commit

Permalink
Ensure that array elements are transformed (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndkoval authored Sep 9, 2024
1 parent 4175292 commit 7a1ed7a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Any>) {
if (obj is Array<*>) {
obj.filterNotNull().forEach { ensureObjectIsTransformed(it, processedObjects) }
return
}

if (!instrumentation.isModifiableClass(obj.javaClass) || !shouldTransform(obj.javaClass.name, instrumentationMode)) {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 7a1ed7a

Please sign in to comment.