Merge pull request #8731 from ShvaykaD/bugfix/PROD-2116

fixed NPE in Flow output node when it used after split array msg node
This commit is contained in:
Andrew Shvayka 2023-06-12 18:01:08 +03:00 committed by GitHub
commit e556afb511
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 3 deletions

View File

@ -64,7 +64,10 @@ public final class TbMsgProcessingCtx implements Serializable {
} }
public TbMsgProcessingStackItem pop() { public TbMsgProcessingStackItem pop() {
return !stack.isEmpty() ? stack.removeLast() : null; if (stack == null || stack.isEmpty()) {
return null;
}
return stack.removeLast();
} }
public static TbMsgProcessingCtx fromProto(MsgProtos.TbMsgProcessingCtxProto ctx) { public static TbMsgProcessingCtx fromProto(MsgProtos.TbMsgProcessingCtxProto ctx) {

View File

@ -77,8 +77,10 @@ public class TbSplitArrayMsgNode implements TbNode {
ctx.tellFailure(msg, e); ctx.tellFailure(msg, e);
} }
}); });
data.forEach(msgNode -> ctx.enqueueForTellNext(TbMsg.newMsg(msg.getQueueName(), msg.getType(), msg.getOriginator(), msg.getMetaData(), JacksonUtil.toString(msgNode)), data.forEach(msgNode -> {
TbRelationTypes.SUCCESS, wrapper::onSuccess, wrapper::onFailure)); TbMsg outMsg = TbMsg.transformMsg(msg, msg.getType(), msg.getOriginator(), msg.getMetaData(), JacksonUtil.toString(msgNode));
ctx.enqueueForTellNext(outMsg, TbRelationTypes.SUCCESS, wrapper::onSuccess, wrapper::onFailure);
});
} }
} else { } else {
ctx.tellFailure(msg, new RuntimeException("Msg data is not a JSON Array!")); ctx.tellFailure(msg, new RuntimeException("Msg data is not a JSON Array!"));

View File

@ -96,6 +96,7 @@ public class TbSplitArrayMsgNodeTest {
ArgumentCaptor<TbMsg> newMsgCaptor = ArgumentCaptor.forClass(TbMsg.class); ArgumentCaptor<TbMsg> newMsgCaptor = ArgumentCaptor.forClass(TbMsg.class);
ArgumentCaptor<Exception> exceptionCaptor = ArgumentCaptor.forClass(Exception.class); ArgumentCaptor<Exception> exceptionCaptor = ArgumentCaptor.forClass(Exception.class);
verify(ctx, never()).tellSuccess(any()); verify(ctx, never()).tellSuccess(any());
verify(ctx, never()).enqueueForTellNext(any(), anyString(), any(), any());
verify(ctx, times(1)).tellFailure(newMsgCaptor.capture(), exceptionCaptor.capture()); verify(ctx, times(1)).tellFailure(newMsgCaptor.capture(), exceptionCaptor.capture());
assertThat(exceptionCaptor.getValue()).isInstanceOf(RuntimeException.class); assertThat(exceptionCaptor.getValue()).isInstanceOf(RuntimeException.class);