From d742a089d41e0bbd0b8dfef78d7f120537c361d8 Mon Sep 17 00:00:00 2001 From: Sergey Pospelov Date: Thu, 22 Sep 2022 17:54:03 +0300 Subject: [PATCH] Fix: class not found in concrete execution --- .../concrete/UtExecutionInstrumentation.kt | 7 ++++++- .../instrumenter/Instrumenter.kt | 20 ++++++++++--------- .../instrumentation/process/ChildProcess.kt | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/concrete/UtExecutionInstrumentation.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/concrete/UtExecutionInstrumentation.kt index bb1050d068..a787dd2ea7 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/concrete/UtExecutionInstrumentation.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/concrete/UtExecutionInstrumentation.kt @@ -13,6 +13,7 @@ import org.utbot.framework.plugin.api.Instruction import org.utbot.framework.plugin.api.MissingState import org.utbot.framework.plugin.api.TimeoutException import org.utbot.framework.plugin.api.UtAssembleModel +import org.utbot.framework.plugin.api.UtConcreteExecutionFailure import org.utbot.framework.plugin.api.UtExecutionFailure import org.utbot.framework.plugin.api.UtExecutionResult import org.utbot.framework.plugin.api.UtExecutionSuccess @@ -161,6 +162,7 @@ object UtExecutionInstrumentation : Instrumentation { Coverage() ) } + throw e } val staticFields = constructor @@ -249,9 +251,12 @@ object UtExecutionInstrumentation : Instrumentation { if (exception is TimeoutException) { return UtTimeoutException(exception) } - if (exception is AccessControlException) { + if (exception is AccessControlException || + exception is ExceptionInInitializerError && exception.exception is AccessControlException) { return UtSandboxFailure(exception) } + // there also can be other cases, when we need to wrap internal exception... I suggest adding them on demand + val instrs = traceHandler.computeInstructionList() val isNested = if (instrs.isEmpty()) { false diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/instrumenter/Instrumenter.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/instrumenter/Instrumenter.kt index e29bdceaa1..70ce2a6515 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/instrumenter/Instrumenter.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/instrumenter/Instrumenter.kt @@ -1,5 +1,11 @@ package org.utbot.instrumentation.instrumentation.instrumenter +import org.objectweb.asm.ClassReader +import org.objectweb.asm.ClassVisitor +import org.objectweb.asm.ClassWriter +import org.objectweb.asm.Opcodes +import org.objectweb.asm.Type +import org.objectweb.asm.tree.ClassNode import org.utbot.framework.plugin.api.util.UtContext import org.utbot.instrumentation.Settings import org.utbot.instrumentation.instrumentation.instrumenter.visitors.MethodToProbesVisitor @@ -9,6 +15,7 @@ import org.utbot.instrumentation.instrumentation.instrumenter.visitors.util.IIns import org.utbot.instrumentation.instrumentation.instrumenter.visitors.util.InstanceFieldInitializer import org.utbot.instrumentation.instrumentation.instrumenter.visitors.util.InstructionVisitorAdapter import org.utbot.instrumentation.instrumentation.instrumenter.visitors.util.StaticFieldInitializer +import org.utbot.instrumentation.process.HandlerClassesLoader import java.io.File import java.io.IOException import java.io.InputStream @@ -17,12 +24,6 @@ import java.nio.file.Path import java.nio.file.Paths import kotlin.reflect.KFunction import kotlin.reflect.jvm.javaMethod -import org.objectweb.asm.ClassReader -import org.objectweb.asm.ClassVisitor -import org.objectweb.asm.ClassWriter -import org.objectweb.asm.Opcodes -import org.objectweb.asm.Type -import org.objectweb.asm.tree.ClassNode // TODO: handle with flags EXPAND_FRAMES, etc. @@ -155,7 +156,7 @@ private class TunedClassWriter( flags: Int ) : ClassWriter(reader, flags) { override fun getClassLoader(): ClassLoader { - return UtContext.currentContext()?.classLoader ?: this::class.java.classLoader + return HandlerClassesLoader } override fun getCommonSuperClass(type1: String, type2: String): String { try { @@ -278,8 +279,9 @@ private class TunedClassWriter( */ @Throws(IOException::class) private fun typeInfo(type: String): ClassReader { - val `is`: InputStream = classLoader.getResourceAsStream("$type.class") - ?: error("Can't find resource for class: $type.class") + val `is`: InputStream = requireNotNull(classLoader.getResourceAsStream("$type.class")) { + "Can't find resource for class: $type.class" + } return `is`.use { ClassReader(it) } } } diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/ChildProcess.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/ChildProcess.kt index 60aa4b6529..31393d1717 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/ChildProcess.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/ChildProcess.kt @@ -45,7 +45,7 @@ import org.utbot.instrumentation.rd.generated.ComputeStaticFieldResult * We use this ClassLoader to separate user's classes and our dependency classes. * Our classes won't be instrumented. */ -private object HandlerClassesLoader : URLClassLoader(emptyArray()) { +internal object HandlerClassesLoader : URLClassLoader(emptyArray()) { fun addUrls(urls: Iterable) { urls.forEach { super.addURL(File(it).toURI().toURL()) } }