From 47aea5507748408e399c6ecdd4d08dfc7207be02 Mon Sep 17 00:00:00 2001 From: tesshucom Date: Thu, 27 Feb 2020 16:21:12 +0900 Subject: [PATCH] Avoid NPE Because there is a case where IndexSearcher is null before the scan is executed. --- .../controller/InternalHelpController.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/airsonic-main/src/main/java/org/airsonic/player/controller/InternalHelpController.java b/airsonic-main/src/main/java/org/airsonic/player/controller/InternalHelpController.java index 7091c43c..aa76fdfd 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/controller/InternalHelpController.java +++ b/airsonic-main/src/main/java/org/airsonic/player/controller/InternalHelpController.java @@ -35,6 +35,7 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.input.ReversedLinesFileReader; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.index.IndexReader; +import org.apache.lucene.search.IndexSearcher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -260,14 +261,18 @@ public class InternalHelpController { private void gatherIndexInfo(Map map) { SortedMap indexStats = new TreeMap<>(); for (IndexType indexType : IndexType.values()) { - try (IndexReader reader = indexManager.getSearcher(indexType).getIndexReader()) { - IndexStatistics stat = new IndexStatistics(); - stat.setName(indexType.name()); + IndexStatistics stat = new IndexStatistics(); + IndexSearcher searcher = indexManager.getSearcher(indexType); + stat.setName(indexType.name()); + indexStats.put(indexType.name(), stat); + if (searcher != null) { + IndexReader reader = searcher.getIndexReader(); stat.setCount(reader.numDocs()); stat.setDeletedCount(reader.numDeletedDocs()); - indexStats.put(indexType.name(), stat); - } catch (IOException e) { - LOG.debug("Unable to gather information about {} index", indexType.name(), e); + indexManager.release(indexType, searcher); + } else { + stat.setCount(0); + stat.setDeletedCount(0); } } map.put("indexStatistics", indexStats);