Kotlin function wrapper treats empty input as no input

未关闭
#1,537 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@seonwooj0810 已经在做这个了。

开始于 2026年11月24日。

  • #1549 来自 @seonwooj0810 —— 未关闭

评估

难度
3/5
预计耗时
半天
新手友好度
30/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
java, kotlin, spring
领域
backend

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Java
星标
1.1k
派生
655
平均合并
4 小时 54 分钟
30 天内合并 PR
10

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

spring-cloud/spring-cloud-function 的其他 Issue

查看 spring-cloud/spring-cloud-function 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。