SmartCompositeMessageConverter fails with NullPointerException or ClassCastException in several conversion paths

Abierto
#1,535 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@seonwooj0810 ya está trabajando en esto.

Desde el 23/11/2026.

  • #1541 de @seonwooj0810 — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
java
Área
backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Java
Estrellas
1.1k
Forks
655
Merge medio
4 h 54 min
PR fusionados (30 d)
10

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de spring-cloud/spring-cloud-function

Todos los issues de spring-cloud/spring-cloud-function

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.