Skip to content

Commit c0a7fc5

Browse files
authored
fix(mapper): avoid null pointer exception in request mappers (#1030)
What changed? nullable check before setting the field in GRPC entities Why? GRPC entities have nullable checks
1 parent 1771f9b commit c0a7fc5

File tree

3 files changed

+43
-36
lines changed

3 files changed

+43
-36
lines changed

src/main/java/com/uber/cadence/internal/compatibility/proto/mappers/DecisionMapper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static Decision decision(com.uber.cadence.Decision d) {
157157
d.getRequestCancelExternalWorkflowExecutionDecisionAttributes();
158158
RequestCancelExternalWorkflowExecutionDecisionAttributes.Builder builder =
159159
RequestCancelExternalWorkflowExecutionDecisionAttributes.newBuilder()
160-
.setDomain(attr.getDomain())
160+
.setDomain(attr.getDomain() != null ? attr.getDomain() : "")
161161
.setWorkflowExecution(workflowRunPair(attr.getWorkflowId(), attr.getRunId()))
162162
.setChildWorkflowOnly(attr.isChildWorkflowOnly());
163163
if (attr.getControl() != null) {
@@ -202,7 +202,7 @@ static Decision decision(com.uber.cadence.Decision d) {
202202
d.getStartChildWorkflowExecutionDecisionAttributes();
203203
StartChildWorkflowExecutionDecisionAttributes.Builder builder =
204204
StartChildWorkflowExecutionDecisionAttributes.newBuilder()
205-
.setDomain(attr.getDomain())
205+
.setDomain(attr.getDomain() != null ? attr.getDomain() : "")
206206
.setWorkflowId(attr.getWorkflowId())
207207
.setWorkflowType(workflowType(attr.getWorkflowType()))
208208
.setTaskList(taskList(attr.getTaskList()))
@@ -234,7 +234,7 @@ static Decision decision(com.uber.cadence.Decision d) {
234234
d.getSignalExternalWorkflowExecutionDecisionAttributes();
235235
SignalExternalWorkflowExecutionDecisionAttributes.Builder builder =
236236
SignalExternalWorkflowExecutionDecisionAttributes.newBuilder()
237-
.setDomain(attr.getDomain())
237+
.setDomain(attr.getDomain() != null ? attr.getDomain() : "")
238238
.setWorkflowExecution(workflowExecution(attr.getExecution()))
239239
.setSignalName(attr.getSignalName())
240240
.setInput(payload(attr.getInput()))

src/main/java/com/uber/cadence/internal/compatibility/proto/mappers/RequestMapper.java

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ public static CountWorkflowExecutionsRequest countWorkflowExecutionsRequest(
121121
return null;
122122
}
123123
CountWorkflowExecutionsRequest.Builder request =
124-
CountWorkflowExecutionsRequest.newBuilder().setDomain(t.getDomain());
124+
CountWorkflowExecutionsRequest.newBuilder()
125+
.setDomain(t.getDomain() != null ? t.getDomain() : "");
125126
if (t.getQuery() != null) {
126127
request.setQuery(t.getQuery());
127128
}
@@ -134,7 +135,7 @@ public static DescribeTaskListRequest describeTaskListRequest(
134135
return null;
135136
}
136137
return DescribeTaskListRequest.newBuilder()
137-
.setDomain(t.getDomain())
138+
.setDomain(t.getDomain() != null ? t.getDomain() : "")
138139
.setTaskList(taskList(t.getTaskList()))
139140
.setTaskListType(taskListType(t.getTaskListType()))
140141
.setIncludeTaskListStatus(t.isIncludeTaskListStatus())
@@ -148,7 +149,7 @@ public static ListArchivedWorkflowExecutionsRequest listArchivedWorkflowExecutio
148149
}
149150
ListArchivedWorkflowExecutionsRequest.Builder request =
150151
ListArchivedWorkflowExecutionsRequest.newBuilder()
151-
.setDomain(t.getDomain())
152+
.setDomain(t.getDomain() != null ? t.getDomain() : "")
152153
.setPageSize(t.getPageSize());
153154
if (t.getNextPageToken() != null) {
154155
request.setNextPageToken(arrayToByteString(t.getNextPageToken()));
@@ -166,7 +167,7 @@ public static RequestCancelWorkflowExecutionRequest requestCancelWorkflowExecuti
166167
}
167168
RequestCancelWorkflowExecutionRequest.Builder builder =
168169
RequestCancelWorkflowExecutionRequest.newBuilder()
169-
.setDomain(t.getDomain())
170+
.setDomain(t.getDomain() != null ? t.getDomain() : "")
170171
.setWorkflowExecution(workflowExecution(t.getWorkflowExecution()))
171172
.setRequestId(t.getRequestId());
172173
if (t.getIdentity() != null) {
@@ -187,7 +188,7 @@ public static ResetStickyTaskListRequest resetStickyTaskListRequest(
187188
return null;
188189
}
189190
return ResetStickyTaskListRequest.newBuilder()
190-
.setDomain(t.getDomain())
191+
.setDomain(t.getDomain() != null ? t.getDomain() : "")
191192
.setWorkflowExecution(workflowExecution(t.getExecution()))
192193
.build();
193194
}
@@ -198,7 +199,7 @@ public static ResetWorkflowExecutionRequest resetWorkflowExecutionRequest(
198199
return null;
199200
}
200201
return ResetWorkflowExecutionRequest.newBuilder()
201-
.setDomain(t.getDomain())
202+
.setDomain(t.getDomain() != null ? t.getDomain() : "")
202203
.setWorkflowExecution(workflowExecution(t.getWorkflowExecution()))
203204
.setReason(t.getReason() != null ? t.getReason() : "")
204205
.setDecisionFinishEventId(t.getDecisionFinishEventId())
@@ -214,7 +215,7 @@ public static RespondActivityTaskCanceledByIDRequest respondActivityTaskCanceled
214215
}
215216
RespondActivityTaskCanceledByIDRequest.Builder builder =
216217
RespondActivityTaskCanceledByIDRequest.newBuilder()
217-
.setDomain(t.getDomain())
218+
.setDomain(t.getDomain() != null ? t.getDomain() : "")
218219
.setWorkflowExecution(TypeMapper.workflowRunPair(t.getWorkflowID(), t.getRunID()))
219220
.setActivityId(t.getActivityID())
220221
.setDetails(payload(t.getDetails()));
@@ -247,7 +248,7 @@ public static RespondActivityTaskCompletedByIDRequest respondActivityTaskComplet
247248
}
248249
RespondActivityTaskCompletedByIDRequest.Builder builder =
249250
RespondActivityTaskCompletedByIDRequest.newBuilder()
250-
.setDomain(t.getDomain())
251+
.setDomain(t.getDomain() != null ? t.getDomain() : "")
251252
.setWorkflowExecution(TypeMapper.workflowRunPair(t.getWorkflowID(), t.getRunID()))
252253
.setActivityId(t.getActivityID())
253254
.setResult(payload(t.getResult()));
@@ -280,7 +281,7 @@ public static RespondActivityTaskFailedByIDRequest respondActivityTaskFailedById
280281
}
281282
RespondActivityTaskFailedByIDRequest.Builder builder =
282283
RespondActivityTaskFailedByIDRequest.newBuilder()
283-
.setDomain(t.getDomain())
284+
.setDomain(t.getDomain() != null ? t.getDomain() : "")
284285
.setWorkflowExecution(TypeMapper.workflowRunPair(t.getWorkflowID(), t.getRunID()))
285286
.setActivityId(t.getActivityID())
286287
.setFailure(failure(t.getReason(), t.getDetails()));
@@ -384,7 +385,7 @@ public static ScanWorkflowExecutionsRequest scanWorkflowExecutionsRequest(
384385
}
385386
ScanWorkflowExecutionsRequest.Builder request =
386387
ScanWorkflowExecutionsRequest.newBuilder()
387-
.setDomain(t.getDomain())
388+
.setDomain(t.getDomain() != null ? t.getDomain() : "")
388389
.setPageSize(t.getPageSize());
389390
if (t.getNextPageToken() != null) {
390391
request.setNextPageToken(arrayToByteString(t.getNextPageToken()));
@@ -401,7 +402,7 @@ public static DescribeWorkflowExecutionRequest describeWorkflowExecutionRequest(
401402
return null;
402403
}
403404
return DescribeWorkflowExecutionRequest.newBuilder()
404-
.setDomain(t.getDomain())
405+
.setDomain(t.getDomain() != null ? t.getDomain() : "")
405406
.setWorkflowExecution(workflowExecution(t.getExecution()))
406407
.setQueryConsistencyLevel(queryConsistencyLevel(t.getQueryConsistencyLevel()))
407408
.build();
@@ -414,7 +415,7 @@ public static GetWorkflowExecutionHistoryRequest getWorkflowExecutionHistoryRequ
414415
}
415416
GetWorkflowExecutionHistoryRequest.Builder builder =
416417
GetWorkflowExecutionHistoryRequest.newBuilder()
417-
.setDomain(t.getDomain())
418+
.setDomain(t.getDomain() != null ? t.getDomain() : "")
418419
.setWorkflowExecution(workflowExecution(t.getExecution()))
419420
.setPageSize(t.getMaximumPageSize())
420421
.setWaitForNewEvent(t.isWaitForNewEvent())
@@ -434,7 +435,7 @@ public static SignalWithStartWorkflowExecutionRequest signalWithStartWorkflowExe
434435
}
435436
StartWorkflowExecutionRequest.Builder builder =
436437
StartWorkflowExecutionRequest.newBuilder()
437-
.setDomain(t.getDomain())
438+
.setDomain(t.getDomain() != null ? t.getDomain() : "")
438439
.setWorkflowId(t.getWorkflowId())
439440
.setWorkflowType(workflowType(t.getWorkflowType()))
440441
.setTaskList(taskList(t.getTaskList()))
@@ -497,7 +498,7 @@ public static SignalWorkflowExecutionRequest signalWorkflowExecutionRequest(
497498
}
498499
SignalWorkflowExecutionRequest.Builder builder =
499500
SignalWorkflowExecutionRequest.newBuilder()
500-
.setDomain(t.getDomain())
501+
.setDomain(t.getDomain() != null ? t.getDomain() : "")
501502
.setWorkflowExecution(workflowExecution(t.getWorkflowExecution()))
502503
.setSignalName(t.getSignalName())
503504
.setSignalInput(payload(t.getInput()))
@@ -518,7 +519,7 @@ public static StartWorkflowExecutionRequest startWorkflowExecutionRequest(
518519
}
519520
StartWorkflowExecutionRequest.Builder request =
520521
StartWorkflowExecutionRequest.newBuilder()
521-
.setDomain(t.getDomain())
522+
.setDomain(t.getDomain() != null ? t.getDomain() : "")
522523
.setWorkflowId(t.getWorkflowId())
523524
.setWorkflowType(workflowType(t.getWorkflowType()))
524525
.setTaskList(taskList(t.getTaskList()))
@@ -566,7 +567,7 @@ public static TerminateWorkflowExecutionRequest terminateWorkflowExecutionReques
566567
}
567568
TerminateWorkflowExecutionRequest.Builder builder =
568569
TerminateWorkflowExecutionRequest.newBuilder()
569-
.setDomain(t.getDomain())
570+
.setDomain(t.getDomain() != null ? t.getDomain() : "")
570571
.setWorkflowExecution(workflowExecution(t.getWorkflowExecution()))
571572
.setReason(t.getReason() != null ? t.getReason() : "")
572573
.setDetails(payload(t.getDetails()));
@@ -622,7 +623,7 @@ public static ListTaskListPartitionsRequest listTaskListPartitionsRequest(
622623
return null;
623624
}
624625
return ListTaskListPartitionsRequest.newBuilder()
625-
.setDomain(t.getDomain())
626+
.setDomain(t.getDomain() != null ? t.getDomain() : "")
626627
.setTaskList(taskList(t.getTaskList()))
627628
.build();
628629
}
@@ -634,7 +635,7 @@ public static ListWorkflowExecutionsRequest listWorkflowExecutionsRequest(
634635
}
635636
ListWorkflowExecutionsRequest.Builder request =
636637
ListWorkflowExecutionsRequest.newBuilder()
637-
.setDomain(t.getDomain())
638+
.setDomain(t.getDomain() != null ? t.getDomain() : "")
638639
.setPageSize(t.getPageSize());
639640
if (t.getNextPageToken() != null) {
640641
request.setNextPageToken(arrayToByteString(t.getNextPageToken()));
@@ -652,7 +653,7 @@ public static PollForActivityTaskRequest pollForActivityTaskRequest(
652653
}
653654
PollForActivityTaskRequest.Builder builder =
654655
PollForActivityTaskRequest.newBuilder()
655-
.setDomain(t.getDomain())
656+
.setDomain(t.getDomain() != null ? t.getDomain() : "")
656657
.setTaskList(taskList(t.getTaskList()))
657658
.setTaskListMetadata(taskListMetadata(t.getTaskListMetadata()));
658659
if (t.getIdentity() != null) {
@@ -668,7 +669,7 @@ public static PollForDecisionTaskRequest pollForDecisionTaskRequest(
668669
}
669670
PollForDecisionTaskRequest.Builder builder =
670671
PollForDecisionTaskRequest.newBuilder()
671-
.setDomain(t.getDomain())
672+
.setDomain(t.getDomain() != null ? t.getDomain() : "")
672673
.setTaskList(taskList(t.getTaskList()));
673674
if (t.getBinaryChecksum() != null) {
674675
builder.setBinaryChecksum(t.getBinaryChecksum());
@@ -684,7 +685,7 @@ public static QueryWorkflowRequest queryWorkflowRequest(com.uber.cadence.QueryWo
684685
return null;
685686
}
686687
return QueryWorkflowRequest.newBuilder()
687-
.setDomain(t.getDomain())
688+
.setDomain(t.getDomain() != null ? t.getDomain() : "")
688689
.setWorkflowExecution(workflowExecution(t.getExecution()))
689690
.setQuery(workflowQuery(t.getQuery()))
690691
.setQueryRejectCondition(queryRejectCondition(t.getQueryRejectCondition()))
@@ -699,7 +700,7 @@ public static RecordActivityTaskHeartbeatByIDRequest recordActivityTaskHeartbeat
699700
}
700701
RecordActivityTaskHeartbeatByIDRequest.Builder builder =
701702
RecordActivityTaskHeartbeatByIDRequest.newBuilder()
702-
.setDomain(t.getDomain())
703+
.setDomain(t.getDomain() != null ? t.getDomain() : "")
703704
.setWorkflowExecution(TypeMapper.workflowRunPair(t.getWorkflowID(), t.getRunID()))
704705
.setActivityId(t.getActivityID())
705706
.setDetails(payload(t.getDetails()));
@@ -756,7 +757,7 @@ public static RestartWorkflowExecutionRequest restartWorkflowExecutionRequest(
756757
return null;
757758
}
758759
return RestartWorkflowExecutionRequest.newBuilder()
759-
.setDomain(t.getDomain())
760+
.setDomain(t.getDomain() != null ? t.getDomain() : "")
760761
.setWorkflowExecution(workflowExecution(t.getWorkflowExecution()))
761762
.setReason(t.getReason() != null ? t.getReason() : "")
762763
.setIdentity(t.getIdentity() != null ? t.getIdentity() : "")
@@ -852,7 +853,7 @@ public static ListClosedWorkflowExecutionsRequest listClosedWorkflowExecutionsRe
852853
}
853854
ListClosedWorkflowExecutionsRequest.Builder request =
854855
ListClosedWorkflowExecutionsRequest.newBuilder()
855-
.setDomain(t.getDomain())
856+
.setDomain(t.getDomain() != null ? t.getDomain() : "")
856857
.setPageSize(t.getMaximumPageSize());
857858
if (t.getExecutionFilter() != null) {
858859
request.setExecutionFilter(workflowExecutionFilter(t.getExecutionFilter()));
@@ -879,7 +880,7 @@ public static ListOpenWorkflowExecutionsRequest listOpenWorkflowExecutionsReques
879880
}
880881
ListOpenWorkflowExecutionsRequest.Builder request =
881882
ListOpenWorkflowExecutionsRequest.newBuilder()
882-
.setDomain(t.getDomain())
883+
.setDomain(t.getDomain() != null ? t.getDomain() : "")
883884
.setPageSize(t.getMaximumPageSize());
884885
if (t.getExecutionFilter() != null) {
885886
request.setExecutionFilter(workflowExecutionFilter(t.getExecutionFilter()));
@@ -903,7 +904,7 @@ public static RespondActivityTaskFailedByIDRequest respondActivityTaskFailedByID
903904
}
904905
RespondActivityTaskFailedByIDRequest.Builder request =
905906
RespondActivityTaskFailedByIDRequest.newBuilder()
906-
.setDomain(failRequest.getDomain())
907+
.setDomain(failRequest.getDomain() != null ? failRequest.getDomain() : "")
907908
.setWorkflowExecution(
908909
TypeMapper.workflowRunPair(failRequest.getWorkflowID(), failRequest.getRunID()))
909910
.setActivityId(failRequest.getActivityID())
@@ -919,7 +920,7 @@ public static RespondActivityTaskCompletedByIDRequest respondActivityTaskComplet
919920
}
920921
RespondActivityTaskCompletedByIDRequest.Builder request =
921922
RespondActivityTaskCompletedByIDRequest.newBuilder()
922-
.setDomain(completeRequest.getDomain())
923+
.setDomain(completeRequest.getDomain() != null ? completeRequest.getDomain() : "")
923924
.setWorkflowExecution(
924925
TypeMapper.workflowRunPair(
925926
completeRequest.getWorkflowID(), completeRequest.getRunID()))
@@ -937,7 +938,7 @@ public static RecordActivityTaskHeartbeatByIDRequest recordActivityTaskHeartbeat
937938
}
938939
RecordActivityTaskHeartbeatByIDRequest.Builder request =
939940
RecordActivityTaskHeartbeatByIDRequest.newBuilder()
940-
.setDomain(heartbeatRequest.getDomain())
941+
.setDomain(heartbeatRequest.getDomain() != null ? heartbeatRequest.getDomain() : "")
941942
.setWorkflowExecution(
942943
TypeMapper.workflowRunPair(
943944
heartbeatRequest.getWorkflowID(), heartbeatRequest.getRunID()))
@@ -955,7 +956,7 @@ public static RespondActivityTaskCanceledByIDRequest respondActivityTaskCanceled
955956
}
956957
RespondActivityTaskCanceledByIDRequest.Builder request =
957958
RespondActivityTaskCanceledByIDRequest.newBuilder()
958-
.setDomain(canceledRequest.getDomain())
959+
.setDomain(canceledRequest.getDomain() != null ? canceledRequest.getDomain() : "")
959960
.setWorkflowExecution(
960961
TypeMapper.workflowRunPair(
961962
canceledRequest.getWorkflowID(), canceledRequest.getRunID()))
@@ -972,7 +973,8 @@ public static GetTaskListsByDomainRequest getTaskListsByDomainRequest(
972973
return null;
973974
}
974975
GetTaskListsByDomainRequest.Builder request =
975-
GetTaskListsByDomainRequest.newBuilder().setDomain(domainRequest.getDomainName());
976+
GetTaskListsByDomainRequest.newBuilder()
977+
.setDomain(domainRequest.getDomainName() != null ? domainRequest.getDomainName() : "");
976978
return request.build();
977979
}
978980

