Skip to content

Commit 989d783

Browse files
committed
using copy only if instanceParameter is not null
1 parent 5e9b549 commit 989d783

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/main/kotlin/com/papsign/ktor/openapigen/validation/ValidationHandler.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,10 @@ class ValidationHandler private constructor(
235235
transformFun = { t: Any? ->
236236
if (t != null) {
237237
val copy = t.javaClass.kotlin.memberFunctions.find { it.name == "copy" }
238-
val copyParams = copy?.instanceParameter?.let { mutableMapOf<KParameter, Any?>(it to t) } ?: mutableMapOf()
238+
val copyParams = copy?.instanceParameter?.let { mutableMapOf<KParameter, Any?>(it to t) }
239239
handled.forEach { (handler, field) ->
240240
val getter = field.kotlinProperty?.javaGetter
241-
if (copy != null && getter != null) {
241+
if (copy != null && copyParams != null && getter != null) {
242242
val param = copy.parameters.first { it.name == field.name }
243243
copyParams[param] = handler.handle(getter(t))
244244
} else {
@@ -249,7 +249,9 @@ class ValidationHandler private constructor(
249249
field.isAccessible = accessible
250250
}
251251
}
252-
copy?.callBy(copyParams.toMap()) ?: t
252+
if (copy != null && copyParams != null) {
253+
copy.callBy(copyParams)
254+
} else t
253255
} else t
254256
}
255257
}

0 commit comments

Comments
 (0)