Skip to content

Commit

Permalink
Fix Null pointer exception on passing empty search attribute (#2277)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quinn-With-Two-Ns authored Oct 17, 2024
1 parent eb64ec3 commit 25f5536
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ StartWorkflowExecutionRequest.Builder newStartWorkflowExecutionRequest(
"Cannot have search attributes and typed search attributes");
}
request.setSearchAttributes(SearchAttributesUtil.encode(options.getSearchAttributes()));
} else if (options.getTypedSearchAttributes() != null) {
} else if (options.getTypedSearchAttributes() != null
&& options.getTypedSearchAttributes().size() > 0) {
request.setSearchAttributes(
SearchAttributesUtil.encodeTyped(options.getTypedSearchAttributes()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,8 @@ private StartChildWorkflowExecutionParameters createChildWorkflowParameters(
"Cannot have both typed search attributes and search attributes");
}
attributes.setSearchAttributes(SearchAttributesUtil.encode(searchAttributes));
} else if (options.getTypedSearchAttributes() != null) {
} else if (options.getTypedSearchAttributes() != null
&& options.getTypedSearchAttributes().size() > 0) {
attributes.setSearchAttributes(
SearchAttributesUtil.encodeTyped(options.getTypedSearchAttributes()));
}
Expand Down Expand Up @@ -1261,7 +1262,8 @@ public void continueAsNew(ContinueAsNewInput input) {
"Cannot have typed search attributes and search attributes");
}
attributes.setSearchAttributes(SearchAttributesUtil.encode(searchAttributes));
} else if (options.getTypedSearchAttributes() != null) {
} else if (options.getTypedSearchAttributes() != null
&& options.getTypedSearchAttributes().size() > 0) {
attributes.setSearchAttributes(
SearchAttributesUtil.encodeTyped(options.getTypedSearchAttributes()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,32 @@ public void testInvalidSearchAttributeKey() {
}
}

@Test
public void testEmptyTypedSearchAttributeKey() {
WorkflowOptions options =
SDKTestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()).toBuilder()
.setTypedSearchAttributes(io.temporal.common.SearchAttributes.EMPTY)
.build();
TestSignaledWorkflow stubF =
testWorkflowRule.getWorkflowClient().newWorkflowStub(TestSignaledWorkflow.class, options);
WorkflowExecution executionF = WorkflowClient.start(stubF::execute);

GetWorkflowExecutionHistoryResponse historyResp =
WorkflowClientHelper.getHistoryPage(
testWorkflowRule.getWorkflowServiceStubs(),
SDKTestWorkflowRule.NAMESPACE,
executionF,
ByteString.EMPTY,
new NoopScope());
HistoryEvent startEvent = historyResp.getHistory().getEvents(0);
SearchAttributes searchAttrFromEvent =
startEvent.getWorkflowExecutionStartedEventAttributes().getSearchAttributes();

io.temporal.common.SearchAttributes decoded =
SearchAttributesUtil.decodeTyped(searchAttrFromEvent);
assertEquals(io.temporal.common.SearchAttributes.EMPTY, decoded);
}

@Test
public void testSearchAttributesPresentInChildWorkflow() {
NoArgsWorkflow client = testWorkflowRule.newWorkflowStubTimeoutOptions(NoArgsWorkflow.class);
Expand Down

0 comments on commit 25f5536

Please sign in to comment.