-
Notifications
You must be signed in to change notification settings - Fork 83
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
Bug Fix - NullPointerException in Kafka Connect Pipeline when JMS Property Key is Empty #144
base: main
Are you sure you want to change the base?
Conversation
…operties, the kafka connect pipeline is failing with NullpointerException while sinking the data to kafka . This scenario is handled in try block in the JmsToKafkaHeaderConverter class
@@ -48,7 +48,13 @@ public ConnectHeaders convertJmsPropertiesToKafkaHeaders(final Message message) | |||
|
|||
jmsPropertyKeys.forEach(key -> { | |||
try { | |||
connectHeaders.addString(key.toString(), message.getObjectProperty(key.toString()).toString()); | |||
String value = ""; | |||
if (message.getObjectProperty(key.toString()) != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit comment: you can extract message.getObjectProperty(key.toString())
to a value and refer to both the places.
value = message.getObjectProperty(key.toString()).toString(); | ||
} | ||
connectHeaders.addString(key.toString(), value); | ||
//connectHeaders.addString(key.toString(), message.getObjectProperty(key.toString()).toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit comment: Remove the commented line. It is not needed.
@@ -48,7 +48,13 @@ public ConnectHeaders convertJmsPropertiesToKafkaHeaders(final Message message) | |||
|
|||
jmsPropertyKeys.forEach(key -> { | |||
try { | |||
connectHeaders.addString(key.toString(), message.getObjectProperty(key.toString()).toString()); | |||
String value = ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we add empty value or null ?
|
||
// Act | ||
final ConnectHeaders actualConnectHeaders = jmsToKafkaHeaderConverter | ||
.convertJmsPropertiesToKafkaHeaders(message); | ||
|
||
|
||
//Verify | ||
assertEquals("Both custom JMS properties were copied to kafka successfully.", 2, actualConnectHeaders.size()); | ||
assertEquals("Both custom JMS properties were copied to kafka successfully.", 3, actualConnectHeaders.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit comment: Both -> All three
In MQ, if the value for any of the JMS property keys is empty, and we set the property mq.jms.properties.copy.to.kafka.headers = true in our connector properties, the Kafka Connect pipeline fails with a "NullPointerException" while attaching those properties in my kafka headers , As a result, the messages are routed to the BO queue.
Type of issue - Bug fix (non-breaking change which fixes an issue)
How Has This Been Tested? - YES
Tried setting the flag as false for mq.jms.properties.copy.to.kafka.headers and there are no exception but the properties from my MQ is not attached to my kafka headers
Handled the scneario in the jmsToKafkaHeaderConverter class , where is the value for a key is empty/null then we are passing the value for that particular key as a empty string "" , by doing this the messages are not moving to BO queue and my kafka connect pipeline is running without any exception
Checklist