From 5636ad0f93164b431dbe5d60e337baba02ff107f Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Tue, 9 Jan 2024 16:25:22 +0100 Subject: [PATCH] Fix NPE when opening and re-opening a library (#10763) --- src/main/java/org/jabref/logic/pdf/search/PdfIndexer.java | 2 +- .../java/org/jabref/logic/pdf/search/PdfIndexerManager.java | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/logic/pdf/search/PdfIndexer.java b/src/main/java/org/jabref/logic/pdf/search/PdfIndexer.java index a973831e134..d28f33b6507 100644 --- a/src/main/java/org/jabref/logic/pdf/search/PdfIndexer.java +++ b/src/main/java/org/jabref/logic/pdf/search/PdfIndexer.java @@ -280,7 +280,7 @@ private void addToIndex(BibEntry entry, LinkedFile linkedFile, boolean shouldCom */ public Set getListOfFilePaths() { Set paths = new HashSet<>(); - try (IndexReader reader = DirectoryReader.open(indexWriter)) { + try (IndexReader reader = DirectoryReader.open(getIndexWriter())) { IndexSearcher searcher = new IndexSearcher(reader); MatchAllDocsQuery query = new MatchAllDocsQuery(); TopDocs allDocs = searcher.search(query, Integer.MAX_VALUE); diff --git a/src/main/java/org/jabref/logic/pdf/search/PdfIndexerManager.java b/src/main/java/org/jabref/logic/pdf/search/PdfIndexerManager.java index 3f4bca38c49..8b620c015c9 100644 --- a/src/main/java/org/jabref/logic/pdf/search/PdfIndexerManager.java +++ b/src/main/java/org/jabref/logic/pdf/search/PdfIndexerManager.java @@ -62,16 +62,20 @@ public static void shutdownAllIndexers() { LOGGER.debug("Problem closing PDF indexer", e); } }); + indexerMap.clear(); + pathFilePreferencesMap.clear(); } public static void shutdownIndexer(BibDatabaseContext context) { - PdfIndexer indexer = indexerMap.get(context.getFulltextIndexPath()); + Path fulltextIndexPath = context.getFulltextIndexPath(); + PdfIndexer indexer = indexerMap.remove(fulltextIndexPath); if (indexer != null) { try { indexer.close(); } catch (IOException e) { LOGGER.debug("Could not close indexer", e); } + pathFilePreferencesMap.remove(fulltextIndexPath); } else { LOGGER.debug("No indexer found for context {}", context); }