summaryrefslogtreecommitdiffstats
path: root/common/src
diff options
context:
space:
mode:
authorSP00501638 <SP00501638@techmahindra.com>2018-03-21 12:17:15 +0530
committerSP00501638 <SP00501638@techmahindra.com>2018-03-21 12:17:42 +0530
commit2cf568610cef0d7cfa3ecbd9a516b2d41180fd9f (patch)
tree39450092cc0097a72ab8752c47f655068456a07c /common/src
parent4f4b3d7e48027fc7b9a973f4229eed2ee1b023f5 (diff)
Sonar Blocker
Use try-with-resources or close in a finally clause MsoLogger.java:993,994,1005 Sonar Link: https://sonar.onap.org/issues?assignees=swapnalipode&resolved=false Location: common/src/main/java/org/openecomp/mso/logger/MsoLogger.java Change-Id: I9a1e5b39f2c25ace3febc65fca1104358acaa7b7 Issue-ID: SO-508 Signed-off-by: SP00501638 <SP00501638@techmahindra.com>
Diffstat (limited to 'common/src')
-rw-r--r--common/src/main/java/org/openecomp/mso/logger/MsoLogger.java24
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);
}