Skip to content

Commit 64cf0b0

Browse files
authored
Concrete executor reflection fix (#1332)
[child-process] Setting Field.modifiers accessible fix. Moving child process debug switch to UtSettings.
1 parent ef83e13 commit 64cf0b0

File tree

7 files changed

+34
-22
lines changed

7 files changed

+34
-22
lines changed

utbot-core/src/main/kotlin/org/utbot/common/Logging.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,20 @@ inline fun <T> LoggerWithLogMethod.bracket(
6868
}
6969
}
7070

71-
inline fun <T> KLogger.catch(block: () -> T): T? {
71+
inline fun <T> KLogger.catchException(block: () -> T): T? {
7272
return try {
7373
block()
7474
} catch (e: Throwable) {
7575
this.error(e) { "Isolated" }
7676
null
7777
}
7878
}
79+
80+
inline fun <T> KLogger.logException(block: () -> T): T {
81+
return try {
82+
block()
83+
} catch (e: Throwable) {
84+
this.error("Exception occurred", e)
85+
throw e
86+
}
87+
}

utbot-core/src/main/kotlin/org/utbot/common/ReflectionUtil.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ object Reflection {
3737
fun setModifiers(field: Field, modifiers: Int) {
3838
modifiersField.set(field, modifiers)
3939
}
40+
41+
fun isModifiersAccessible(): Boolean {
42+
return modifiersField.isAccessible
43+
}
4044
}
4145

4246
inline fun <R> AccessibleObject.withAccessibility(block: () -> R): R {

utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,21 @@ object UtSettings : AbstractSettings(
291291
*/
292292
var runIdeaProcessWithDebug by getBooleanProperty(false)
293293

294+
/**
295+
* If true, runs the child process with the ability to attach a debugger.
296+
*
297+
* To debug the child process, set the breakpoint in the childProcessRunner.start() line
298+
* and in the child process's main function and run the main process.
299+
* Then run the remote JVM debug configuration in IDEA.
300+
* If you see the message in console about successful connection, then
301+
* the debugger is attached successfully.
302+
* Now you can put the breakpoints in the child process and debug
303+
* both processes simultaneously.
304+
*
305+
* @see [org.utbot.instrumentation.process.ChildProcessRunner.cmds]
306+
*/
307+
var runChildProcessWithDebug by getBooleanProperty(false)
308+
294309
/**
295310
* Number of branch instructions using for clustering executions in the test minimization phase.
296311
*/

utbot-framework/src/main/kotlin/org/utbot/engine/ValueConstructor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.utbot.engine
22

3+
import org.utbot.common.Reflection
34
import org.utbot.common.invokeCatching
45
import org.utbot.framework.plugin.api.ClassId
56
import org.utbot.engine.util.lambda.CapturedArgument
@@ -239,8 +240,7 @@ class ValueConstructor {
239240
try {
240241
declaredField.isAccessible = true
241242

242-
val modifiersField = Field::class.java.getDeclaredField("modifiers")
243-
modifiersField.isAccessible = true
243+
check(Reflection.isModifiersAccessible())
244244

245245
val target = mockTarget(fieldModel) {
246246
FieldMockTarget(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import kotlin.reflect.KClass
4444
import org.mockito.Mockito
4545
import org.mockito.stubbing.Answer
4646
import org.objectweb.asm.Type
47+
import org.utbot.common.Reflection
4748
import org.utbot.engine.util.lambda.CapturedArgument
4849
import org.utbot.engine.util.lambda.constructLambda
4950
import org.utbot.engine.util.lambda.constructStaticLambda
@@ -189,8 +190,7 @@ class MockValueConstructor(
189190
val accessible = declaredField.isAccessible
190191
declaredField.isAccessible = true
191192

192-
val modifiersField = Field::class.java.getDeclaredField("modifiers")
193-
modifiersField.isAccessible = true
193+
check(Reflection.isModifiersAccessible())
194194

195195
val target = mockTarget(fieldModel) {
196196
FieldMockTarget(fieldModel.classId.name, model.classId.name, UtConcreteValue(classInstance), fieldId.name)

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/Settings.kt

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,5 @@ object Settings {
1414

1515
const val TRACE_ARRAY_SIZE: Int = 1 shl 20
1616

17-
// TODO: maybe add this guide to confluence?
18-
/**
19-
* If true, runs the child process with the ability to attach a debugger.
20-
*
21-
* To debug the child process, set the breakpoint in the childProcessRunner.start() line
22-
* and in the child process's main function and run the main process.
23-
* Then run the remote JVM debug configuration in IDEA.
24-
* If you see the message in console about successful connection, then
25-
* the debugger is attached successfully.
26-
* Now you can put the breakpoints in the child process and debug
27-
* both processes simultaneously.
28-
*
29-
* @see [org.utbot.instrumentation.process.ChildProcessRunner.cmds]
30-
*/
31-
const val runChildProcessWithDebug = false
32-
3317
var defaultConcreteExecutorPoolSize = 10
3418
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ChildProcessRunner {
2020
private val id = Random.nextLong()
2121
private var processSeqN = 0
2222
private val cmds: List<String> by lazy {
23-
val debugCmd = listOfNotNull(DEBUG_RUN_CMD.takeIf { Settings.runChildProcessWithDebug })
23+
val debugCmd = listOfNotNull(DEBUG_RUN_CMD.takeIf { UtSettings.runChildProcessWithDebug })
2424
val javaVersionSpecificArguments = OpenModulesContainer.javaVersionSpecificArguments
2525
val pathToJava = JdkInfoService.provide().path
2626

0 commit comments

Comments
 (0)