Skip to content

Commit

Permalink
Fix sonar reported NPE bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
forus committed Jun 20, 2024
1 parent eea7af7 commit 126c16a
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,20 @@ public ResponseEntity<VirtualStudy> publishVirtualStudy(
}
ResponseEntity<VirtualStudy> responseEntity = getVirtualStudyById(id);
HttpStatusCode statusCode = responseEntity.getStatusCode();
VirtualStudy virtualStudy = responseEntity.getBody();
if (!statusCode.is2xxSuccessful()) {
LOG.error("The downstream server replied with statusCode={} and body={}." +
" Replying with the same status code to the client.",
statusCode, responseEntity.getBody());
statusCode, virtualStudy);
return new ResponseEntity<>(null, statusCode);
}
if (responseEntity.getBody() == null) {
if (virtualStudy == null) {
LOG.error("The downstream server replied without body and statusCode={}." +
" Replying with internal server error status code to the client.",
statusCode);
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
return publishVirtualStudyData(responseEntity.getBody().getData(), providedPublisherApiKey, typeOfCancerId, pmid);
return publishVirtualStudyData(virtualStudy.getData(), providedPublisherApiKey, typeOfCancerId, pmid);
}

private ResponseEntity<VirtualStudy> getVirtualStudyById(String id) {
Expand All @@ -173,19 +174,19 @@ public ResponseEntity retractVirtualStudy(
}
ResponseEntity<VirtualStudy> responseEntity = getVirtualStudyById(id);
HttpStatusCode statusCode = responseEntity.getStatusCode();
VirtualStudy virtualStudy = responseEntity.getBody();
if (!statusCode.is2xxSuccessful()) {
LOG.error("The downstream server replied with statusCode={} and body={}." +
" Replying with the same status code to the client.",
statusCode, responseEntity.getBody());
statusCode, virtualStudy);
return new ResponseEntity<>(null, statusCode);
}
if (responseEntity.getBody() == null) {
if (virtualStudy == null) {
LOG.error("The downstream server replied without body and statusCode={}." +
" Replying with internal server error status code to the client.",
statusCode);
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
VirtualStudy virtualStudy = responseEntity.getBody();
VirtualStudyData data = virtualStudy.getData();
data.setUsers(Collections.emptySet());
new RestTemplate()
Expand Down

0 comments on commit 126c16a

Please sign in to comment.