From de1712a114b40bedb5c5b40e1f6f51a464f7faeb Mon Sep 17 00:00:00 2001 From: IlyaMuravjov <71839386+IlyaMuravjov@users.noreply.github.com> Date: Fri, 25 Aug 2023 12:34:21 +0300 Subject: [PATCH] Make `findEqualValueOfWellKnownType` catch exceptions #2554 (#2555) --- .../execution/constructors/UtModelConstructor.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/UtModelConstructor.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/UtModelConstructor.kt index e739432f5b..b9bf5053f9 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/UtModelConstructor.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/UtModelConstructor.kt @@ -348,12 +348,14 @@ class UtModelConstructor( ?: constructCompositeModel(value, remainingDepth) } - private fun findEqualValueOfWellKnownType(value: Any): Pair? = when (value) { - is List<*> -> ArrayList(value) to listClassId - is Set<*> -> LinkedHashSet(value) to setClassId - is Map<*, *> -> LinkedHashMap(value) to mapClassId - else -> null - } + private fun findEqualValueOfWellKnownType(value: Any): Pair? = runCatching { + when (value) { + is List<*> -> ArrayList(value) to listClassId + is Set<*> -> LinkedHashSet(value) to setClassId + is Map<*, *> -> LinkedHashMap(value) to mapClassId + else -> null + } + }.getOrNull() /** * Constructs custom UtModel but does it only for predefined list of classes.