Skip to content

Commit b5578ce

Browse files
authored
Make toMethodResult function safer (#1720)
1 parent c7c493e commit b5578ce

File tree

1 file changed

+16
-2
lines changed
  • utbot-framework/src/main/kotlin/org/utbot/engine

1 file changed

+16
-2
lines changed

utbot-framework/src/main/kotlin/org/utbot/engine/Resolver.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,14 @@ fun Traverser.toMethodResult(value: Any?, sootType: Type): MethodResult {
12351235

12361236
val createdElement = if (elementType is RefType) {
12371237
val className = value[it]!!.javaClass.id.name
1238-
createObject(addr, Scene.v().getRefType(className), useConcreteType = true)
1238+
// Try to take an instance of class we find in Runtime
1239+
// If it is impossible, take the default `elementType` without a concrete type instead.
1240+
val (type, useConcreteType) =
1241+
Scene.v().getRefTypeUnsafe(className)
1242+
?.let { type -> type to true }
1243+
?: (elementType to false)
1244+
1245+
createObject(addr, type, useConcreteType)
12391246
} else {
12401247
require(elementType is ArrayType)
12411248
// We cannot use concrete types since we do not receive
@@ -1262,7 +1269,14 @@ fun Traverser.toMethodResult(value: Any?, sootType: Type): MethodResult {
12621269

12631270
return asMethodResult {
12641271
val addr = UtAddrExpression(mkBVConst("staticVariable${value.hashCode()}", UtInt32Sort))
1265-
createObject(addr, Scene.v().getRefType(refTypeName), useConcreteType = true)
1272+
// Try to take a type from an object from the Runtime.
1273+
// If it is impossible, create an instance of a default `sootType` without a concrete type.
1274+
val (type, useConcreteType) = Scene.v()
1275+
.getRefTypeUnsafe(refTypeName)
1276+
?.let { type -> type to true }
1277+
?: (sootType as RefType to false)
1278+
1279+
createObject(addr, type, useConcreteType)
12661280
}
12671281
}
12681282
}

0 commit comments

Comments
 (0)