OPENNLP-464 Model loading error is now reported to the user.
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/MultiModelNameFinder.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/MultiModelNameFinder.java
index 5aae42a..dec49d1 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/MultiModelNameFinder.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/MultiModelNameFinder.java
@@ -111,9 +111,13 @@
TokenNameFinderModel model = new TokenNameFinderModel(modelIn);
sequenceValidators[i] = new RestrictedSequencesValidator(modelTypes[i]);
nameFinders[i] = new NameFinderME(model, null, 5, sequenceValidators[i]);
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
+ }
+ catch (IOException e) {
+ // Error message should include model type
+ throw new IOException("Failed to load a model, path:\n" + modelPathes[i] +
+ "\nError Message:\n" + e.getMessage());
+ }
+ finally {
if (modelIn != null) {
try {
modelIn.close();
diff --git a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderJob.java b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderJob.java
index 21dc4f6..5bd20d8 100644
--- a/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderJob.java
+++ b/caseditor-opennlp-plugin/src/main/java/org/apache/opennlp/caseditor/namefinder/NameFinderJob.java
@@ -114,13 +114,12 @@
try {
nameFinder = new MultiModelNameFinder(modelPath, modelTypes);
} catch (IOException e) {
- return new Status(IStatus.CANCEL, OpenNLPPlugin.ID,
- "Failed to load model(s):\n" + e.getMessage());
+ return new Status(IStatus.CANCEL, OpenNLPPlugin.ID, e.getMessage());
}
}
if (nameFinder != null) {
- nameFinder.clearAdaptiveData();
+ nameFinder.clearAdaptiveData(); // TODO: If model loading fails we get a NPE here!
nameList = new ArrayList<PotentialAnnotation>();