Fix various NPE and other potential errors
This commit is contained in:
parent
45738ddbb8
commit
0a88c2d55f
@ -58,6 +58,17 @@ public class SearchEngine<R extends SearchResult> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Set<String> suggestsKw;
|
||||||
|
try {
|
||||||
|
suggestsKw = result.getSuggestionKeywords();
|
||||||
|
Preconditions.checkNotNull(suggestsKw, "SearchResult instance must provide a non null set of suggestions keywords");
|
||||||
|
suggestsKw = new HashSet<>(suggestsKw);
|
||||||
|
suggestsKw.removeIf(e -> e == null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.severe(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
resultSet.add(result);
|
resultSet.add(result);
|
||||||
|
|
||||||
for (String skw : searchKw) {
|
for (String skw : searchKw) {
|
||||||
@ -66,17 +77,7 @@ public class SearchEngine<R extends SearchResult> {
|
|||||||
|
|
||||||
resultsSearchKeywordsMap.put(result, searchKw);
|
resultsSearchKeywordsMap.put(result, searchKw);
|
||||||
|
|
||||||
Set<String> suggestsKw;
|
resultsSuggestionsKeywordsMap.put(result, suggestsKw);
|
||||||
try {
|
|
||||||
suggestsKw = result.getSuggestionKeywords();
|
|
||||||
Preconditions.checkNotNull(suggestsKw, "SearchResult instance must provide a non null set of suggestions keywords");
|
|
||||||
suggestsKw.removeIf(e -> e == null);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.severe(e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
resultsSuggestionsKeywordsMap.put(result, new HashSet<>(suggestsKw));
|
|
||||||
|
|
||||||
for (String skw : suggestsKw) {
|
for (String skw : suggestsKw) {
|
||||||
suggestionsKeywordsResultMap.computeIfAbsent(skw, s -> new HashSet<>()).add(result);
|
suggestionsKeywordsResultMap.computeIfAbsent(skw, s -> new HashSet<>()).add(result);
|
||||||
@ -92,19 +93,27 @@ public class SearchEngine<R extends SearchResult> {
|
|||||||
resultSet.remove(result);
|
resultSet.remove(result);
|
||||||
|
|
||||||
Set<String> searchKw = resultsSearchKeywordsMap.remove(result);
|
Set<String> searchKw = resultsSearchKeywordsMap.remove(result);
|
||||||
for (String skw : searchKw) {
|
if (searchKw != null) {
|
||||||
Set<R> set = searchKeywordsResultMap.get(skw);
|
for (String skw : searchKw) {
|
||||||
set.remove(result);
|
Set<R> set = searchKeywordsResultMap.get(skw);
|
||||||
if (set.isEmpty())
|
if (set == null)
|
||||||
searchKeywordsResultMap.remove(skw);
|
continue;
|
||||||
|
set.remove(result);
|
||||||
|
if (set.isEmpty())
|
||||||
|
searchKeywordsResultMap.remove(skw);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<String> suggestsKw = resultsSearchKeywordsMap.remove(result);
|
Set<String> suggestsKw = resultsSearchKeywordsMap.remove(result);
|
||||||
for (String skw : suggestsKw) {
|
if (suggestsKw != null) {
|
||||||
Set<R> set = suggestionsKeywordsResultMap.get(skw);
|
for (String skw : suggestsKw) {
|
||||||
set.remove(result);
|
Set<R> set = suggestionsKeywordsResultMap.get(skw);
|
||||||
if (set.isEmpty())
|
if (set == null)
|
||||||
suggestionsKeywordsResultMap.remove(skw);
|
continue;
|
||||||
|
set.remove(result);
|
||||||
|
if (set.isEmpty())
|
||||||
|
suggestionsKeywordsResultMap.remove(skw);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resultsSuggestionsKeywordsMap.remove(result);
|
resultsSuggestionsKeywordsMap.remove(result);
|
||||||
|
Loading…
Reference in New Issue
Block a user