Skip to content

Commit dafaf24

Browse files
committed
fix nd checking
1 parent 5398ffc commit dafaf24

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/ndd/NonDeterministicClassVisitor.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.utbot.instrumentation.instrumentation.execution.ndd
33
import org.objectweb.asm.ClassVisitor
44
import org.objectweb.asm.MethodVisitor
55
import org.objectweb.asm.commons.Method
6+
import org.utbot.framework.plugin.api.ClassId
67
import org.utbot.framework.plugin.api.MethodId
78
import org.utbot.framework.plugin.api.util.executableId
89
import org.utbot.framework.plugin.api.util.id
@@ -19,15 +20,15 @@ class NonDeterministicClassVisitor(
1920
private fun getOwnerClass(owner: String): Class<*> =
2021
utContext.classLoader.loadClass(owner.replace('/', '.'))
2122

22-
private fun getMethodId(owner: String?, name: String?, descriptor: String?): MethodId? {
23+
private fun getMethodAndOwnerId(owner: String?, name: String?, descriptor: String?): Pair<ClassId, MethodId>? {
2324
if (owner == null || name == null || descriptor == null) {
2425
return null
2526
}
2627
val clazz = getOwnerClass(owner)
2728
val method = clazz.methods.find {
2829
it.name == name && Method.getMethod(it).descriptor == descriptor
29-
}
30-
return method?.executableId
30+
} ?: return null
31+
return clazz.id to method.executableId
3132
}
3233

3334
override fun visit(
@@ -68,8 +69,8 @@ class NonDeterministicClassVisitor(
6869
return
6970
}
7071

71-
getMethodId(owner, name, descriptor)?.let { method ->
72-
if (detector.isNonDeterministic(method)) {
72+
getMethodAndOwnerId(owner, name, descriptor)?.let { (caller, method) ->
73+
if (detector.isNonDeterministic(caller, method)) {
7374
detector.inserter.insertBeforeNDMethod(mv, method)
7475
mv.visitMethodInsn(opcodeAndSource, owner, name, descriptor, isInterface)
7576
detector.inserter.insertAfterNDMethod(mv, method)

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/ndd/NonDeterministicDetector.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ package org.utbot.instrumentation.instrumentation.execution.ndd
22

33
import org.utbot.framework.plugin.api.ClassId
44
import org.utbot.framework.plugin.api.MethodId
5-
import org.utbot.framework.plugin.api.util.executableId
65
import org.utbot.framework.plugin.api.util.id
76
import org.utbot.framework.plugin.api.util.isStatic
8-
import java.lang.reflect.Method
97
import kotlin.random.Random
108

119
class NonDeterministicDetector {
@@ -18,11 +16,11 @@ class NonDeterministicDetector {
1816

1917
val inserter = NonDeterministicBytecodeInserter()
2018

21-
fun isNonDeterministic(method: MethodId): Boolean {
19+
fun isNonDeterministic(caller: ClassId, method: MethodId): Boolean {
2220
return if (method.isStatic) {
2321
nonDeterministicStaticMethods.contains(method)
2422
} else {
25-
isNonDeterministic(method.classId)
23+
isNonDeterministic(caller)
2624
}
2725
}
2826

0 commit comments

Comments
 (0)