From 15a08107d8554b32edd9b566fe70c6b65a2d6597 Mon Sep 17 00:00:00 2001 From: Hugo Trippaers Date: Mon, 13 Jan 2014 11:53:50 +0100 Subject: [PATCH] Fix coverity issue 600070 --- .../cloud/network/nicira/NiciraNvpApi.java | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/NiciraNvpApi.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/NiciraNvpApi.java index e58dcb9b4f7..92c23ebf5b9 100644 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/NiciraNvpApi.java +++ b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/NiciraNvpApi.java @@ -71,6 +71,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import com.google.gson.reflect.TypeToken; +@SuppressWarnings("rawtypes") public class NiciraNvpApi { protected static final String GET_METHOD_TYPE = "get"; protected static final String DELETE_METHOD_TYPE = "delete"; @@ -98,14 +99,27 @@ public class NiciraNvpApi { private final Gson gson; - @SuppressWarnings("rawtypes") protected static Map prefixMap; - @SuppressWarnings("rawtypes") protected static Map listTypeMap; protected static Map defaultListParams; + static { + prefixMap = new HashMap(); + prefixMap.put(SecurityProfile.class, SEC_PROFILE_URI_PREFIX); + prefixMap.put(Acl.class, ACL_URI_PREFIX); + + listTypeMap = new HashMap(); + listTypeMap.put(SecurityProfile.class, new TypeToken>() { + }.getType()); + listTypeMap.put(Acl.class, new TypeToken>() { + }.getType()); + + defaultListParams = new HashMap(); + defaultListParams.put("fields", "*"); + } + /* This factory method is protected so we can extend this * in the unittests. */ @@ -147,23 +161,6 @@ public class NiciraNvpApi { } gson = new GsonBuilder().registerTypeAdapter(NatRule.class, new NatRuleAdapter()).setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create(); - buildTypeSpecificStructures(); - } - - @SuppressWarnings("rawtypes") - protected void buildTypeSpecificStructures() { - if (prefixMap == null || listTypeMap == null || defaultListParams == null) { - prefixMap = new HashMap(); - prefixMap.put(SecurityProfile.class, SEC_PROFILE_URI_PREFIX); - prefixMap.put(Acl.class, ACL_URI_PREFIX); - - listTypeMap = new HashMap(); - listTypeMap.put(SecurityProfile.class, new TypeToken>() {}.getType()); - listTypeMap.put(Acl.class, new TypeToken>() {}.getType()); - - defaultListParams = new HashMap(); - defaultListParams.put("fields", "*"); - } } public void setControllerAddress(final String address) {