diff --git a/solr/core/src/java/org/apache/solr/storage/AccessDirectory.java b/solr/core/src/java/org/apache/solr/storage/AccessDirectory.java index 8ec3dca6a60..3f74746405d 100644 --- a/solr/core/src/java/org/apache/solr/storage/AccessDirectory.java +++ b/solr/core/src/java/org/apache/solr/storage/AccessDirectory.java @@ -25,6 +25,7 @@ import java.io.Closeable; import java.io.EOFException; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; import java.io.UncheckedIOException; @@ -131,7 +132,7 @@ public AccessDirectory( public long fileLength(String name) throws IOException { try { return super.fileLength(name); - } catch (NoSuchFileException ex) { + } catch (NoSuchFileException | FileNotFoundException ex) { LazyEntry lazy = open(name); if (lazy == null) { throw ex; @@ -174,7 +175,7 @@ public void sync(Collection names) throws IOException { for (String name : names) { try { fsync(name); - } catch (NoSuchFileException ex) { + } catch (NoSuchFileException | FileNotFoundException ex) { LazyEntry lazy = open(name); if (lazy == null) { throw ex; @@ -380,7 +381,7 @@ public IndexInput openInput(String name, IOContext context) throws IOException { IndexInput ret = super.openInput(name, context); rawCt.increment(); return ret; - } catch (NoSuchFileException ex) { + } catch (NoSuchFileException | FileNotFoundException ex) { try { LazyEntry lazy = open(name); if (lazy == null) { diff --git a/solr/core/src/java/org/apache/solr/storage/CompressingDirectory.java b/solr/core/src/java/org/apache/solr/storage/CompressingDirectory.java index f8d1fe66ec6..70ca3bfc654 100644 --- a/solr/core/src/java/org/apache/solr/storage/CompressingDirectory.java +++ b/solr/core/src/java/org/apache/solr/storage/CompressingDirectory.java @@ -18,7 +18,6 @@ package org.apache.solr.storage; import java.io.ByteArrayOutputStream; -import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.nio.ByteBuffer; @@ -107,15 +106,14 @@ public CompressingDirectory( @Override public long fileLength(String name) throws IOException { Path path = directoryPath.resolve(name); - File file = path.toFile(); ensureOpen(); if (getPendingDeletions().contains(name)) { throw new NoSuchFileException("file \"" + name + "\" is pending delete"); } - if (file.length() < Long.BYTES) { + if (Files.size(path) < Long.BYTES) { return 0; } else { - try (FileInputStream in = new FileInputStream(file)) { + try (FileInputStream in = new FileInputStream(path.toFile())) { byte[] bytes = in.readNBytes(Long.BYTES); return ByteBuffer.wrap(bytes).getLong(0); }