Fix sonar issues in vid 28/85928/1
authorParshad Patel <pars.patel@samsung.com>
Mon, 22 Apr 2019 04:09:58 +0000 (13:09 +0900)
committerParshad Patel <pars.patel@samsung.com>
Mon, 22 Apr 2019 04:23:52 +0000 (13:23 +0900)
Fix A "NullPointerException" could be thrown issue
Fix Either log or rethrow this exception issue

Issue-ID: VID-464
Change-Id: I92fc200bf019fc335dde8a27b50e36cefffda440
Signed-off-by: Parshad Patel <pars.patel@samsung.com>
vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java
vid-app-common/src/main/java/org/onap/vid/aai/PombaClientImpl.java
vid-app-common/src/main/java/org/onap/vid/aai/PombaRestInterface.java
vid-app-common/src/main/java/org/onap/vid/services/CsvServiceImpl.java

index 6a8439f..1710d98 100644 (file)
@@ -195,6 +195,7 @@ public class AaiClient implements AaiClientInterface {
                 return new AaiResponse(e.getCause(), "AAI response parsing Error" , HttpStatus.SC_INTERNAL_SERVER_ERROR);
             }
             catch (Exception e) {
+                logger.error(EELFLoggerDelegate.errorLogger,"Exception in aai response parsing", e);
                 return new AaiResponse(e.getCause(), "Got " + aaiResponse.getHttpCode() + " from a&ai" , aaiResponse.getHttpCode());
             }
         }
@@ -335,8 +336,8 @@ public class AaiClient implements AaiClientInterface {
                 encodedParam= URLEncoder.encode(param, "UTF-8");
             } catch (UnsupportedEncodingException e) {
                 String methodName = "getUrlFromList";
-                logger.error(EELFLoggerDelegate.errorLogger, methodName + e.toString());
-                logger.debug(EELFLoggerDelegate.debugLogger, methodName + e.toString());
+                logger.error(EELFLoggerDelegate.errorLogger, methodName, e);
+                logger.debug(EELFLoggerDelegate.debugLogger, methodName, e);
             }
             url = url.concat(encodedParam);
             if(i != params.size()){
index 1ee4da0..5641bc5 100644 (file)
@@ -51,8 +51,8 @@ public class PombaClientImpl implements PombaClientInterface {
         try {
             pombaRestInterface.RestPost(fromAppId, uri, new ObjectMapper().writeValueAsString(request));
         } catch (Exception e) {
-            logger.info(EELFLoggerDelegate.errorLogger, methodName + e.toString());
-            logger.debug(EELFLoggerDelegate.debugLogger, methodName + e.toString());
+            logger.info(EELFLoggerDelegate.errorLogger, methodName, e);
+            logger.debug(EELFLoggerDelegate.debugLogger, methodName, e);
         }
     }
 }
index 129a610..b118901 100644 (file)
@@ -50,8 +50,8 @@ public class PombaRestInterface extends AAIRestInterface {
                 client = httpsAuthClientFactory.getClient(HttpClientMode.WITH_KEYSTORE);
             }
             catch (Exception e) {
-                logger.info(EELFLoggerDelegate.errorLogger, "Exception in REST call to DB in initRestClient" + e.toString());
-                logger.debug(EELFLoggerDelegate.debugLogger, "Exception in REST call to DB : " + e.toString());
+                logger.info(EELFLoggerDelegate.errorLogger, "Exception in REST call to DB in initRestClient", e);
+                logger.debug(EELFLoggerDelegate.debugLogger, "Exception in REST call to DB : ", e);
             }
         }
     }
index 4a5564e..4aabdae 100644 (file)
@@ -197,7 +197,9 @@ public class CsvServiceImpl implements CsvService{
                     currentJson.put(new JSONObject().put(key, values));
                 } else {
                 JSONObject lastItem = lastItemInArray(currentJson);
-                    lastItem.put(key, values);
+                    if(lastItem != null) {
+                        lastItem.put(key, values);
+                    }
                 }
             }
         }