Kotlin function wrapper treats empty input as no input

Offen
#1,537 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@seonwooj0810 arbeitet bereits daran.

Seit 24.11.2026.

  • #1549 von @seonwooj0810 — offen

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
Ein halber Tag
Anfängerfreundlichkeit
30/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Veraltet
Tech-Stack
java, kotlin, spring
Bereich
backend

Rechercherichtung

Start in the spring-cloud-function-kotlin module at KotlinLambdaToFunctionAutoConfiguration, focusing on KotlinFunctionWrapper.apply, getFunctionRegistration and isTypeRepresentedByClass. Read the existing Kotlin function tests to see how a (String) -> String function is registered, then change the empty check to input == null and add tests for empty string, collection, map, array and Optional, plus the suffix and Function1/Function10 cases. Done means the module tests pass and empty inputs reach the function instead of throwing ClassCastException.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

5.0.x backport bug

KotlinLambdaToFunctionAutoConfiguration.KotlinFunctionWrapper.apply(Object) decides between calling the function with an argument and without one using ObjectUtils.isEmpty(input). That is also true for an empty String, an empty collection, an empty map, an empty array and an empty Optional, which are valid inputs.

For a Kotlin function of one argument (for example (String) -> String) invoked with "", the wrapper calls invoke() without an argument. That method checks for a Function0 or a suspending supplier and otherwise casts the target to java.util.function.Supplier, which a Kotlin lambda is not, so the call fails with ClassCastException instead of invoking the function with the empty value.

The check should be input == null.

Other problems in the same class:

  • getFunctionRegistration(..) casts the discovered function type to ParameterizedType without checking it, which fails with NullPointerException or ClassCastException if the type can not be determined
  • the bean name suffix is removed with replace(SUFFIX, ""), which removes every occurrence rather than only a trailing one
  • isTypeRepresentedByClass uses getTypeName().contains("kotlin.jvm.functions.Function1"), which also matches Function10 to Function19 (and Function2 matches Function20 to Function22)

There are no tests for this class in the module. Proposed change: fix the null check and the issues above and add unit tests, including empty-string input.

Vorherrschende Sprache
Java
Sterne
1.1k
Forks
655
Ø Merge
4 Std. 54 Min.
Gemergte PRs (30 T.)
10

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus spring-cloud/spring-cloud-function

Alle Issues in spring-cloud/spring-cloud-function

Ähnliche Issues

Weitere Issues zu Java

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.