Fixed a NullPointerException case.

Could occur when a search request was performed just after peer startup,
and the Switchboard Thread "LibraryProvider.initialize" had completed,
thus requesting a ProbabilisticClassifier not completely initialized
(and having a null contexts property).
pull/97/head
luccioman 8 years ago
parent 6bc2bf1aa4
commit 3f561c1635

@ -105,7 +105,7 @@ public class ProbabilisticClassifier {
} }
private static Map<String, Context> contexts; private static Map<String, Context> contexts = new HashMap<>();
public static Set<String> getContextNames() { public static Set<String> getContextNames() {
return contexts.keySet(); return contexts.keySet();
@ -120,7 +120,7 @@ public class ProbabilisticClassifier {
* @param path_to_context_directory directory containing contexts wich are directories containing .txt files. One of them must be named 'negative.txt' * @param path_to_context_directory directory containing contexts wich are directories containing .txt files. One of them must be named 'negative.txt'
*/ */
public static void initialize(File path_to_context_directory) { public static void initialize(File path_to_context_directory) {
contexts = new HashMap<>(); contexts.clear();
String[] context_candidates = path_to_context_directory.list(); String[] context_candidates = path_to_context_directory.list();
for (String context_candidate: context_candidates) { for (String context_candidate: context_candidates) {
File ccf = new File(path_to_context_directory, context_candidate); File ccf = new File(path_to_context_directory, context_candidate);

Loading…
Cancel
Save