SmartCompositeMessageConverter fails with NullPointerException or ClassCastException in several conversion paths

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

维护者通常 1 天内回复

@seonwooj0810 已经在做这个了。

开始于 2026年11月23日。

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

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java
领域
backend

调研方向

Start in SmartCompositeMessageConverter and compare the two-argument toMessage/fromMessage variants, which already do the instanceof and content-type checks, against the three-argument ones. Each bullet in the issue maps to one guard to copy over: null headers/content type, instanceof before casting, per-converter try/catch, null-safe element handling, and && instead of &. Add a test per case in the converter's existing test class, then run the module's test suite. Note that an open pull request (#1541) already targets this, so check with maintainers before starting.

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

描述

5.0.x backport bug

SmartCompositeMessageConverter has several paths that fail with an unexpected exception instead of converting or returning null:

  • toMessage(payload, headers, hint) calls headers.get(CONTENT_TYPE).toString(), which throws NullPointerException when the headers or the content type are missing (the two-argument variant checks the content type)
  • the same method casts each converter unconditionally to AbstractMessageConverter and SmartMessageConverter, so a converter that is neither (for example one provided by the user) causes ClassCastException, while the two-argument variant uses instanceof
  • the three-argument fromMessage(..) has no try/catch and no per-converter failure handling, unlike the two-argument variant, so one converter that throws (for example on a malformed content type header) aborts the whole chain
  • when converting an Iterable, item.getClass() is called without a null check, so a null element causes NullPointerException
  • one condition uses the non short-circuiting & instead of &&

In addition, the MessageConversionException message contains the complete message (payload and headers), which may end up in logs or in responses if a caller exposes the exception message, and the converter list is copied for every message.

Proposed change: make the three-argument variants behave like the two-argument ones (null checks, instanceof checks, per-converter error handling), use &&, and add tests for each case above.

主要语言
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 摘要。