Calling DefaultKafkaHeaderMapper constructor with the same ObjectMapper instance may result memory leak #2611
Labels
ideal-for-user-contribution
An issue that would ideal for a user to get started with contributing.
type: bug
Milestone
In what version(s) of Spring for Apache Kafka are you seeing this issue?
2.8.2
Describe the bug
DefaultKafkaHeaderMapper
is registering aSimpleModule
in constructor to the givenObjectMapper
instance. Since theSimpleModule
's are unnamed modules,IGNORE_DUPLICATE_MODULE_REGISTRATIONS
configuration ofObjectMapper
doesn't handle multiple registration of this module. This is problematic and can cause a memory leak if theDefaultKafkaHeaderMapper(ObjectMapper mapper)
constructor is called with the sameObjectMapper
instance multiple times.To Reproduce
Call the
DefaultKafkaHeaderMapper(ObjectMapper mapper)
function with same ObjectMapper instance multiple times.Expected behavior
A new SimpleModule would be registered to the ObjectMapper beacuse of the
new SimpleModule().addDeserializer(MimeType.class, new MimeTypeJsonDeserializer())
call.Solution
This problematic situation can be avoided simply by giving a name to the SimpleModule created as below:
The text was updated successfully, but these errors were encountered: