SpringBoot: fix potential null pointer

This commit is contained in:
djmil 2023-08-31 16:14:17 +02:00
parent 89fcf4e10f
commit c8d733dfac

View File

@ -13,6 +13,8 @@ import org.springframework.web.client.RestTemplate;
import djmil.cordacheckers.cordaclient.dao.VirtualNode; import djmil.cordacheckers.cordaclient.dao.VirtualNode;
import djmil.cordacheckers.cordaclient.dao.VirtualNodeList; import djmil.cordacheckers.cordaclient.dao.VirtualNodeList;
import static java.util.Objects.requireNonNull;
@Service @Service
public class CordaClient { public class CordaClient {
private final RestTemplate restTemplate; private final RestTemplate restTemplate;
@ -39,12 +41,12 @@ public class CordaClient {
request, request,
VirtualNodeList.class ); VirtualNodeList.class );
// TODO: throw exeption instead if (resp.getStatusCode() != HttpStatus.OK) {
if (resp.getStatusCode() != HttpStatus.OK || !resp.hasBody()) { throw new RuntimeException("CordaClient.getVirtualNodeList: unexpected request status "+resp.getStatusCode()) ;
return null;
} }
return resp.getBody().virtualNodes(); return requireNonNull(resp.getBody(), "CordaClient.getVirtualNodeList: empty getBody()")
.virtualNodes();
} }
// public String getGemeProposals(String ) { // public String getGemeProposals(String ) {