Skip to content

Commit 8a18fce

Browse files
params/Configuration: Protection against exceptions while loading the parameters.
1 parent 82485a0 commit 8a18fce

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

src/java/pt/lsts/neptus/params/ConfigurationManager.java

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.util.LinkedHashMap;
4040
import java.util.List;
4141
import java.util.Map;
42+
import java.util.Objects;
4243

4344
import org.apache.commons.lang3.BooleanUtils;
4445
import org.apache.commons.lang3.tuple.Pair;
@@ -124,25 +125,38 @@ public static ConfigurationManager getInstance() {
124125
private void loadConfigurations() {
125126
String lang = GeneralPreferences.language;
126127

127-
File fx = new File(ConfigFetch.getConfFolder() + CONF_DIR);
128+
String filePath = ConfigFetch.getConfFolder() + CONF_DIR;
129+
File fx = new File(filePath);
128130
if (fx.exists()) {
129-
for(File f : fx.listFiles(getFileFilterForConfigurationFiles())) {
130-
if (!f.isFile())
131-
continue;
132-
String fname = f.getName();
133-
String fext = FileUtil.getFileExtension(fname);
134-
if (!fname.replaceAll("." + fext + "$", "").endsWith(lang))
135-
continue;
131+
try {
132+
for (File f : Objects.requireNonNull(fx.listFiles(getFileFilterForConfigurationFiles()))) {
133+
try {
134+
if (!f.isFile()) {
135+
continue;
136+
}
137+
String fname = f.getName();
138+
String fext = FileUtil.getFileExtension(fname);
139+
if (!fname.replaceAll("." + fext + "$", "").endsWith(lang)) {
140+
continue;
141+
}
136142

137-
NeptusLog.pub().debug("Loading vehicle configuration from " + f.getName());
138-
String systemName = f.getName().split("\\.")[0];
139-
try {
140-
map.put(systemName, readConfiguration(f));
141-
}
142-
catch (InvalidConfigurationException e) {
143-
NeptusLog.pub().error(e.getMessage());
144-
e.printStackTrace();
145-
}
143+
NeptusLog.pub().debug("Loading vehicle configuration from " + f.getName());
144+
String systemName = f.getName().split("\\.")[0];
145+
try {
146+
map.put(systemName, readConfiguration(f));
147+
}
148+
catch (Exception e) {
149+
NeptusLog.pub().error(e.getMessage());
150+
e.printStackTrace();
151+
}
152+
}
153+
catch (Exception e) {
154+
NeptusLog.pub().error("Error processing systems parameters at '{}'", f);
155+
}
156+
}
157+
}
158+
catch (Exception e) {
159+
NeptusLog.pub().warn("No systems parameters found to process incide '{}'", filePath);
146160
}
147161
}
148162
}

0 commit comments

Comments
 (0)