@@ -981,6 +983,8 @@ public static RefreshWorkflowTasksRequest refreshWorkflowTasksRequest(
981983
if (request == null) {
982984
return null;
983985
}
984-
return RefreshWorkflowTasksRequest.newBuilder().setDomain(request.getDomain()).build();
986+
return RefreshWorkflowTasksRequest.newBuilder()
987+
.setDomain(request.getDomain() != null ? request.getDomain() : "")
988+
.build();
985989
}
986990
}

src/main/java/com/uber/cadence/internal/compatibility/proto/mappers/TypeMapper.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ static WorkflowExecution workflowRunPair(String workflowId, String runId) {
128128
if (Strings.isNullOrEmpty(workflowId) && Strings.isNullOrEmpty(runId)) {
129129
return WorkflowExecution.newBuilder().build();
130130
}
131-
return WorkflowExecution.newBuilder().setWorkflowId(workflowId).setRunId(runId).build();
131+
return WorkflowExecution.newBuilder()
132+
.setWorkflowId(workflowId)
133+
.setRunId(runId != null ? runId : "")
134+
.build();
132135
}
133136

134137
static ActivityType activityType(com.uber.cadence.ActivityType t) {
@@ -275,7 +278,7 @@ static WorkflowExecutionFilter workflowExecutionFilter(
275278
}
276279
return WorkflowExecutionFilter.newBuilder()
277280
.setWorkflowId(t.getWorkflowId())
278-
.setRunId(t.getRunId())
281+
.setRunId(t.getRunId() != null ? t.getRunId() : "")
279282
.build();
280283
}
281284

0 commit comments

Comments
 (0)