Logged all caught exceptions 59/99159/3
authorDmitry Puzikov <d.puzikov2@partner.samsung.com>
Thu, 28 Nov 2019 13:33:24 +0000 (14:33 +0100)
committerOfir Sonsino <ofir.sonsino@intl.att.com>
Thu, 5 Dec 2019 12:26:30 +0000 (12:26 +0000)
Fix sonar issue related to logging
caught exceptions.

Change-Id: I61b2106165a81f3b2f0f9cc0da5911787504f50e
Issue-ID: SDC-2698
Signed-off-by: Dmitry Puzikov <d.puzikov2@partner.samsung.com>
common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationImpl.java

index 9a3fbd2..d13d5f7 100644 (file)
@@ -39,9 +39,13 @@ import org.onap.config.Constants;
 import org.onap.config.NonConfigResource;
 import org.onap.config.api.Config;
 import org.onap.config.api.Hint;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ConfigurationImpl implements org.onap.config.api.Configuration {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationImpl.class);
+
     private static final String KEY_CANNOT_BE_NULL = "Key can't be null.";
 
     private static final NonConfigResource NON_CONFIG_RESOURCE = new NonConfigResource();
@@ -51,7 +55,7 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration {
         try {
             init();
         } catch (ConfigurationException e) {
-            throw new IllegalStateException("Failed to initialize configuration");
+            throw new IllegalStateException("Failed to initialize configuration", e);
         }
     }
 
@@ -214,7 +218,14 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration {
                 }
             }
         } catch (Exception e) {
-            e.printStackTrace();
+            LOGGER.warn(
+                    "Couldn't populate map fot tenant: {}, namespace: {}, key: {}, type: {}",
+                    tenantId,
+                    namespace,
+                    key,
+                    clazz.getSimpleName(),
+                    e
+            );
         }
         return map;
     }
@@ -262,7 +273,13 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration {
                 map.put(k, value);
             }
         } catch (Exception e) {
-            e.printStackTrace();
+            LOGGER.warn(
+                    "Couldn't generate map fot tenant: {}, namespace: {}, key: {}",
+                    tenantId,
+                    namespace,
+                    key,
+                    e
+            );
         }
         return parentMap;
     }
@@ -336,7 +353,14 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration {
                                 + "class decorated with @org.openecomp.config.api.Config are allowed as argument.");
             }
         } catch (Exception exception) {
-            exception.printStackTrace();
+            LOGGER.warn(
+                    "Failed to get internal value fot tenant: {}, namespace: {}, key: {}, type: {}",
+                    tenant,
+                    namespace,
+                    key,
+                    clazz.getSimpleName(),
+                    exception
+            );
         }
         return null;
     }
@@ -422,6 +446,7 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration {
         try {
             return clazz.getDeclaredConstructor(classes);
         } catch (Exception exception) {
+            LOGGER.warn("Failed to get {} constructor.", clazz.getSimpleName(), exception);
             return null;
         }
     }
@@ -546,7 +571,7 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration {
                     collection.add(type1);
                 }
             } catch (RuntimeException re) {
-                // do nothing
+                LOGGER.warn("Failed to convert {}", commaSeparatedValues, re);
             }
         }
         return collection;