Skip to content

Commit dd54e53

Browse files
committed
Wrap failing method in try-catch block
1 parent ad5860b commit dd54e53

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ class UtBotSymbolicEngine(
531531

532532
emit(
533533
UtFuzzedExecution(
534-
stateBefore = stateBefore,
534+
stateBefore = concreteExecutionResult.stateBefore,
535535
stateAfter = concreteExecutionResult.stateAfter,
536536
result = concreteExecutionResult.result,
537537
coverage = concreteExecutionResult.coverage,

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/tree/CgVariableConstructor.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,13 @@ open class CgVariableConstructor(val context: CgContext) :
248248
is UtStatementCallModel -> {
249249
val call = createCgExecutableCallFromUtExecutableCall(statementModel)
250250
val equivalentFieldAccess = replaceCgExecutableCallWithFieldAccessIfNeeded(call)
251-
if (equivalentFieldAccess != null)
252-
+equivalentFieldAccess
253-
else
254-
+call
251+
val thrownException = statementModel.thrownConcreteException
252+
253+
if (equivalentFieldAccess != null) +equivalentFieldAccess
254+
else if (thrownException != null) {
255+
+tryBlock { +call }
256+
.catch(thrownException) { /* do nothing */ }
257+
} else +call
255258
}
256259
}
257260
}

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/SimpleUtExecutionInstrumentation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class SimpleUtExecutionInstrumentation(
110110
applyPostprocessing()
111111
}
112112
}
113-
}
113+
}.copy(stateBefore = parameters.stateBefore)
114114
}
115115

116116
override fun getStaticField(fieldId: FieldId): Result<UtModel> =

utbot-java-fuzzing/src/main/kotlin/org/utbot/fuzzing/providers/Objects.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class ObjectValueProvider(
106106
model.modificationsChain as MutableList +=
107107
UtExecutableCallModel(
108108
model,
109-
md.executableId,
109+
md.executable,
110110
values.map { it.model }
111111
)
112112
})
@@ -232,9 +232,8 @@ internal class FieldDescription(
232232

233233
internal class MethodDescription(
234234
val name: String,
235-
// val returnType: FuzzedType,
236235
val parameterTypes: List<FuzzedType>,
237-
val executableId: ExecutableId
236+
val executable: ExecutableId
238237
)
239238

240239
internal fun findAccessibleModifiableFields(description: FuzzedDescription?, classId: ClassId, packageName: String?): List<FieldDescription> {
@@ -262,27 +261,28 @@ internal fun findAllPublicMethods(
262261
description: FuzzedDescription?,
263262
classId: ClassId,
264263
packageName: String?
265-
): List<MethodDescription> {
266-
return classId.jClass.declaredMethods.mapNotNull { method ->
264+
): List<MethodDescription> =
265+
classId.jClass.declaredMethods.mapNotNull { method ->
267266
if (isAccessible(method, packageName)) {
268267
val parameterTypes =
269268
method
270269
.parameterTypes
271270
.map {
272-
if (description != null) toFuzzerType(
273-
it,
274-
description.typeCache
275-
) else FuzzedType(method.returnType.id)
271+
if (description != null) {
272+
toFuzzerType(
273+
it,
274+
description.typeCache
275+
)
276+
} else FuzzedType(it.id)
276277
}
277278

278279
MethodDescription(
279280
name = method.name,
280281
parameterTypes = parameterTypes,
281-
executableId = method.executableId
282+
executable = method.executableId
282283
)
283284
} else null
284285
}
285-
}
286286

287287
internal fun Class<*>.findPublicSetterGetterIfHasPublicGetter(field: Field, packageName: String?): PublicSetterGetter? {
288288
@Suppress("DEPRECATION") val postfixName = field.name.capitalize()

0 commit comments

Comments
 (0)