Skip to content

Commit

Permalink
Issue #ditto/777: Fix a NullPointerException in ImmutableMessageSender.
Browse files Browse the repository at this point in the history
Signed-off-by: Yufei Cai <yufei.cai@bosch.io>
  • Loading branch information
yufei-cai committed Sep 4, 2020
1 parent c5b77ba commit 0e35280
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,11 @@ private static <T> void checkPayloadTypeAndAccept(final Class<T> clazz,
final BiConsumer<Message<T>, Throwable> responseMessageHandler,
final Message<?> message,
final Throwable error) {
if (message != null && message.getPayload().isPresent()) {
if (message != null && clazz.isAssignableFrom(ByteBuffer.class)) {
responseMessageHandler.accept(
withPayload(message, message.getRawPayload().map(clazz::cast).orElse(null)),
error);
} else if (message != null && message.getPayload().isPresent()) {
final Object payload = message.getPayload().get();
if (clazz.isInstance(payload)) {
responseMessageHandler.accept(withPayload(message, clazz.cast(payload)), error);
Expand All @@ -244,13 +248,7 @@ private static <T> void checkPayloadTypeAndAccept(final Class<T> clazz,
));
}
} else if (message != null) {
if (clazz.isAssignableFrom(ByteBuffer.class)) {
responseMessageHandler.accept(
withPayload(message, message.getRawPayload().map(clazz::cast).orElse(null)),
error);
} else {
responseMessageHandler.accept(null, new NoSuchElementException("No payload"));
}
responseMessageHandler.accept(null, new NoSuchElementException("No payload"));
} else {
responseMessageHandler.accept(null, error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,10 @@ private SendClaimMessage<String> claim() {
AbstractDittoClientTest.<String>newMessageBuilder(subject)
.payload(payload)
.build(),
DittoHeaders.newBuilder().randomCorrelationId().build());
DittoHeaders.newBuilder()
.randomCorrelationId()
.contentType("text/plain")
.build());
}

private SendClaimMessageResponse<String> claimResponse() {
Expand All @@ -539,7 +542,9 @@ private SendClaimMessageResponse<String> claimResponse() {
.payload(responsePayload)
.build(),
responseStatus,
DittoHeaders.empty());
DittoHeaders.newBuilder()
.contentType("text/plain")
.build());
}

private SendFeatureMessage<String> featureMessage() {
Expand Down

0 comments on commit 0e35280

Please sign in to comment.