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

Bug Fix - NullPointerException in Kafka Connect Pipeline when JMS Property Key is Empty #144

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

balajisekarraman
Copy link

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

  • My code follows the style guidelines of this project - YES
  • I have performed a self-review of my code - YES
  • I have commented my code, particularly in hard-to-understand areas - YES
  • My changes generate no new warnings - YES
  • I have added tests that prove my fix is effective or that my feature works - YES
  • New and existing unit tests pass locally with my changes - YES

…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
@balajisekarraman balajisekarraman changed the title Bug fix - Null handling for empty values in JMS Header properties Bug Fix - NullPointerException in Kafka Connect Pipeline when JMS Property Key is Empty Feb 12, 2025
@@ -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)

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());

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 = "";

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());

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants