Skip to content

Commit 94d8eca

Browse files
committed
Removed incorrect assertions
1 parent eb7393b commit 94d8eca

File tree

4 files changed

+11
-20
lines changed

4 files changed

+11
-20
lines changed

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/IdUtil.kt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,22 +285,15 @@ val ClassId.isMap: Boolean
285285
val ClassId.isIterableOrMap: Boolean
286286
get() = isIterable || isMap
287287

288-
// TODO: needs to be refactored (do we really need receiver? Can't we specify cases where we should return null?)
289288
fun ClassId.findFieldByIdOrNull(fieldId: FieldId): Field? {
290289
if (isNotSubtypeOf(fieldId.declaringClass)) {
291-
error("findFieldByIdOrNull is called on class ${name}, which is not a subclass of ${fieldId.name}'s declaring class")
290+
return null
292291
}
293292

294293
return fieldId.declaringClass.jClass.declaredFields.firstOrNull { it.name == fieldId.name }
295294
}
296295

297-
// TODO: maybe we could replace its usages with FieldId.field
298-
fun ClassId.findFieldById(fieldId: FieldId): Field =
299-
findFieldByIdOrNull(fieldId) ?: error("Can't find field ${fieldId.name} in $name")
300-
301-
// TODO: check if we need this function
302296
fun ClassId.hasField(fieldId: FieldId): Boolean {
303-
assert(findFieldByIdOrNull(fieldId) != null)
304297
return findFieldByIdOrNull(fieldId) != null
305298
}
306299

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ import org.utbot.framework.plugin.api.MethodId
8989
import org.utbot.framework.plugin.api.UtMethod
9090
import org.utbot.framework.plugin.api.classId
9191
import org.utbot.framework.plugin.api.id
92-
import org.utbot.framework.plugin.api.util.findFieldById
92+
import org.utbot.framework.plugin.api.util.field
9393
import org.utbot.framework.plugin.api.util.jClass
9494
import org.utbot.framework.plugin.api.util.id
9595
import org.utbot.framework.plugin.api.util.signature
@@ -582,7 +582,7 @@ class Traverser(
582582
declaringClass: SootClass,
583583
stmt: Stmt
584584
): SymbolicStateUpdate {
585-
val concreteValue = extractConcreteValue(field, declaringClass)
585+
val concreteValue = extractConcreteValue(field)
586586
val (symbolicResult, symbolicStateUpdate) = toMethodResult(concreteValue, field.type)
587587
val symbolicValue = (symbolicResult as SymbolicSuccess).value
588588

@@ -634,12 +634,12 @@ class Traverser(
634634
// Some fields are inaccessible with reflection, so we have to instantiate it by ourselves.
635635
// Otherwise, extract it from the class.
636636
// TODO JIRA:1593
637-
private fun extractConcreteValue(field: SootField, declaringClass: SootClass): Any? =
637+
private fun extractConcreteValue(field: SootField): Any? =
638638
when (field.signature) {
639639
SECURITY_FIELD_SIGNATURE -> SecurityManager()
640640
FIELD_FILTER_MAP_FIELD_SIGNATURE -> mapOf(Reflection::class to arrayOf("fieldFilterMap", "methodFilterMap"))
641641
METHOD_FILTER_MAP_FIELD_SIGNATURE -> emptyMap<Class<*>, Array<String>>()
642-
else -> declaringClass.id.findFieldById(field.fieldId).let { it.withAccessibility { it.get(null) } }
642+
else -> field.fieldId.field.let { it.withAccessibility { it.get(null) } }
643643
}
644644

645645
private fun isStaticInstanceInMethodResult(id: ClassId, methodResult: MethodResult?) =

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import org.utbot.framework.plugin.api.UtVoidModel
3636
import org.utbot.framework.plugin.api.isMockModel
3737
import org.utbot.framework.plugin.api.util.constructor
3838
import org.utbot.framework.plugin.api.util.field
39-
import org.utbot.framework.plugin.api.util.findFieldById
4039
import org.utbot.framework.plugin.api.util.jClass
4140
import org.utbot.framework.plugin.api.util.method
4241
import org.utbot.framework.plugin.api.util.utContext
@@ -212,8 +211,8 @@ class ValueConstructor {
212211
val classInstance = javaClass.anyInstance
213212
constructedObjects[model] = classInstance
214213

215-
model.fields.forEach { (field, fieldModel) ->
216-
val declaredField = model.classId.findFieldById(field)
214+
model.fields.forEach { (fieldId, fieldModel) ->
215+
val declaredField = fieldId.field
217216
val accessible = declaredField.isAccessible
218217

219218
try {
@@ -227,7 +226,7 @@ class ValueConstructor {
227226
fieldModel.classId.name,
228227
model.classId.name,
229228
UtConcreteValue(classInstance),
230-
field.name
229+
fieldId.name
231230
)
232231
}
233232
val value = construct(fieldModel, target).value

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import org.mockito.Mockito
4545
import org.mockito.stubbing.Answer
4646
import org.objectweb.asm.Type
4747
import org.utbot.common.withAccessibility
48-
import org.utbot.framework.plugin.api.util.findFieldById
4948

5049
/**
5150
* Constructs values (including mocks) from models.
@@ -169,16 +168,16 @@ class MockValueConstructor(
169168
mockInstance
170169
}
171170

172-
model.fields.forEach { (field, fieldModel) ->
173-
val declaredField = model.classId.findFieldById(field)
171+
model.fields.forEach { (fieldId, fieldModel) ->
172+
val declaredField = fieldId.field
174173
val accessible = declaredField.isAccessible
175174
declaredField.isAccessible = true
176175

177176
val modifiersField = Field::class.java.getDeclaredField("modifiers")
178177
modifiersField.isAccessible = true
179178

180179
val target = mockTarget(fieldModel) {
181-
FieldMockTarget(fieldModel.classId.name, model.classId.name, UtConcreteValue(classInstance), field.name)
180+
FieldMockTarget(fieldModel.classId.name, model.classId.name, UtConcreteValue(classInstance), fieldId.name)
182181
}
183182
val value = construct(fieldModel, target).value
184183
val instance = if (Modifier.isStatic(declaredField.modifiers)) null else classInstance

0 commit comments

Comments
 (0)