From e9244cf34105c86a8fa7687eddb3860e1f9330a8 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Thu, 21 Sep 2017 16:03:37 +0530 Subject: [PATCH] cloudian: let's guard more apis wrt NPEs Signed-off-by: Rohit Yadav --- .../src/com/cloudian/cloudstack/CloudianClient.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/integrations/cloudian/src/com/cloudian/cloudstack/CloudianClient.java b/plugins/integrations/cloudian/src/com/cloudian/cloudstack/CloudianClient.java index 170f22a954f..58713633ec3 100644 --- a/plugins/integrations/cloudian/src/com/cloudian/cloudstack/CloudianClient.java +++ b/plugins/integrations/cloudian/src/com/cloudian/cloudstack/CloudianClient.java @@ -134,6 +134,9 @@ public class CloudianClient { try { final HttpResponse response = get(String.format("/user?userId=%s&groupId=%s", userId, groupId)); final ObjectMapper mapper = new ObjectMapper(); + if (response.getEntity() == null || response.getEntity().getContent() == null) { + return null; + } return mapper.readValue(response.getEntity().getContent(), UserInfo.class); } catch (final IOException e) { LOG.error("Failed to list Cloudian user due to:", e); @@ -204,6 +207,9 @@ public class CloudianClient { try { final HttpResponse response = get("/group/list"); final ObjectMapper mapper = new ObjectMapper(); + if (response.getEntity() == null || response.getEntity().getContent() == null) { + return null; + } return Arrays.asList(mapper.readValue(response.getEntity().getContent(), GroupInfo[].class)); } catch (final IOException e) { LOG.error("Failed to list Cloudian groups due to:", e);