Skip to content

Commit

Permalink
fix NPE by adding null check conditional (#3989)
Browse files Browse the repository at this point in the history
Fix NPE seen on Sentry by adding null check for result body
  • Loading branch information
sumitsum authored and nidhi-nair committed Apr 13, 2021
1 parent 8447c9c commit 4257353
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,11 @@ private ActionExecutionResult addDataTypes(ActionExecutionResult result) {
return result;
}

if (result.getBody() == null) {
result.setDataTypes(new ArrayList<>());
return result;
}

List<ParsedDataType> parsedDataTypeList = new ArrayList<>();
Stream.of(ActionResultDataType.values())
.parallel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1307,4 +1307,33 @@ public void testActionExecuteWithPreAssignedReturnType() {
executeAndAssertAction(executeActionDTO, actionConfiguration, mockResult,
List.of(new ParsedDataType(ActionResultDataType.RAW)));
}

@Test
@WithUserDetails(value = "api_user")
public void testActionExecuteReturnTypeWithNullResultBody() {
Mockito.when(pluginExecutorHelper.getPluginExecutor(Mockito.any())).thenReturn(Mono.just(pluginExecutor));

ActionExecutionResult mockResult = new ActionExecutionResult();
mockResult.setIsExecutionSuccess(true);
mockResult.setBody(null);
mockResult.setStatusCode("200");
mockResult.setHeaders(objectMapper.valueToTree(Map.of("response-header-key", "response-header-value")));

ActionDTO action = new ActionDTO();
ActionConfiguration actionConfiguration = new ActionConfiguration();
actionConfiguration.setHttpMethod(HttpMethod.POST);
actionConfiguration.setBody("random-request-body");
actionConfiguration.setHeaders(List.of(new Property("random-header-key", "random-header-value")));
action.setActionConfiguration(actionConfiguration);
action.setPageId(testPage.getId());
action.setName("testActionExecute");
action.setDatasource(datasource);
ActionDTO createdAction = newActionService.createAction(action).block();

ExecuteActionDTO executeActionDTO = new ExecuteActionDTO();
executeActionDTO.setActionId(createdAction.getId());
executeActionDTO.setViewMode(false);

executeAndAssertAction(executeActionDTO, actionConfiguration, mockResult, new ArrayList<>());
}
}

0 comments on commit 4257353

Please sign in to comment.