-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Nit comment: you can extract |
||
{ | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Nit comment: Remove the commented line. It is not needed. |
||
} catch (final JMSException e) { | ||
// Not failing the message processing if JMS properties cannot be read for some | ||
// reason. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,22 +44,23 @@ public class JmsToKafkaHeaderConverterTest { | |
@Test | ||
public void convertJmsPropertiesToKafkaHeaders() throws JMSException { | ||
|
||
final List<String> keys = Arrays.asList("facilityCountryCode", "facilityNum"); | ||
final List<String> keys = Arrays.asList("facilityCountryCode", "facilityNum","nullProperty"); | ||
|
||
final Enumeration<String> keyEnumeration = Collections.enumeration(keys); | ||
|
||
// Arrange | ||
when(message.getPropertyNames()).thenReturn(keyEnumeration); | ||
when(message.getObjectProperty("facilityCountryCode")).thenReturn("US"); | ||
when(message.getObjectProperty("facilityNum")).thenReturn("12345"); | ||
when(message.getObjectProperty("nullProperty")).thenReturn(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 commentThe reason will be displayed to describe this comment to others. Learn more. Nit comment: Both -> All three |
||
|
||
|
||
} | ||
|
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 ?
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.
My preference would be to use null, please - as otherwise on the Kafka side you wouldn't be able to differentiate between a property that was explicitly set to an empty string or a property that was actually null