Skip to content

Commit 3954ddb

Browse files
committed
Wrap failing method in try-catch block
1 parent 66f58c9 commit 3954ddb

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
@@ -478,7 +478,7 @@ class UtBotSymbolicEngine(
478478

479479
emit(
480480
UtFuzzedExecution(
481-
stateBefore = stateBefore,
481+
stateBefore = concreteExecutionResult.stateBefore,
482482
stateAfter = concreteExecutionResult.stateAfter,
483483
result = concreteExecutionResult.result,
484484
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
@@ -230,10 +230,13 @@ open class CgVariableConstructor(val context: CgContext) :
230230
is UtStatementCallModel -> {
231231
val call = createCgExecutableCallFromUtExecutableCall(statementModel)
232232
val equivalentFieldAccess = replaceCgExecutableCallWithFieldAccessIfNeeded(call)
233-
if (equivalentFieldAccess != null)
234-
+equivalentFieldAccess
235-
else
236-
+call
233+
val thrownException = statementModel.thrownConcreteException
234+
235+
if (equivalentFieldAccess != null) +equivalentFieldAccess
236+
else if (thrownException != null) {
237+
+tryBlock { +call }
238+
.catch(thrownException) { /* do nothing */ }
239+
} else +call
237240
}
238241
}
239242
}

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
})
@@ -212,9 +212,8 @@ internal class FieldDescription(
212212

213213
internal class MethodDescription(
214214
val name: String,
215-
// val returnType: FuzzedType,
216215
val parameterTypes: List<FuzzedType>,
217-
val executableId: ExecutableId
216+
val executable: ExecutableId
218217
)
219218

220219
internal fun findAccessibleModifiableFields(description: FuzzedDescription?, classId: ClassId, packageName: String?): List<FieldDescription> {
@@ -242,27 +241,28 @@ internal fun findAllPublicMethods(
242241
description: FuzzedDescription?,
243242
classId: ClassId,
244243
packageName: String?
245-
): List<MethodDescription> {
246-
return classId.jClass.declaredMethods.mapNotNull { method ->
244+
): List<MethodDescription> =
245+
classId.jClass.declaredMethods.mapNotNull { method ->
247246
if (isAccessible(method, packageName)) {
248247
val parameterTypes =
249248
method
250249
.parameterTypes
251250
.map {
252-
if (description != null) toFuzzerType(
253-
it,
254-
description.typeCache
255-
) else FuzzedType(method.returnType.id)
251+
if (description != null) {
252+
toFuzzerType(
253+
it,
254+
description.typeCache
255+
)
256+
} else FuzzedType(it.id)
256257
}
257258

258259
MethodDescription(
259260
name = method.name,
260261
parameterTypes = parameterTypes,
261-
executableId = method.executableId
262+
executable = method.executableId
262263
)
263264
} else null
264265
}
265-
}
266266

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

0 commit comments

Comments
 (0)