Skip to content

Commit 1321946

Browse files
authored
Fuzzer fails with IllegalStateException #655 (#663)
1 parent e23289b commit 1321946

File tree

1 file changed

+50
-37
lines changed

1 file changed

+50
-37
lines changed

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

+50-37
Original file line numberDiff line numberDiff line change
@@ -451,56 +451,69 @@ class UtBotSymbolicEngine(
451451
EnvironmentModels(values.first().model, emptyList(), mapOf())
452452
}
453453

454-
try {
455-
val concreteExecutionResult =
456-
concreteExecutor.executeConcretely(methodUnderTest, initialEnvironmentModels, listOf())
454+
val concreteExecutionResult: UtConcreteExecutionResult? = try {
455+
concreteExecutor.executeConcretely(methodUnderTest, initialEnvironmentModels, listOf())
456+
} catch (e: CancellationException) {
457+
logger.debug { "Cancelled by timeout" }; null
458+
} catch (e: ConcreteExecutionFailureException) {
459+
emitFailedConcreteExecutionResult(initialEnvironmentModels, e); null
460+
} catch (e: Throwable) {
461+
emit(UtError("Default concrete execution failed", e)); null
462+
}
457463

458-
workaround(REMOVE_ANONYMOUS_CLASSES) {
459-
concreteExecutionResult.result.onSuccess {
460-
if (it.classId.isAnonymous) {
461-
logger.debug("Anonymous class found as a concrete result, symbolic one will be returned")
462-
return@flow
463-
}
464+
// in case an exception occurred from the concrete execution
465+
concreteExecutionResult ?: return@forEach
466+
467+
workaround(REMOVE_ANONYMOUS_CLASSES) {
468+
concreteExecutionResult.result.onSuccess {
469+
if (it.classId.isAnonymous) {
470+
logger.debug("Anonymous class found as a concrete result, symbolic one will be returned")
471+
return@flow
464472
}
465473
}
474+
}
466475

467-
val count = coveredInstructionTracker.add(concreteExecutionResult.coverage.coveredInstructions)
476+
val coveredInstructions = concreteExecutionResult.coverage.coveredInstructions
477+
if (coveredInstructions.isNotEmpty()) {
478+
val count = coveredInstructionTracker.add(coveredInstructions)
468479
if (count.count > 1) {
469480
if (--attempts < 0) {
470481
return@flow
471482
}
472483
return@forEach
473484
}
474485
coveredInstructionValues[count] = values
475-
val nameSuggester = sequenceOf(ModelBasedNameSuggester(), MethodBasedNameSuggester())
476-
val testMethodName = try {
477-
nameSuggester.flatMap { it.suggest(methodUnderTestDescription, values, concreteExecutionResult.result) }.firstOrNull()
478-
} catch (t: Throwable) {
479-
logger.error(t) { "Cannot create suggested test name for ${methodUnderTest.displayName}" }
480-
null
481-
}
482-
483-
emit(
484-
UtExecution(
485-
stateBefore = initialEnvironmentModels,
486-
stateAfter = concreteExecutionResult.stateAfter,
487-
result = concreteExecutionResult.result,
488-
instrumentation = emptyList(),
489-
path = mutableListOf(),
490-
fullPath = emptyList(),
491-
coverage = concreteExecutionResult.coverage,
492-
createdBy = UtExecutionCreator.FUZZER,
493-
testMethodName = testMethodName?.testName,
494-
displayName = testMethodName?.takeIf { hasMethodUnderTestParametersToFuzz }?.displayName
486+
} else {
487+
logger.error { "Coverage is empty for $methodUnderTest with ${values.map { it.model }}" }
488+
}
489+
val nameSuggester = sequenceOf(ModelBasedNameSuggester(), MethodBasedNameSuggester())
490+
val testMethodName = try {
491+
nameSuggester.flatMap {
492+
it.suggest(
493+
methodUnderTestDescription,
494+
values,
495+
concreteExecutionResult.result
495496
)
496-
)
497-
} catch (e: CancellationException) {
498-
logger.debug { "Cancelled by timeout" }
499-
} catch (e: ConcreteExecutionFailureException) {
500-
emitFailedConcreteExecutionResult(initialEnvironmentModels, e)
501-
} catch (e: Throwable) {
502-
emit(UtError("Default concrete execution failed", e))
497+
}.firstOrNull()
498+
} catch (t: Throwable) {
499+
logger.error(t) { "Cannot create suggested test name for ${methodUnderTest.displayName}" }
500+
null
503501
}
502+
503+
emit(
504+
UtExecution(
505+
stateBefore = initialEnvironmentModels,
506+
stateAfter = concreteExecutionResult.stateAfter,
507+
result = concreteExecutionResult.result,
508+
instrumentation = emptyList(),
509+
path = mutableListOf(),
510+
fullPath = emptyList(),
511+
coverage = concreteExecutionResult.coverage,
512+
createdBy = UtExecutionCreator.FUZZER,
513+
testMethodName = testMethodName?.testName,
514+
displayName = testMethodName?.takeIf { hasMethodUnderTestParametersToFuzz }?.displayName
515+
)
516+
)
504517
}
505518
}
506519

0 commit comments

Comments
 (0)