SmartCompositeMessageConverter fails with NullPointerException or ClassCastException in several conversion paths

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

Maintainer antworten meist innerhalb von 1 Tag

@seonwooj0810 arbeitet bereits daran.

Seit 23.11.2026.

  • #1541 von @seonwooj0810 — offen

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
java
Bereich
backend

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

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.