From c8d733dfac56b3f409671bda716d4b39cf3f5457 Mon Sep 17 00:00:00 2001 From: djmil Date: Thu, 31 Aug 2023 16:14:17 +0200 Subject: [PATCH] SpringBoot: fix potential null pointer --- .../djmil/cordacheckers/cordaclient/CordaClient.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/djmil/cordacheckers/cordaclient/CordaClient.java b/backend/src/main/java/djmil/cordacheckers/cordaclient/CordaClient.java index 2553ae7..7e0f047 100644 --- a/backend/src/main/java/djmil/cordacheckers/cordaclient/CordaClient.java +++ b/backend/src/main/java/djmil/cordacheckers/cordaclient/CordaClient.java @@ -13,6 +13,8 @@ import org.springframework.web.client.RestTemplate; import djmil.cordacheckers.cordaclient.dao.VirtualNode; import djmil.cordacheckers.cordaclient.dao.VirtualNodeList; +import static java.util.Objects.requireNonNull; + @Service public class CordaClient { private final RestTemplate restTemplate; @@ -39,12 +41,12 @@ public class CordaClient { request, VirtualNodeList.class ); - // TODO: throw exeption instead - if (resp.getStatusCode() != HttpStatus.OK || !resp.hasBody()) { - return null; + if (resp.getStatusCode() != HttpStatus.OK) { + throw new RuntimeException("CordaClient.getVirtualNodeList: unexpected request status "+resp.getStatusCode()) ; } - return resp.getBody().virtualNodes(); + return requireNonNull(resp.getBody(), "CordaClient.getVirtualNodeList: empty getBody()") + .virtualNodes(); } // public String getGemeProposals(String ) {