Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MessageHeaders is declared immutable - but writeObject() removes any non-serializable fields [SPR-13541] #18117

spring-projects-issues opened this issue Mar 18, 2015 · 2 comments
in: messaging type: bug


Copy link

@spring-projects-issues spring-projects-issues commented Mar 18, 2015

John Nichol opened SPR-13541 and commented

org.springframework.messaging.MessageHeaders clearly states it is immutable in its JavaDoc. However the private void writeObject(ObjectOutputStream out) method any non-serializable values in the map are actually removed from the headers,


rather than simply not being placed in the output stream.

So a result (and I appreciate this is probably an usual use case), if the MessageHeaders are serialized in say a ChannelInterceptor it is possible to break a message flow by accidentally removing the reply-channel from the headers.

The correct implementation is to write the keys/values that ARE serializable as a map into the output stream rather than the whole map.

Affects: 4.2.1

Issue Links:

  • #17966 MessageHeaders mutable through Map.Entry.setValue()

Referenced from: commits 181533c

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 5, 2015

Artem Bilan commented

Moved to Spring Framework JIRA to consider, because the requested MessageHeaders is exactly there in the Messaging module.

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 6, 2015

Juergen Hoeller commented

Good point. I've addressed this through serializing a temporary copy of MessageHeaders if necessary, not including the non-serializable entries. The original MessageHeaders instance will now always retain the full set of entries, even after having being serialized at any point.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
in: messaging type: bug
None yet

No branches or pull requests

2 participants