@@ -134,6 +134,7 @@ import org.utbot.framework.plugin.api.util.utContext
134134import org.utbot.framework.util.executableId
135135import org.utbot.framework.util.graph
136136import org.utbot.framework.plugin.api.util.isInaccessibleViaReflection
137+ import org.utbot.summary.ast.declaredClassName
137138import java.lang.reflect.ParameterizedType
138139import kotlin.collections.plus
139140import kotlin.collections.plusAssign
@@ -2953,9 +2954,25 @@ class Traverser(
29532954 declaringClass == utArrayMockClass -> utArrayMockInvoke(target, parameters)
29542955 isUtMockForbidClassCastException -> isUtMockDisableClassCastExceptionCheckInvoke(parameters)
29552956 else -> {
2956- val graph = substitutedMethod?.jimpleBody()?.graph() ? : jimpleBody().graph()
2957- pushToPathSelector(graph, target.instance, parameters, target.constraints, isLibraryMethod)
2958- emptyList()
2957+ // Try to extract a body from substitution of our method or from the method itself.
2958+ // For the substitution, if it exists, we have a corresponding body and graph,
2959+ // but for the method itself its body might not be present in the memory.
2960+ // This may happen because of classloading issues (e.g. absence of required library JAR file)
2961+ val graph = (substitutedMethod ? : this ).takeIf { it.canRetrieveBody() }?.jimpleBody()?.graph()
2962+
2963+ if (graph != null ) {
2964+ // If we have a graph to analyze, do it
2965+ pushToPathSelector(graph, target.instance, parameters, target.constraints, isLibraryMethod)
2966+ emptyList()
2967+ } else {
2968+ // Otherwise, depending on [treatAbsentMethodsAsUnboundedValue] either throw an exception
2969+ // or continue analysis with an unbounded variable as a result of the [this] method
2970+ if (UtSettings .treatAbsentMethodsAsUnboundedValue) {
2971+ listOf (unboundedVariable(" methodWithoutBodyResult" , method = this ))
2972+ } else {
2973+ error(" Cannot retrieve body for a $declaredClassName .$name method" )
2974+ }
2975+ }
29592976 }
29602977 }
29612978 }
0 commit comments