Missing properties are no longer fatal
Change-Id: I199e25d0d26d44a74bdda8a8d24ce5e419a06c28
diff --git a/src/main/java/de/ids_mannheim/korap/KrillIndex.java b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
index 1ed2b33..6f8682c 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
@@ -65,8 +65,7 @@
* </pre></blockquote>
*
* <p>Properties can be stored in a properies file called
- * <tt>krill.properties</tt>. Relevant properties are
- * <tt>krill.version</tt> and <tt>krill.name</tt>.</p>
+ * <tt>krill.properties</tt>.
*
* @author diewald
*/
@@ -145,16 +144,21 @@
// Some initializations ...
{
- Properties prop = loadProperties();
- Properties version = loadInfo();
- this.version = version.getProperty("krill.version");
- this.name = version.getProperty("krill.name");
+ Properties prop = loadProperties();
+ Properties info = loadInfo();
+ if (info != null) {
+ this.version = info.getProperty("krill.version");
+ this.name = info.getProperty("krill.name");
+ };
// Check for auto commit value
- String stringProp = prop.getProperty("krill.index.commit.auto");
- if (stringProp != null) {
+ String autoCommitStr = null;
+ if (prop != null)
+ autoCommitStr = prop.getProperty("krill.index.commit.auto");
+
+ if (autoCommitStr != null) {
try {
- this.autoCommit = Integer.parseInt(stringProp);
+ this.autoCommit = Integer.parseInt(autoCommitStr);
}
catch (NumberFormatException e) {
log.error("krill.index.commit.auto expected to be a numerical value");
diff --git a/src/main/java/de/ids_mannheim/korap/util/KrillProperties.java b/src/main/java/de/ids_mannheim/korap/util/KrillProperties.java
index 6d1aec8..82ed821 100644
--- a/src/main/java/de/ids_mannheim/korap/util/KrillProperties.java
+++ b/src/main/java/de/ids_mannheim/korap/util/KrillProperties.java
@@ -9,7 +9,7 @@
// Todo: Properties may be loaded twice - althogh Java may cache automatically
public class KrillProperties {
- public static String file = "krill.properties";
+ public static String file = "krill.properties";
private static String info = "krill.info";
private static Properties prop;
@@ -44,7 +44,7 @@
.getResourceAsStream(propFile);
if (iFile == null) {
- log.error(
+ log.warn(
"Cannot find {}. Please create it using \"{}.info\" as template.",
propFile, propFile);
return null;
@@ -52,6 +52,7 @@
prop = new Properties();
prop.load(iFile);
+ iFile.close();
}
catch (IOException e) {
log.error(e.getLocalizedMessage());
@@ -67,8 +68,15 @@
try {
InputStream iFile = KrillProperties.class.getClassLoader()
.getResourceAsStream(info);
+
+ if (iFile == null) {
+ log.error("Cannot find {}.", info);
+ return null;
+ };
+
Properties prop = new Properties();
prop.load(iFile);
+ iFile.close();
}
catch (IOException e) {
log.error(e.getLocalizedMessage());