Skip to content

Commit 25f5536

Browse files
Fix Null pointer exception on passing empty search attribute (#2277)
1 parent eb64ec3 commit 25f5536

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

temporal-sdk/src/main/java/io/temporal/internal/client/WorkflowClientRequestFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ StartWorkflowExecutionRequest.Builder newStartWorkflowExecutionRequest(
132132
"Cannot have search attributes and typed search attributes");
133133
}
134134
request.setSearchAttributes(SearchAttributesUtil.encode(options.getSearchAttributes()));
135-
} else if (options.getTypedSearchAttributes() != null) {
135+
} else if (options.getTypedSearchAttributes() != null
136+
&& options.getTypedSearchAttributes().size() > 0) {
136137
request.setSearchAttributes(
137138
SearchAttributesUtil.encodeTyped(options.getTypedSearchAttributes()));
138139
}

temporal-sdk/src/main/java/io/temporal/internal/sync/SyncWorkflowContext.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,8 @@ private StartChildWorkflowExecutionParameters createChildWorkflowParameters(
865865
"Cannot have both typed search attributes and search attributes");
866866
}
867867
attributes.setSearchAttributes(SearchAttributesUtil.encode(searchAttributes));
868-
} else if (options.getTypedSearchAttributes() != null) {
868+
} else if (options.getTypedSearchAttributes() != null
869+
&& options.getTypedSearchAttributes().size() > 0) {
869870
attributes.setSearchAttributes(
870871
SearchAttributesUtil.encodeTyped(options.getTypedSearchAttributes()));
871872
}
@@ -1261,7 +1262,8 @@ public void continueAsNew(ContinueAsNewInput input) {
12611262
"Cannot have typed search attributes and search attributes");
12621263
}
12631264
attributes.setSearchAttributes(SearchAttributesUtil.encode(searchAttributes));
1264-
} else if (options.getTypedSearchAttributes() != null) {
1265+
} else if (options.getTypedSearchAttributes() != null
1266+
&& options.getTypedSearchAttributes().size() > 0) {
12651267
attributes.setSearchAttributes(
12661268
SearchAttributesUtil.encodeTyped(options.getTypedSearchAttributes()));
12671269
}

temporal-sdk/src/test/java/io/temporal/workflow/searchattributes/TypedSearchAttributesTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,32 @@ public void testInvalidSearchAttributeKey() {
190190
}
191191
}
192192

193+
@Test
194+
public void testEmptyTypedSearchAttributeKey() {
195+
WorkflowOptions options =
196+
SDKTestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()).toBuilder()
197+
.setTypedSearchAttributes(io.temporal.common.SearchAttributes.EMPTY)
198+
.build();
199+
TestSignaledWorkflow stubF =
200+
testWorkflowRule.getWorkflowClient().newWorkflowStub(TestSignaledWorkflow.class, options);
201+
WorkflowExecution executionF = WorkflowClient.start(stubF::execute);
202+
203+
GetWorkflowExecutionHistoryResponse historyResp =
204+
WorkflowClientHelper.getHistoryPage(
205+
testWorkflowRule.getWorkflowServiceStubs(),
206+
SDKTestWorkflowRule.NAMESPACE,
207+
executionF,
208+
ByteString.EMPTY,
209+
new NoopScope());
210+
HistoryEvent startEvent = historyResp.getHistory().getEvents(0);
211+
SearchAttributes searchAttrFromEvent =
212+
startEvent.getWorkflowExecutionStartedEventAttributes().getSearchAttributes();
213+
214+
io.temporal.common.SearchAttributes decoded =
215+
SearchAttributesUtil.decodeTyped(searchAttrFromEvent);
216+
assertEquals(io.temporal.common.SearchAttributes.EMPTY, decoded);
217+
}
218+
193219
@Test
194220
public void testSearchAttributesPresentInChildWorkflow() {
195221
NoArgsWorkflow client = testWorkflowRule.newWorkflowStubTimeoutOptions(NoArgsWorkflow.class);

0 commit comments

Comments
 (0)