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.
#17966 MessageHeaders mutable through Map.Entry.setValue()
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.