Skip to content

Commit

Permalink
Merge pull request #2100 from beyonnex-io/bugfix/npe-in-scripted-mapping
Browse files Browse the repository at this point in the history
fix NPE in ScriptedOutgoingMapping when value from script resolved to null
  • Loading branch information
thjaeckle authored Jan 21, 2025
2 parents 70c3bad + 1fb100a commit 4966ef4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,20 @@ private static JsonObject toJsonObject(final NativeObject nativeObject) {
objectBuilder.set(key.toString(), JsonFactory.newValue(intValue));
} else if (value instanceof Double doubleValue) {
objectBuilder.set(key.toString(), JsonFactory.newValue(doubleValue));
} else if (value == null || value instanceof Undefined) {
objectBuilder.set(key.toString(), JsonFactory.nullLiteral());
} else {
if (log.isDebugEnabled()){
log.debug("Unsupported type: {}, adding as string: {}", value.getClass().getName(), value);
}
objectBuilder.set(key.toString(), value.toString());
}
} catch (final JsonParseException e) {
objectBuilder.set(key.toString(), value.toString());
if (value != null) {
objectBuilder.set(key.toString(), value.toString());
} else {
objectBuilder.set(key.toString(), JsonFactory.nullLiteral());
}
}
});
return objectBuilder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ private SendingOrDropped publishToGenericTarget(final ExpressionResolver resolve
DittoHeaders.newBuilder(mappedMessage.getHeaders())
.removeHeader(DittoHeaderDefinition.W3C_TRACEPARENT.getKey())
.build()
.asCaseSensitiveMap()
));

final CompletionStage<SendResult> responsesFuture = publishMessage(outboundSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ private void handleJmsMessage(final JmsMessage message) throws JMSException {
.toBuilder()
.removeHeader(DittoHeaderDefinition.W3C_TRACEPARENT.getKey())
.build()
.asCaseSensitiveMap()
);
final ExternalMessageBuilder builder = ExternalMessageFactory.newExternalMessageBuilder(headers);
final ExternalMessage externalMessage = extractPayloadFromMessage(message, builder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public TransformationResult transform(final ConsumerRecord<String, ByteBuffer> c
.toBuilder()
.removeHeader(DittoHeaderDefinition.W3C_TRACEPARENT.getKey())
.build()
.asCaseSensitiveMap()
);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ private void handleDelivery(final Delivery delivery) {
.toBuilder()
.removeHeader(DittoHeaderDefinition.W3C_TRACEPARENT.getKey())
.build()
.asCaseSensitiveMap()
);

final ExternalMessageBuilder externalMessageBuilder =
Expand Down

0 comments on commit 4966ef4

Please sign in to comment.