aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/common/src
diff options
context:
space:
mode:
authorMichael DÜrre <michael.duerre@highstreet-technologies.com>2021-08-24 06:16:11 +0200
committerMichael DÜrre <michael.duerre@highstreet-technologies.com>2021-08-24 06:17:47 +0200
commitc8f7e3f376992b202ba26464b9b329d6c4b2821d (patch)
treec61507b22b28ccc536485a8bf291826d0461b031 /sdnr/wt/common/src
parent2a55fbf61c4450bfc2bb3f90b060c3aa65af91f3 (diff)
fix some sdnr sonar bugs
sonar fixes for some sdnr components Issue-ID: SDNC-1590 Change-Id: I02e44b6f5477bcd0490c3499caf20228eb9772ed Signed-off-by: Michael DÜrre <michael.duerre@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/common/src')
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/ConfigurationFileRepresentation.java31
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/subtypes/Section.java3
2 files changed, 14 insertions, 20 deletions
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/ConfigurationFileRepresentation.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/ConfigurationFileRepresentation.java
index 54a5172a3..9ca985d4d 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/ConfigurationFileRepresentation.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/ConfigurationFileRepresentation.java
@@ -49,6 +49,8 @@ public class ConfigurationFileRepresentation implements IConfigChangedListener {
public static final String SECTIONNAME_ROOT = "";
private static final String LR = "\n";
private static final String EMPTY = "";
+
+ private static final String LOG_UNKNWON_CONFIG_SECTION = "Unknown configuration section {}";
// end of constants
// variables
@@ -70,8 +72,12 @@ public class ConfigurationFileRepresentation implements IConfigChangedListener {
if (!this.mFile.createNewFile()) {
LOG.error("Can not create file {}", f.getAbsolutePath());
}
- this.mFile.setReadable(true, false);
- this.mFile.setWritable(true, false);
+ if (!this.mFile.setReadable(true, false)) {
+ LOG.warn("unable to set file as readable");
+ }
+ if (!this.mFile.setWritable(true, false)) {
+ LOG.warn("unable to set file as writable");
+ }
}
reLoad();
@@ -106,9 +112,7 @@ public class ConfigurationFileRepresentation implements IConfigChangedListener {
String curSectionName = SECTIONNAME_ROOT;
Optional<Section> sectionOptional = this.getSection(curSectionName);
Section curSection = sectionOptional.isPresent() ? sectionOptional.get() : this.addSection(curSectionName);
- BufferedReader br = null;
- try {
- br = new BufferedReader(new FileReader(this.mFile));
+ try (BufferedReader br = new BufferedReader(new FileReader(this.mFile))) {
for (String line; (line = br.readLine()) != null;) {
line = line.trim();
if (line.isEmpty()) {
@@ -124,13 +128,6 @@ public class ConfigurationFileRepresentation implements IConfigChangedListener {
} catch (Exception e) {
LOG.info("Problem loading configuration file. {} {}", getMFileName(), e);
- } finally {
- try {
- if (br != null) {
- br.close();
- }
- } catch (IOException e) {
- }
}
LOG.debug("finished loading file");
LOG.debug("start parsing sections");
@@ -164,9 +161,8 @@ public class ConfigurationFileRepresentation implements IConfigChangedListener {
bw.write(String.join(LR, section.toLines()) + LR + LR);
}
}
- bw.close();
} catch (Exception e) {
- LOG.warn("problem saving value: " + e.getMessage());
+ LOG.warn("problem saving value: {}", e.getMessage());
}
}
@@ -194,7 +190,6 @@ public class ConfigurationFileRepresentation implements IConfigChangedListener {
if (this.fileObserver != null) {
this.fileObserver.interrupt();
}
- super.finalize();
}
/*
@@ -206,7 +201,7 @@ public class ConfigurationFileRepresentation implements IConfigChangedListener {
os.get().setProperty(key, value == null ? "null" : value.toString());
save();
} else {
- LOG.info("Unknown configuration section {}", section);
+ LOG.info(LOG_UNKNWON_CONFIG_SECTION, section);
}
}
@@ -215,7 +210,7 @@ public class ConfigurationFileRepresentation implements IConfigChangedListener {
if (os.isPresent()) {
return os.get().getProperty(propertyKey);
} else {
- LOG.debug("Unknown configuration section {}", section);
+ LOG.debug(LOG_UNKNWON_CONFIG_SECTION, section);
return EMPTY;
}
}
@@ -225,7 +220,7 @@ public class ConfigurationFileRepresentation implements IConfigChangedListener {
if (os.isPresent()) {
return os.get().getLong(propertyKey);
} else {
- LOG.debug("Unknown configuration section {}", section);
+ LOG.debug(LOG_UNKNWON_CONFIG_SECTION, section);
return Optional.empty();
}
}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/subtypes/Section.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/subtypes/Section.java
index c6b121ae3..55e329ebc 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/subtypes/Section.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/configuration/subtypes/Section.java
@@ -29,7 +29,6 @@ import java.util.Objects;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.eclipse.jdt.annotation.NonNull;
import org.onap.ccsdk.features.sdnr.wt.common.configuration.exception.ConversionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -266,7 +265,7 @@ public class Section {
}
// static methods
- public static void setEnvGetter(@NonNull EnvGetter newEnvGetter) {
+ public static void setEnvGetter(EnvGetter newEnvGetter) {
if (Objects.nonNull(newEnvGetter)) {
envGetter = newEnvGetter;
} else {