Skip to content

Commit

Permalink
Stricter check for enum classes in EnumModelProvider #558
Browse files Browse the repository at this point in the history
Co-author: volivan239

Anonymous inner classes declared for enum constants are not enums
themselves, as the necessary condition for being enums is that their
direct supertype is `java.lang.Enum` (see the JavaDoc and comments of
`java.lang.Class#isEnum` method). For these classes, `getEnumConstants`
method returns `null`.
  • Loading branch information
dtim committed Jul 19, 2022
1 parent 87283e3 commit d08e4af
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object EnumModelProvider : ModelProvider {
override fun generate(description: FuzzedMethodDescription): Sequence<FuzzedParameter> = sequence {
description.parametersMap
.asSequence()
.filter { (classId, _) -> classId.isSubtypeOf(Enum::class.java.id) }
.filter { (classId, _) -> classId.jClass.isEnum }
.forEach { (classId, indices) ->
yieldAllValues(indices, classId.jClass.enumConstants.filterIsInstance<Enum<*>>().map {
UtEnumConstantModel(classId, it).fuzzed { summary = "%var% = ${it.name}" }
Expand Down

0 comments on commit d08e4af

Please sign in to comment.