From 1a1d919bbba5346ab8a1e459595f5062fcb35fe9 Mon Sep 17 00:00:00 2001 From: rama-huawei Date: Tue, 19 Sep 2017 18:26:52 +0530 Subject: [PATCH] Fix for Sonar Blocker issues NullPointerException might be thrown Replace the type specification on RHS side Iterate over the "entrySet" instead of the "keySet". The return type of this method should be an interface such as "Map" rather than the implementation "HashMap". DCAEGEN2-114 Change-Id: I84ef3e21cd426963f4f0ed726f5d8fa9979eb441 Signed-off-by: rama-huawei --- .../att/nsa/dmaap/filemonitor/ServicePropertiesMap.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/att/nsa/dmaap/filemonitor/ServicePropertiesMap.java b/src/main/java/com/att/nsa/dmaap/filemonitor/ServicePropertiesMap.java index 731428d..0f7744c 100644 --- a/src/main/java/com/att/nsa/dmaap/filemonitor/ServicePropertiesMap.java +++ b/src/main/java/com/att/nsa/dmaap/filemonitor/ServicePropertiesMap.java @@ -52,12 +52,15 @@ public class ServicePropertiesMap */ public static void refresh(File file) throws Exception { + String filePath= null; try { logger.info("Loading properties - " + (file != null?file.getName():"")); //Store .json & .properties files into map of maps - String filePath = file.getPath(); + if (file != null) { + filePath = file.getPath(); + } if(filePath.lastIndexOf(".json")>0){ @@ -65,9 +68,10 @@ public class ServicePropertiesMap TypeReference> typeRef = new TypeReference>() {}; HashMap propMap = om.readValue(file, typeRef); - HashMap lcasePropMap = new HashMap(); - for (String key : propMap.keySet() ) + HashMap lcasePropMap = new HashMap<>(); + for (Map.Entry entry : propMap.entrySet()) { + String key = entry.getKey(); String lcaseKey = ifNullThenEmpty(key); lcasePropMap.put(lcaseKey, propMap.get(key)); } @@ -81,7 +85,7 @@ public class ServicePropertiesMap prop.load(fis); @SuppressWarnings("unchecked") - HashMap propMap = new HashMap((Map)prop); + HashMap propMap = new HashMap<>((Map)prop); mapOfMaps.put(file.getName(), propMap); } @@ -111,7 +115,7 @@ public class ServicePropertiesMap * @param fileName fileName * @return mapProp */ - public static HashMap getProperties(String fileName){ + public static Map getProperties(String fileName){ return mapOfMaps.get(fileName); } -- 2.16.6