From 6490197cf9ceebdd1704cff28d6c30d4a9580d8d Mon Sep 17 00:00:00 2001 From: "Vassiliy.Kudryashov" Date: Wed, 18 Jan 2023 16:15:26 +0300 Subject: [PATCH 1/2] Fuzzing generates impossible UtAssembleModels #1684 --- .../utbot/fuzzing/providers/Collections.kt | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/utbot-fuzzers/src/main/kotlin/org/utbot/fuzzing/providers/Collections.kt b/utbot-fuzzers/src/main/kotlin/org/utbot/fuzzing/providers/Collections.kt index 87fc8a61c3..9c5b8a75e3 100644 --- a/utbot-fuzzers/src/main/kotlin/org/utbot/fuzzing/providers/Collections.kt +++ b/utbot-fuzzers/src/main/kotlin/org/utbot/fuzzing/providers/Collections.kt @@ -182,6 +182,8 @@ abstract class CollectionValueProvider( abstract fun findMethod(resolvedType: FuzzedType, values: List) : MethodId + private val FuzzedType.isCollection get() = this.classId.isSubtypeOf(java.util.Collection::class) + override fun generate(description: FuzzedDescription, type: FuzzedType) = sequence> { resolveType(description, type).forEach { resolvedType -> val typeParameter = resolvedType.generics @@ -198,17 +200,19 @@ abstract class CollectionValueProvider( ), modificationsChainProvider = { mutableListOf() } ).fuzzed { - summary = "%var% = collection" + summary = if (resolvedType.isCollection) "%var% = collection" else "%var% = iterable" } }, - modify = Routine.ForEach(typeParameter) { self, _, values -> - val model = self.model as UtAssembleModel - (model.modificationsChain as MutableList) += UtExecutableCallModel( - model, - findMethod(resolvedType, values), - values.map { it.model } - ) - } + modify = if (resolvedType.isCollection) { + Routine.ForEach(typeParameter) { self, _, values -> + val model = self.model as UtAssembleModel + (model.modificationsChain as MutableList) += UtExecutableCallModel( + model, + findMethod(resolvedType, values), + values.map { it.model } + ) + } + } else Routine.ForEach(typeParameter) { _, _, _ -> run {} } //No mutations for java.lang.Iterable )) } } From f34dea71738b720b2eed331b368648c9469fe9ce Mon Sep 17 00:00:00 2001 From: "Vassiliy.Kudryashov" Date: Fri, 20 Jan 2023 17:48:15 +0300 Subject: [PATCH 2/2] Fuzzing generates impossible UtAssembleModels #1684 Process "Iterable but not a Collection" with ObjectValueProvider --- .../utbot/framework/plugin/api/util/IdUtil.kt | 7 +++++ .../utbot/fuzzing/providers/Collections.kt | 28 +++++++------------ .../org/utbot/fuzzing/providers/Objects.kt | 2 +- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/IdUtil.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/IdUtil.kt index ec03e8995c..b1d7d9e710 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/IdUtil.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/IdUtil.kt @@ -301,6 +301,7 @@ val atomicIntegerGetAndIncrement = MethodId(atomicIntegerClassId, "getAndIncreme val iterableClassId = java.lang.Iterable::class.id val mapClassId = java.util.Map::class.id +val collectionClassId = java.util.Collection::class.id val baseStreamClassId = java.util.stream.BaseStream::class.id val streamClassId = java.util.stream.Stream::class.id @@ -405,6 +406,12 @@ val ClassId.isMap: Boolean val ClassId.isIterableOrMap: Boolean get() = isIterable || isMap +val ClassId.isCollection: Boolean + get() = isSubtypeOf(collectionClassId) + +val ClassId.isCollectionOrMap: Boolean + get() = isCollection || isMap + val ClassId.isEnum: Boolean get() = jClass.isEnum diff --git a/utbot-fuzzers/src/main/kotlin/org/utbot/fuzzing/providers/Collections.kt b/utbot-fuzzers/src/main/kotlin/org/utbot/fuzzing/providers/Collections.kt index 9c5b8a75e3..c5309c3694 100644 --- a/utbot-fuzzers/src/main/kotlin/org/utbot/fuzzing/providers/Collections.kt +++ b/utbot-fuzzers/src/main/kotlin/org/utbot/fuzzing/providers/Collections.kt @@ -107,14 +107,10 @@ class MapValueProvider( class ListSetValueProvider( idGenerator: IdGenerator -) : CollectionValueProvider(idGenerator, java.lang.Iterable::class.id) { +) : CollectionValueProvider(idGenerator, java.util.Collection::class.id) { override fun resolveType(description: FuzzedDescription, type: FuzzedType) = sequence { val generic = type.generics.firstOrNull() ?: FuzzedType(objectClassId) when (type.classId) { - java.lang.Iterable::class.id -> { - yield(FuzzedType(java.util.ArrayList::class.id, listOf(generic))) - yield(FuzzedType(java.util.HashSet::class.id, listOf(generic))) - } java.util.Queue::class.id, java.util.Deque::class.id-> { yield(FuzzedType(java.util.ArrayDeque::class.id, listOf(generic))) @@ -182,8 +178,6 @@ abstract class CollectionValueProvider( abstract fun findMethod(resolvedType: FuzzedType, values: List) : MethodId - private val FuzzedType.isCollection get() = this.classId.isSubtypeOf(java.util.Collection::class) - override fun generate(description: FuzzedDescription, type: FuzzedType) = sequence> { resolveType(description, type).forEach { resolvedType -> val typeParameter = resolvedType.generics @@ -200,19 +194,17 @@ abstract class CollectionValueProvider( ), modificationsChainProvider = { mutableListOf() } ).fuzzed { - summary = if (resolvedType.isCollection) "%var% = collection" else "%var% = iterable" + summary = "%var% = collection" } }, - modify = if (resolvedType.isCollection) { - Routine.ForEach(typeParameter) { self, _, values -> - val model = self.model as UtAssembleModel - (model.modificationsChain as MutableList) += UtExecutableCallModel( - model, - findMethod(resolvedType, values), - values.map { it.model } - ) - } - } else Routine.ForEach(typeParameter) { _, _, _ -> run {} } //No mutations for java.lang.Iterable + modify = Routine.ForEach(typeParameter) { self, _, values -> + val model = self.model as UtAssembleModel + (model.modificationsChain as MutableList) += UtExecutableCallModel( + model, + findMethod(resolvedType, values), + values.map { it.model } + ) + } )) } } diff --git a/utbot-fuzzers/src/main/kotlin/org/utbot/fuzzing/providers/Objects.kt b/utbot-fuzzers/src/main/kotlin/org/utbot/fuzzing/providers/Objects.kt index 0b35d166e2..4723c0ddc9 100644 --- a/utbot-fuzzers/src/main/kotlin/org/utbot/fuzzing/providers/Objects.kt +++ b/utbot-fuzzers/src/main/kotlin/org/utbot/fuzzing/providers/Objects.kt @@ -97,7 +97,7 @@ class ObjectValueProvider( private fun isIgnored(type: ClassId): Boolean { return unwantedConstructorsClasses.contains(type) - || type.isIterableOrMap + || type.isCollectionOrMap || type.isPrimitiveWrapper || type.isEnum || type.isAbstract