@@ -49,39 +49,32 @@ suspend fun runJavaFuzzing(
49
49
exec : suspend (thisInstance: FuzzedValue ? , description: FuzzedDescription , values: List <FuzzedValue >) -> BaseFeedback <Trie .Node <Instruction >, FuzzedType , FuzzedValue >
50
50
) {
51
51
val classUnderTest = methodUnderTest.classId
52
- val thisInstance = with (methodUnderTest) {
53
- if (! isStatic && ! isConstructor) {
54
- classUnderTest
55
- } else {
56
- null
57
- }
58
- }
59
52
val name = methodUnderTest.classId.simpleName + " ." + methodUnderTest.name
60
53
val returnType = methodUnderTest.returnType
61
- val parameters = listOfNotNull(thisInstance) + methodUnderTest.parameters
54
+ val parameters = methodUnderTest.parameters
62
55
63
56
/* *
64
57
* To fuzz this instance the class of it is added into head of parameters list.
65
58
* Done for compatibility with old fuzzer logic and should be reworked more robust way.
66
59
*/
67
- fun createFuzzedMethodDescription (thisInstance : ClassId ? ) = FuzzedMethodDescription (
68
- name, returnType, parameters, constants
60
+ fun createFuzzedMethodDescription (self : ClassId ? ) = FuzzedMethodDescription (
61
+ name, returnType, listOfNotNull(self) + parameters, constants
69
62
).apply {
70
63
compilableName = if (! methodUnderTest.isConstructor) methodUnderTest.name else null
71
64
className = classUnderTest.simpleName
72
65
packageName = classUnderTest.packageName
73
66
parameterNameMap = { index ->
74
67
when {
75
- thisInstance != null && index == 0 -> " this"
76
- thisInstance != null -> names.getOrNull(index - 1 )
68
+ self != null && index == 0 -> " this"
69
+ self != null -> names.getOrNull(index - 1 )
77
70
else -> names.getOrNull(index)
78
71
}
79
72
}
80
73
fuzzerType = {
81
74
try {
82
75
when {
83
- thisInstance != null && it == 0 -> toFuzzerType(methodUnderTest.executable.declaringClass)
84
- thisInstance != null -> toFuzzerType(methodUnderTest.executable.genericParameterTypes[it - 1 ])
76
+ self != null && it == 0 -> toFuzzerType(methodUnderTest.executable.declaringClass)
77
+ self != null -> toFuzzerType(methodUnderTest.executable.genericParameterTypes[it - 1 ])
85
78
else -> toFuzzerType(methodUnderTest.executable.genericParameterTypes[it])
86
79
}
87
80
} catch (_: Throwable ) {
@@ -91,12 +84,15 @@ suspend fun runJavaFuzzing(
91
84
shouldMock = mock
92
85
}
93
86
87
+ val thisInstance = with (methodUnderTest) {
88
+ if (! isStatic && ! isConstructor) { classUnderTest } else { null }
89
+ }
94
90
val tracer = Trie (Instruction ::id)
95
91
val descriptionWithOptionalThisInstance = FuzzedDescription (createFuzzedMethodDescription(thisInstance), tracer)
96
92
val descriptionWithOnlyParameters = FuzzedDescription (createFuzzedMethodDescription(null ), tracer)
97
- BaseFuzzing (providers) { d , t ->
93
+ BaseFuzzing (providers) { _ , t ->
98
94
if (thisInstance == null ) {
99
- exec(null , d , t)
95
+ exec(null , descriptionWithOnlyParameters , t)
100
96
} else {
101
97
exec(t.first(), descriptionWithOnlyParameters, t.drop(1 ))
102
98
}
0 commit comments