Skip to content

Commit eba7ff4

Browse files
Class not found fix #643 (#996)
1 parent d754136 commit eba7ff4

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

utbot-framework/src/main/kotlin/org/utbot/framework/concrete/UtExecutionInstrumentation.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import org.utbot.framework.plugin.api.Instruction
1313
import org.utbot.framework.plugin.api.MissingState
1414
import org.utbot.framework.plugin.api.TimeoutException
1515
import org.utbot.framework.plugin.api.UtAssembleModel
16+
import org.utbot.framework.plugin.api.UtConcreteExecutionFailure
1617
import org.utbot.framework.plugin.api.UtExecutionFailure
1718
import org.utbot.framework.plugin.api.UtExecutionResult
1819
import org.utbot.framework.plugin.api.UtExecutionSuccess
@@ -161,6 +162,7 @@ object UtExecutionInstrumentation : Instrumentation<UtConcreteExecutionResult> {
161162
Coverage()
162163
)
163164
}
165+
164166
throw e
165167
}
166168
val staticFields = constructor
@@ -249,9 +251,12 @@ object UtExecutionInstrumentation : Instrumentation<UtConcreteExecutionResult> {
249251
if (exception is TimeoutException) {
250252
return UtTimeoutException(exception)
251253
}
252-
if (exception is AccessControlException) {
254+
if (exception is AccessControlException ||
255+
exception is ExceptionInInitializerError && exception.exception is AccessControlException) {
253256
return UtSandboxFailure(exception)
254257
}
258+
// there also can be other cases, when we need to wrap internal exception... I suggest adding them on demand
259+
255260
val instrs = traceHandler.computeInstructionList()
256261
val isNested = if (instrs.isEmpty()) {
257262
false

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/instrumenter/Instrumenter.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package org.utbot.instrumentation.instrumentation.instrumenter
22

3+
import org.objectweb.asm.ClassReader
4+
import org.objectweb.asm.ClassVisitor
5+
import org.objectweb.asm.ClassWriter
6+
import org.objectweb.asm.Opcodes
7+
import org.objectweb.asm.Type
8+
import org.objectweb.asm.tree.ClassNode
39
import org.utbot.framework.plugin.api.util.UtContext
410
import org.utbot.instrumentation.Settings
511
import org.utbot.instrumentation.instrumentation.instrumenter.visitors.MethodToProbesVisitor
@@ -9,6 +15,7 @@ import org.utbot.instrumentation.instrumentation.instrumenter.visitors.util.IIns
915
import org.utbot.instrumentation.instrumentation.instrumenter.visitors.util.InstanceFieldInitializer
1016
import org.utbot.instrumentation.instrumentation.instrumenter.visitors.util.InstructionVisitorAdapter
1117
import org.utbot.instrumentation.instrumentation.instrumenter.visitors.util.StaticFieldInitializer
18+
import org.utbot.instrumentation.process.HandlerClassesLoader
1219
import java.io.File
1320
import java.io.IOException
1421
import java.io.InputStream
@@ -17,12 +24,6 @@ import java.nio.file.Path
1724
import java.nio.file.Paths
1825
import kotlin.reflect.KFunction
1926
import kotlin.reflect.jvm.javaMethod
20-
import org.objectweb.asm.ClassReader
21-
import org.objectweb.asm.ClassVisitor
22-
import org.objectweb.asm.ClassWriter
23-
import org.objectweb.asm.Opcodes
24-
import org.objectweb.asm.Type
25-
import org.objectweb.asm.tree.ClassNode
2627

2728

2829
// TODO: handle with flags EXPAND_FRAMES, etc.
@@ -155,7 +156,7 @@ private class TunedClassWriter(
155156
flags: Int
156157
) : ClassWriter(reader, flags) {
157158
override fun getClassLoader(): ClassLoader {
158-
return UtContext.currentContext()?.classLoader ?: this::class.java.classLoader
159+
return HandlerClassesLoader
159160
}
160161
override fun getCommonSuperClass(type1: String, type2: String): String {
161162
try {
@@ -278,8 +279,9 @@ private class TunedClassWriter(
278279
*/
279280
@Throws(IOException::class)
280281
private fun typeInfo(type: String): ClassReader {
281-
val `is`: InputStream = classLoader.getResourceAsStream("$type.class")
282-
?: error("Can't find resource for class: $type.class")
282+
val `is`: InputStream = requireNotNull(classLoader.getResourceAsStream("$type.class")) {
283+
"Can't find resource for class: $type.class"
284+
}
283285
return `is`.use { ClassReader(it) }
284286
}
285287
}

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/ChildProcess.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import org.utbot.instrumentation.rd.generated.ComputeStaticFieldResult
4545
* We use this ClassLoader to separate user's classes and our dependency classes.
4646
* Our classes won't be instrumented.
4747
*/
48-
private object HandlerClassesLoader : URLClassLoader(emptyArray()) {
48+
internal object HandlerClassesLoader : URLClassLoader(emptyArray()) {
4949
fun addUrls(urls: Iterable<String>) {
5050
urls.forEach { super.addURL(File(it).toURI().toURL()) }
5151
}

0 commit comments

Comments
 (0)