Fix Blocker/Critical sonar issues 83/13683/6
authorshashikanth <shashikanth.vh@huawei.com>
Wed, 20 Sep 2017 05:53:57 +0000 (11:23 +0530)
committerShashikanth VH <shashikanth.vh@huawei.com>
Thu, 21 Sep 2017 11:30:36 +0000 (11:30 +0000)
Fix Blocker/Critical sonar issues in aai/sparky-be module
https://sonar.onap.org/component_issues?id=org.openecomp.aai.sparky-be%3Asparky-be#resolved=false|severities=BLOCKER

Fixed Close "FileInputStream".

Issue-Id:AAI-342
Change-Id: Ia97fa8fee074660e081123e3fb6334d670d2fad1
Signed-off-by: shashikanth.vh <shashikanth.vh@huawei.com>
src/main/java/org/openecomp/sparky/config/oxm/OxmModelLoader.java

index 8a2cc6e..2a19551 100644 (file)
@@ -50,7 +50,6 @@ import org.openecomp.sparky.logging.AaiUiMsgs;
 import org.openecomp.sparky.synchronizer.entity.SuggestionSearchEntity;
 import org.openecomp.sparky.viewandinspect.config.TierSupportUiConstants;
 
-
 /**
  * The Class OxmModelLoader.
  */
@@ -133,27 +132,24 @@ public class OxmModelLoader {
    */
   public void loadModel(String version) {
     String fileName = loadOxmFileName(version);
-    InputStream inputStream;
-    try {
-      inputStream = new FileInputStream(new File(fileName));
-    } catch (FileNotFoundException fnf) {
-      LOG.info(AaiUiMsgs.OXM_READ_ERROR_NONVERBOSE);
-      LOG.error(AaiUiMsgs.OXM_READ_ERROR_VERBOSE, fileName);
-      return;
-    }
 
-    Map<String, Object> properties = new HashMap<String, Object>();
-    properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, inputStream);
-    try {
-      final DynamicJAXBContext oxmContext = DynamicJAXBContextFactory
-          .createContextFromOXM(Thread.currentThread().getContextClassLoader(), properties);
+    try(FileInputStream inputStream = new FileInputStream(new File(fileName))) {
+        Map<String, Object> properties = new HashMap<String, Object>();
+        properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, inputStream);
 
-      parseOxmContext(oxmContext);
-      // populateSearchableOxmModel();
-      LOG.info(AaiUiMsgs.OXM_LOAD_SUCCESS);
+        final DynamicJAXBContext oxmContext = DynamicJAXBContextFactory
+                                               .createContextFromOXM(Thread.currentThread()
+                                               .getContextClassLoader(), properties);
+        parseOxmContext(oxmContext);
+        // populateSearchableOxmModel();
+        LOG.info(AaiUiMsgs.OXM_LOAD_SUCCESS);
+
+    } catch (FileNotFoundException fnf) {
+        LOG.info(AaiUiMsgs.OXM_READ_ERROR_NONVERBOSE);
+        LOG.error(AaiUiMsgs.OXM_READ_ERROR_VERBOSE, fileName);
     } catch (Exception exc) {
-      LOG.info(AaiUiMsgs.OXM_PARSE_ERROR_NONVERBOSE);
-      LOG.error(AaiUiMsgs.OXM_PARSE_ERROR_VERBOSE, fileName, exc.getMessage());
+        LOG.info(AaiUiMsgs.OXM_PARSE_ERROR_NONVERBOSE);
+        LOG.error(AaiUiMsgs.OXM_PARSE_ERROR_VERBOSE, fileName, exc.getMessage());
     }
   }