Prevent NullPointerException in config-util 43/2743/1
authorMaros Marsalek <mmarsale@cisco.com>
Thu, 14 Nov 2013 16:03:57 +0000 (17:03 +0100)
committerMaros Marsalek <mmarsale@cisco.com>
Thu, 14 Nov 2013 16:05:09 +0000 (17:05 +0100)
Change-Id: I269f6a23e8cd1ff3accbbe41165276152832a0df
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/jolokia/ListableJolokiaClient.java

index e998bebe27b00be5a9d14291595d9eb573315fde..6277f6a0e6fa6acd28d6aa52dc0fa7c87d7195f5 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.controller.config.util.jolokia;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -144,7 +145,13 @@ abstract class ListableJolokiaClient {
         J4pResponse<J4pListRequest> response = execute(req);
         JSONObject listJSONResponse = response.getValue();
         JSONObject attributes = (JSONObject) listJSONResponse.get("attr");
-        Map<String, JSONObject> listMap = new HashMap<String, JSONObject>();
+
+        // Empty attributes list
+        if(attributes == null)
+            return Collections.emptyMap();
+
+        Map<String, JSONObject> listMap = new HashMap<>();
+
         for (Object entryObject : attributes.entrySet()) {
             Entry<String, Object> entry = (Entry<String, Object>) entryObject;
             JSONObject entryVal = (JSONObject) entry.getValue();