in src/jvm/main/org/jetbrains/kotlinx/lincheck/strategy/managed/ManagedStrategy.kt [1442:1481]
override fun beforeWriteArrayElement(
threadDescriptor: ThreadDescriptor,
codeLocation: Int,
array: Any?,
index: Int,
value: Any?,
): Unit = threadDescriptor.runInsideIgnoredSection {
val threadId = threadScheduler.getCurrentThreadId()
if (array == null) {
return // ignore, `NullPointerException` will be thrown
}
updateSnapshotOnArrayElementAccess(array, index)
objectTracker.registerObjectLink(fromObject = array, toObject = value)
if (!shouldTrackArrayAccess(array)) {
getNextEventId() // increment event id as required by the method's contract
return
}
newSwitchPoint(threadId, codeLocation)
// TODO: consider moving trace point addition to `afterWriteArrayElement`.
val eventId = getNextEventId()
val tracePoint = if (collectTrace) {
WriteTracePoint(
context = context,
eventId = eventId,
iThread = threadId,
actorId = currentActorId[threadId]!!,
ownerRepresentation = null,
fieldName = "${objectTracker.getObjectRepresentation(array)}[$index]",
codeLocation = codeLocation,
isLocal = false,
).also {
it.initializeWrittenValue(objectTracker.getObjectRepresentation(value), objectFqTypeName(value))
}
} else {
null
}
traceCollector?.addTracePointInternal(tracePoint)
loopDetector.beforeWriteArrayElement(array, index, value)
}