diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt index ffb15e7344..6b5c7480f3 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt @@ -1029,7 +1029,7 @@ open class ClassId @JvmOverloads constructor( // so we create a specific name for them isAnonymous -> "Anonymous${supertypeOfAnonymousClass.prettifiedName}" // in other cases where canonical name is still null, we use ClassId.name instead - else -> jClass.canonicalName ?: name // Explicit jClass reference to get null instead of exception + else -> runCatching { canonicalName }.getOrElse { name } } return baseName .substringAfterLast(".") diff --git a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/converter/JcToUtExecutionConverter.kt b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/converter/JcToUtExecutionConverter.kt index 061f89cd42..d6a163942b 100644 --- a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/converter/JcToUtExecutionConverter.kt +++ b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/converter/JcToUtExecutionConverter.kt @@ -24,9 +24,11 @@ import org.utbot.framework.plugin.api.ClassId import org.utbot.framework.plugin.api.Coverage import org.utbot.framework.plugin.api.EnvironmentModels import org.utbot.framework.plugin.api.ExecutableId +import org.utbot.framework.plugin.api.FieldId import org.utbot.framework.plugin.api.Instruction import org.utbot.framework.plugin.api.UtArrayModel import org.utbot.framework.plugin.api.UtAssembleModel +import org.utbot.framework.plugin.api.UtCompositeModel import org.utbot.framework.plugin.api.UtExecutableCallModel import org.utbot.framework.plugin.api.UtExecution import org.utbot.framework.plugin.api.UtExecutionFailure @@ -170,7 +172,25 @@ class JcToUtExecutionConverter( utilMethodProvider.setFieldMethodId == (it as? UtStatementCallModel)?.statement } ) { - model.origin ?: model + UtCompositeModel( + id = model.id, + classId = model.classId, + isMock = false, + fields = model.modificationsChain.associateTo(mutableMapOf()) { + // `setFieldMethodId` call example for reference: + // setField(outputStream, "java.io.ByteArrayOutputStream", "buf", buf); + + val params = (it as UtStatementCallModel).params + val fieldId = FieldId( + declaringClass = ClassId((params[1] as UtPrimitiveModel).value as String), + name = ((params[2] as UtPrimitiveModel).value as String) + ) + // We prefer `model.origin?.fields?.get(fieldId)` over `params[3]`, because + // - `model.origin?.fields?.get(fieldId)` is created from concrete execution initial state + // - `params[3]` is created from jcMachine output, which could be a bit off + fieldId to (model.origin?.fields?.get(fieldId) ?: params[3]) + } + ) } else { model } diff --git a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/converter/UTestInstToUtModelConverter.kt b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/converter/UTestInstToUtModelConverter.kt index be2d579ed5..7dc45583aa 100644 --- a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/converter/UTestInstToUtModelConverter.kt +++ b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/converter/UTestInstToUtModelConverter.kt @@ -240,7 +240,7 @@ class UTestInstToUtModelConverter( executable = utilMethodProvider.getFieldValueMethodId, params = listOf( instanceModel, - UtPrimitiveModel(uTestExpr.field.type), + UtPrimitiveModel(uTestExpr.field.enclosingClass.classId.name), UtPrimitiveModel(uTestExpr.field.name), ), ) @@ -258,7 +258,7 @@ class UTestInstToUtModelConverter( instance = null, executable = utilMethodProvider.getStaticFieldValueMethodId, params = listOf( - UtPrimitiveModel(uTestExpr.field.type), + UtPrimitiveModel(uTestExpr.field.enclosingClass.classId.name), UtPrimitiveModel(uTestExpr.field.name), ), )