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:
René Pfeuffer
2022-03-30 15:30:54 +02:00
committed by GitHub
parent 5505b3ce11
commit de9984ae2c
5 changed files with 31 additions and 53 deletions

View File

@@ -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);
}

View File

@@ -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()));