SmartCompositeMessageConverter fails with NullPointerException or ClassCastException in several conversion paths

Đang mở
#1,535 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@seonwooj0810 đang làm issue này rồi.

Từ ngày 23/11/2026.

  • #1541 của @seonwooj0810 — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Java
Star
1.1k
Fork
655
Merge trung bình
4 giờ 54 phút
Pull request đã merge (30 ngày)
10

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của spring-cloud/spring-cloud-function

Tất cả issue của spring-cloud/spring-cloud-function

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.