Skip to content

Make toMethodResult function safer #1720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions utbot-framework/src/main/kotlin/org/utbot/engine/Resolver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,14 @@ fun Traverser.toMethodResult(value: Any?, sootType: Type): MethodResult {

val createdElement = if (elementType is RefType) {
val className = value[it]!!.javaClass.id.name
createObject(addr, Scene.v().getRefType(className), useConcreteType = true)
// Try to take an instance of class we find in Runtime
// If it is impossible, take the default `elementType` without a concrete type instead.
val (type, useConcreteType) =
Scene.v().getRefTypeUnsafe(className)
?.let { type -> type to true }
?: (elementType to false)

createObject(addr, type, useConcreteType)
} else {
require(elementType is ArrayType)
// We cannot use concrete types since we do not receive
Expand All @@ -1262,7 +1269,14 @@ fun Traverser.toMethodResult(value: Any?, sootType: Type): MethodResult {

return asMethodResult {
val addr = UtAddrExpression(mkBVConst("staticVariable${value.hashCode()}", UtInt32Sort))
createObject(addr, Scene.v().getRefType(refTypeName), useConcreteType = true)
// Try to take a type from an object from the Runtime.
// If it is impossible, create an instance of a default `sootType` without a concrete type.
val (type, useConcreteType) = Scene.v()
.getRefTypeUnsafe(refTypeName)
?.let { type -> type to true }
?: (sootType as RefType to false)

createObject(addr, type, useConcreteType)
}
}
}
Expand Down