mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-20 22:42:16 +01:00
Do not process missing index types (#1985)
Fixes an error that arises, when a plugin with search indices for repositories is removed and later on a repository is deleted. This led to a null pointer exception in the SearchableTypeResolver, but only because an "illegal" index detail without proper type was given as a parameter. This type cannot be resolved any longer due to the removed plugin. We therefore can simply filter these index details.
This commit is contained in:
@@ -27,6 +27,8 @@ package sonia.scm.search;
|
||||
import com.google.common.base.Joiner;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.work.CentralWorkQueue;
|
||||
import sonia.scm.work.CentralWorkQueue.Enqueue;
|
||||
import sonia.scm.work.Task;
|
||||
@@ -41,6 +43,8 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class LuceneSearchEngine implements SearchEngine {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(LuceneSearchEngine.class);
|
||||
|
||||
private final IndexManager indexManager;
|
||||
private final SearchableTypeResolver resolver;
|
||||
private final LuceneQueryBuilderFactory queryBuilderFactory;
|
||||
@@ -128,10 +132,19 @@ public class LuceneSearchEngine implements SearchEngine {
|
||||
indexManager.all()
|
||||
.stream()
|
||||
.filter(predicate)
|
||||
.filter(this::isTypeAvailable)
|
||||
.map(details -> new IndexParams(details.getName(), resolver.resolve(details.getType())))
|
||||
.forEach(consumer);
|
||||
}
|
||||
|
||||
private boolean isTypeAvailable(IndexDetails details) {
|
||||
if (details.getType() == null) {
|
||||
LOG.info("no type found for index with name '{}'; index will not be updated", details.getName());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void batch(IndexParams params, Task task) {
|
||||
LuceneSearchEngine.this.enqueue(params.getSearchableType(), params.getIndex(), resources, task);
|
||||
}
|
||||
|
||||
@@ -86,9 +86,6 @@ class SearchableTypeResolver {
|
||||
}
|
||||
|
||||
public LuceneSearchableType resolve(Class<?> type) {
|
||||
if (type == null) {
|
||||
throw notFound(entity("type", "null"));
|
||||
}
|
||||
LuceneSearchableType searchableType = classToSearchableType.get(type);
|
||||
if (searchableType == null) {
|
||||
throw notFound(entity("type", type.getName()));
|
||||
|
||||
Reference in New Issue
Block a user