Skip to content

AbstractJacksonMessageConverter throws InvalidMimeTypeException for a malformed content type #3743

Closed

Description

@sharanggupta

In what version(s) of Spring AMQP are you seeing this issue?

4.0.x and 4.1.x since GH-3520, and main.

Describe the bug

AbstractJacksonMessageConverter#fromMessage checks the incoming content type with this.supportedContentType.isCompatibleWith(MimeType.valueOf(contentType)). MimeType.valueOf throws InvalidMimeTypeException for a value that is not a MIME type, such as json or text, which third-party publishers do set. Before GH-3520 such a message was either converted ("json".contains("json")) or returned as byte[] with a warning; now the exception escapes fromMessage. As it is an IllegalArgumentException rather than a MessageConversionException, ConditionalRejectingErrorHandler does not consider it fatal, so the message is requeued and redelivered indefinitely.

determineEncoding, a few lines below, already guards its own MimeTypeUtils.parseMimeType(contentType) against exactly this.

To Reproduce

JacksonJsonMessageConverter converter = new JacksonJsonMessageConverter();
MessageProperties properties = new MessageProperties();
properties.setContentType("json");
converter.fromMessage(new Message("{\"ticker\":\"VMW\"}".getBytes(), properties));
// org.springframework.util.InvalidMimeTypeException: Invalid mime type "json": does not contain '/'

Expected behavior

A content type that cannot be parsed is treated like an unsupported one: the usual warning is logged and the body is returned as is (or Optional.empty() with nullAsOptionalEmpty), so listener error handling sees the same outcome as for any other non-JSON content type.

Sample

Branch with the fix and a test: main...sharanggupta:spring-amqp:jackson-converter-malformed-content-type (isSupportedContentType catches InvalidMimeTypeException and returns false). Happy to open the PR.

Activity

  1. artembilan commented on Oct 26, 2026

    @artembilan
    Member

    @sharanggupta ,

    Please, be our guest.

    Happy to review and merge your PR.

    Thank you!

  2. added this to the 4.2.0 milestone on Oct 26, 2026
  3. sharanggupta commented on Oct 26, 2026

    @sharanggupta
    ContributorAuthor

    Thanks, @artembilan, opened #3779.

  4. added a commit that references this issue on Oct 26, 2026
  5. added 2 commits that reference this issue on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions