Skip to content

Commit b3a8464

Browse files
committed
fix statics construction
1 parent b5f40fc commit b3a8464

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

utbot-framework/src/main/kotlin/org/utbot/framework/concrete/UtExecutionInstrumentation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ object UtExecutionInstrumentation : Instrumentation<UtConcreteExecutionResult> {
169169
val executionResult = convertToExecutionResult(concreteResult, returnClassId)
170170

171171
val stateAfterParametersWithThis = constructParameters(params)
172-
val stateAfterStatics = constructStatics(statics.keys/* + traceHandler.computePutStatics()*/)
172+
val stateAfterStatics = constructStatics(stateBefore, statics)
173173
val (stateAfterThis, stateAfterParameters) = if (stateBefore.thisInstance == null) {
174174
null to stateAfterParametersWithThis
175175
} else {

utbot-framework/src/main/kotlin/org/utbot/framework/concrete/phases/ModelConstructionContext.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.utbot.common.withAccessibility
66
import org.utbot.framework.concrete.constructors.UtCompositeModelStrategy
77
import org.utbot.framework.concrete.constructors.UtModelConstructor
88
import org.utbot.framework.plugin.api.ClassId
9+
import org.utbot.framework.plugin.api.EnvironmentModels
910
import org.utbot.framework.plugin.api.FieldId
1011
import org.utbot.framework.plugin.api.TimeoutException
1112
import org.utbot.framework.plugin.api.UtConcreteValue
@@ -58,11 +59,20 @@ class ModelConstructionContext(
5859
constructor.construct(it.value, it.clazz.id)
5960
}
6061

61-
fun constructStatics(staticFields: Set<FieldId>): Map<FieldId, UtModel> =
62-
staticFields.associateWith { fieldId ->
62+
fun constructStatics(
63+
stateBefore: EnvironmentModels,
64+
staticFields: Map<FieldId, UtConcreteValue<*>>
65+
): Map<FieldId, UtModel> =
66+
staticFields.keys.associateWith { fieldId ->
6367
fieldId.jField.run {
6468
val computedValue = withAccessibility { get(null) }
65-
constructor.construct(computedValue, fieldId.type)
69+
val knownModel = stateBefore.statics[fieldId]
70+
val knownValue = staticFields[fieldId]?.value
71+
if (knownModel != null && knownValue != null && knownValue == computedValue) {
72+
knownModel
73+
} else {
74+
constructor.construct(computedValue, fieldId.type)
75+
}
6676
}
6777
}
6878

0 commit comments

Comments
 (0)