@@ -14,7 +14,6 @@ typealias JavaValueProvider = ValueProvider<FuzzedType, FuzzedValue, FuzzedDescr
14
14
class FuzzedDescription (
15
15
val description : FuzzedMethodDescription ,
16
16
val tracer : Trie <Instruction , * >,
17
- val genThisInstance : ClassId ? ,
18
17
) : Description<FuzzedType>(
19
18
description.parameters.mapIndexed { index, classId ->
20
19
description.fuzzerType(index) ? : FuzzedType (classId)
@@ -47,7 +46,7 @@ suspend fun runJavaFuzzing(
47
46
names : List <String >,
48
47
mock : (ClassId ) -> Boolean = { false },
49
48
providers : List <ValueProvider <FuzzedType , FuzzedValue , FuzzedDescription >> = defaultValueProviders(idGenerator),
50
- exec : suspend (description: FuzzedDescription , values: List <FuzzedValue >) -> BaseFeedback <Trie .Node <Instruction >, FuzzedType , FuzzedValue >
49
+ exec : suspend (thisInstance: FuzzedValue ? , description: FuzzedDescription , values: List <FuzzedValue >) -> BaseFeedback <Trie .Node <Instruction >, FuzzedType , FuzzedValue >
51
50
) {
52
51
val classUnderTest = methodUnderTest.classId
53
52
val thisInstance = with (methodUnderTest) {
@@ -61,17 +60,27 @@ suspend fun runJavaFuzzing(
61
60
val returnType = methodUnderTest.returnType
62
61
val parameters = listOfNotNull(thisInstance) + methodUnderTest.parameters
63
62
64
- val fmd = FuzzedMethodDescription (
63
+ /* *
64
+ * To fuzz this instance the class of it is added into head of parameters list.
65
+ * Done for compatibility with old fuzzer logic and should be reworked more robust way.
66
+ */
67
+ fun createFuzzedMethodDescription (thisInstance : ClassId ? ) = FuzzedMethodDescription (
65
68
name, returnType, parameters, constants
66
69
).apply {
67
70
compilableName = if (! methodUnderTest.isConstructor) methodUnderTest.name else null
68
71
className = classUnderTest.simpleName
69
72
packageName = classUnderTest.packageName
70
- parameterNameMap = { index -> names.getOrNull(index) }
73
+ parameterNameMap = { index ->
74
+ when {
75
+ thisInstance != null && index == 0 -> " this"
76
+ thisInstance != null -> names.getOrNull(index - 1 )
77
+ else -> names.getOrNull(index)
78
+ }
79
+ }
71
80
fuzzerType = {
72
81
try {
73
82
when {
74
- thisInstance != null && it == 0 -> toFuzzerType(classUnderTest.jClass )
83
+ thisInstance != null && it == 0 -> toFuzzerType(methodUnderTest.executable.declaringClass )
75
84
thisInstance != null -> toFuzzerType(methodUnderTest.executable.genericParameterTypes[it - 1 ])
76
85
else -> toFuzzerType(methodUnderTest.executable.genericParameterTypes[it])
77
86
}
@@ -81,8 +90,17 @@ suspend fun runJavaFuzzing(
81
90
}
82
91
shouldMock = mock
83
92
}
84
- BaseFuzzing (providers, exec)
85
- .fuzz(FuzzedDescription (fmd, Trie (Instruction ::id), thisInstance))
93
+
94
+ val tracer = Trie (Instruction ::id)
95
+ val descriptionWithOptionalThisInstance = FuzzedDescription (createFuzzedMethodDescription(thisInstance), tracer)
96
+ val descriptionWithOnlyParameters = FuzzedDescription (createFuzzedMethodDescription(null ), tracer)
97
+ BaseFuzzing (providers) { d, t ->
98
+ if (thisInstance == null ) {
99
+ exec(null , d, t)
100
+ } else {
101
+ exec(t.first(), descriptionWithOnlyParameters, t.drop(1 ))
102
+ }
103
+ }.fuzz(descriptionWithOptionalThisInstance)
86
104
}
87
105
88
106
private fun toFuzzerType (type : Type ): FuzzedType {
0 commit comments