Skip to content

Class not found fix #643 #996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -161,6 +162,7 @@ object UtExecutionInstrumentation : Instrumentation<UtConcreteExecutionResult> {
Coverage()
)
}

throw e
}
val staticFields = constructor
Expand Down Expand Up @@ -249,9 +251,12 @@ object UtExecutionInstrumentation : Instrumentation<UtConcreteExecutionResult> {
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) {
urls.forEach { super.addURL(File(it).toURI().toURL()) }
}
Expand Down