diff options
author | Seshu Kumar M <seshu.kumar.m@huawei.com> | 2018-03-21 08:16:08 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-03-21 08:16:08 +0000 |
commit | 4bea4da9e0ebd8068f565c6224d58dbd9a43f0fc (patch) | |
tree | 226c379f318370ab693f29f17f52f5253a350d89 | |
parent | 9b42af91f65875aacdde55e5c3418ed28bffc020 (diff) | |
parent | 2cf568610cef0d7cfa3ecbd9a516b2d41180fd9f (diff) |
Merge "Sonar Blocker"
-rw-r--r-- | common/src/main/java/org/openecomp/mso/logger/MsoLogger.java | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/common/src/main/java/org/openecomp/mso/logger/MsoLogger.java b/common/src/main/java/org/openecomp/mso/logger/MsoLogger.java index 6588995308..45f2746f0b 100644 --- a/common/src/main/java/org/openecomp/mso/logger/MsoLogger.java +++ b/common/src/main/java/org/openecomp/mso/logger/MsoLogger.java @@ -979,8 +979,7 @@ public class MsoLogger { File configFile = new File(CONFIG_FILE); String uuid = ""; BufferedReader in = null; - BufferedWriter bw = null; - try { + try{ // Verify whether instanceUUID file exist, // If yes, read the content; if not, generate the instanceUUID and // write to the file @@ -990,10 +989,11 @@ public class MsoLogger { if ((uuid = in.readLine()) == null) { // the file is empty, regenerate the file uuid = UUID.randomUUID().toString(); - FileWriter fw = new FileWriter(configFile.getAbsoluteFile()); - bw = new BufferedWriter(fw); + try(BufferedWriter bw = new BufferedWriter(new FileWriter(configFile.getAbsoluteFile()))) { bw.write(uuid); - bw.close(); + } catch (IOException e) { + LOGGER.log(Level.SEVERE, "Error trying to write UUID file", e); + } } in.close(); } else { @@ -1002,21 +1002,19 @@ public class MsoLogger { uuid = UUID.randomUUID().toString(); configFile.getParentFile().mkdirs(); configFile.createNewFile(); - FileWriter fw = new FileWriter(configFile.getAbsoluteFile()); - bw = new BufferedWriter(fw); - bw.write(uuid); - bw.close(); + try(BufferedWriter bw1 = new BufferedWriter(new FileWriter(configFile.getAbsoluteFile()))){ + bw1.write(uuid); + } catch (IOException e) { + LOGGER.log(Level.SEVERE, "Error trying to write UUID file", e); + } } } catch (IOException e) { - LOGGER.log(Level.SEVERE, "Error trying to read UUID file", e); + LOGGER.log(Level.SEVERE, "Error trying to read UUID file", e); } finally { try { if (in != null) { in.close(); } - if (bw != null) { - bw.close(); - } } catch (IOException ex) { LOGGER.log(Level.SEVERE, "Error trying to close UUID file", ex); } |