Skip to content

Apache Lucene open-source search software

LUCENE-8663: NRTCachingDirectory.slowFileExists may open a file while it's inaccessible

Dawid Weissb802a5268571
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index bb392a85fd7..c3d43ad7c76 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -10,6 +10,10 @@ API Changes
* LUCENE-8474: RAMDirectory and associated deprecated classes have been
removed. (Dawid Weiss)
+Bug fixes:
+
+* LUCENE-8663: NRTCachingDirectory.slowFileExists may open a file while
+ it's inaccessible. (Dawid Weiss)
======================= Lucene 8.1.0 =======================
(No Changes)
diff --git a/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java b/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
index ee8aac0e1a1..63526742372 100644
--- a/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
@@ -289,7 +289,7 @@ public class NRTCachingDirectory extends FilterDirectory implements Accountable
* there's some unexpected error. */
static boolean slowFileExists(Directory dir, String fileName) throws IOException {
try {
- dir.openInput(fileName, IOContext.DEFAULT).close();
+ dir.fileLength(fileName);
return true;
} catch (NoSuchFileException | FileNotFoundException e) {
return false;