Skip to content

Concrete executor reflection fix #1332

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
Nov 9, 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
11 changes: 10 additions & 1 deletion utbot-core/src/main/kotlin/org/utbot/common/Logging.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,20 @@ inline fun <T> LoggerWithLogMethod.bracket(
}
}

inline fun <T> KLogger.catch(block: () -> T): T? {
inline fun <T> KLogger.catchException(block: () -> T): T? {
return try {
block()
} catch (e: Throwable) {
this.error(e) { "Isolated" }
null
}
}

inline fun <T> KLogger.logException(block: () -> T): T {
return try {
block()
} catch (e: Throwable) {
this.error("Exception occurred", e)
throw e
}
}
4 changes: 4 additions & 0 deletions utbot-core/src/main/kotlin/org/utbot/common/ReflectionUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ object Reflection {
fun setModifiers(field: Field, modifiers: Int) {
modifiersField.set(field, modifiers)
}

fun isModifiersAccessible(): Boolean {
return modifiersField.isAccessible
}
}

inline fun <R> AccessibleObject.withAccessibility(block: () -> R): R {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,21 @@ object UtSettings : AbstractSettings(
*/
var runIdeaProcessWithDebug by getBooleanProperty(false)

/**
* If true, runs the child process with the ability to attach a debugger.
*
* To debug the child process, set the breakpoint in the childProcessRunner.start() line
* and in the child process's main function and run the main process.
* Then run the remote JVM debug configuration in IDEA.
* If you see the message in console about successful connection, then
* the debugger is attached successfully.
* Now you can put the breakpoints in the child process and debug
* both processes simultaneously.
*
* @see [org.utbot.instrumentation.process.ChildProcessRunner.cmds]
*/
var runChildProcessWithDebug by getBooleanProperty(false)

/**
* Number of branch instructions using for clustering executions in the test minimization phase.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.utbot.engine

import org.utbot.common.Reflection
import org.utbot.common.invokeCatching
import org.utbot.framework.plugin.api.ClassId
import org.utbot.engine.util.lambda.CapturedArgument
Expand Down Expand Up @@ -239,8 +240,7 @@ class ValueConstructor {
try {
declaredField.isAccessible = true

val modifiersField = Field::class.java.getDeclaredField("modifiers")
modifiersField.isAccessible = true
check(Reflection.isModifiersAccessible())

val target = mockTarget(fieldModel) {
FieldMockTarget(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import kotlin.reflect.KClass
import org.mockito.Mockito
import org.mockito.stubbing.Answer
import org.objectweb.asm.Type
import org.utbot.common.Reflection
import org.utbot.engine.util.lambda.CapturedArgument
import org.utbot.engine.util.lambda.constructLambda
import org.utbot.engine.util.lambda.constructStaticLambda
Expand Down Expand Up @@ -189,8 +190,7 @@ class MockValueConstructor(
val accessible = declaredField.isAccessible
declaredField.isAccessible = true

val modifiersField = Field::class.java.getDeclaredField("modifiers")
modifiersField.isAccessible = true
check(Reflection.isModifiersAccessible())

val target = mockTarget(fieldModel) {
FieldMockTarget(fieldModel.classId.name, model.classId.name, UtConcreteValue(classInstance), fieldId.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,5 @@ object Settings {

const val TRACE_ARRAY_SIZE: Int = 1 shl 20

// TODO: maybe add this guide to confluence?
/**
* If true, runs the child process with the ability to attach a debugger.
*
* To debug the child process, set the breakpoint in the childProcessRunner.start() line
* and in the child process's main function and run the main process.
* Then run the remote JVM debug configuration in IDEA.
* If you see the message in console about successful connection, then
* the debugger is attached successfully.
* Now you can put the breakpoints in the child process and debug
* both processes simultaneously.
*
* @see [org.utbot.instrumentation.process.ChildProcessRunner.cmds]
*/
const val runChildProcessWithDebug = false

var defaultConcreteExecutorPoolSize = 10
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ChildProcessRunner {
private val id = Random.nextLong()
private var processSeqN = 0
private val cmds: List<String> by lazy {
val debugCmd = listOfNotNull(DEBUG_RUN_CMD.takeIf { Settings.runChildProcessWithDebug })
val debugCmd = listOfNotNull(DEBUG_RUN_CMD.takeIf { UtSettings.runChildProcessWithDebug })
val javaVersionSpecificArguments = OpenModulesContainer.javaVersionSpecificArguments
val pathToJava = JdkInfoService.provide().path

Expand Down