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,20 +93,28 @@ public class SearchEngine<R extends SearchResult> {
|
|||||||
resultSet.remove(result);
|
resultSet.remove(result);
|
||||||
|
|
||||||
Set<String> searchKw = resultsSearchKeywordsMap.remove(result);
|
Set<String> searchKw = resultsSearchKeywordsMap.remove(result);
|
||||||
|
if (searchKw != null) {
|
||||||
for (String skw : searchKw) {
|
for (String skw : searchKw) {
|
||||||
Set<R> set = searchKeywordsResultMap.get(skw);
|
Set<R> set = searchKeywordsResultMap.get(skw);
|
||||||
|
if (set == null)
|
||||||
|
continue;
|
||||||
set.remove(result);
|
set.remove(result);
|
||||||
if (set.isEmpty())
|
if (set.isEmpty())
|
||||||
searchKeywordsResultMap.remove(skw);
|
searchKeywordsResultMap.remove(skw);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Set<String> suggestsKw = resultsSearchKeywordsMap.remove(result);
|
Set<String> suggestsKw = resultsSearchKeywordsMap.remove(result);
|
||||||
|
if (suggestsKw != null) {
|
||||||
for (String skw : suggestsKw) {
|
for (String skw : suggestsKw) {
|
||||||
Set<R> set = suggestionsKeywordsResultMap.get(skw);
|
Set<R> set = suggestionsKeywordsResultMap.get(skw);
|
||||||
|
if (set == null)
|
||||||
|
continue;
|
||||||
set.remove(result);
|
set.remove(result);
|
||||||
if (set.isEmpty())
|
if (set.isEmpty())
|
||||||
suggestionsKeywordsResultMap.remove(skw);
|
suggestionsKeywordsResultMap.remove(skw);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
resultsSuggestionsKeywordsMap.remove(result);
|
resultsSuggestionsKeywordsMap.remove(result);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user