Index: lucene/core/src/java/org/apache/lucene/index/DirectoryReader.java =================================================================== --- lucene/core/src/java/org/apache/lucene/index/DirectoryReader.java (revision 1491970) +++ lucene/core/src/java/org/apache/lucene/index/DirectoryReader.java (working copy) @@ -19,6 +19,7 @@ import java.io.FileNotFoundException; import java.io.IOException; +import java.nio.file.NoSuchFileException; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -291,7 +292,7 @@ // IOException allowed to throw there, in case // segments_N is corrupt sis.read(dir, fileName); - } catch (FileNotFoundException fnfe) { + } catch (FileNotFoundException | NoSuchFileException fnfe) { // LUCENE-948: on NFS (and maybe others), if // you have writers switching back and forth // between machines, it's very likely that the Index: lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java =================================================================== --- lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java (revision 1491970) +++ lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java (working copy) @@ -20,6 +20,7 @@ import java.io.Closeable; import java.io.FileNotFoundException; import java.io.IOException; +import java.nio.file.NoSuchFileException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -170,7 +171,7 @@ SegmentInfos sis = new SegmentInfos(); try { sis.read(directory, fileName); - } catch (FileNotFoundException e) { + } catch (FileNotFoundException | NoSuchFileException e) { // LUCENE-948: on NFS (and maybe others), if // you have writers switching back and forth // between machines, it's very likely that the Index: lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java =================================================================== --- lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java (revision 1491970) +++ lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java (working copy) @@ -17,7 +17,6 @@ * limitations under the License. */ -import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintStream; import java.util.ArrayList; Index: lucene/core/src/java/org/apache/lucene/store/Directory.java =================================================================== --- lucene/core/src/java/org/apache/lucene/store/Directory.java (revision 1491970) +++ lucene/core/src/java/org/apache/lucene/store/Directory.java (working copy) @@ -21,6 +21,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.Closeable; +import java.nio.file.NoSuchFileException; import java.util.Collection; // for javadocs import org.apache.lucene.util.IOUtils; @@ -70,12 +71,12 @@ * Returns the length of a file in the directory. This method follows the * following contract: * * * @param name the name of the file for which to return the length. - * @throws FileNotFoundException if the file does not exist. * @throws IOException if there was an IO error while retrieving the file's * length. */ @@ -106,7 +107,9 @@ * the only Directory implementations that respect this * parameter are {@link FSDirectory} and {@link * CompoundFileDirectory}. - */ + *

Throws {@link FileNotFoundException} or {@link NoSuchFileException} + * if the file does not exist. + */ public abstract IndexInput openInput(String name, IOContext context) throws IOException; /** Construct a {@link Lock}. @@ -223,6 +226,8 @@ * efficiently open one or more sliced {@link IndexInput} instances from a * single file handle. The underlying file handle is kept open until the * {@link IndexInputSlicer} is closed. + *

Throws {@link FileNotFoundException} or {@link NoSuchFileException} + * if the file does not exist. * * @throws IOException * if an {@link IOException} occurs Index: lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java =================================================================== --- lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java (revision 1491970) +++ lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java (working copy) @@ -19,6 +19,7 @@ import java.io.FileNotFoundException; import java.io.IOException; +import java.nio.file.NoSuchFileException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -888,7 +889,7 @@ if (t instanceof AlreadyClosedException || t instanceof MergePolicy.MergeAbortedException || t instanceof NullPointerException) { report = !didClose; - } else if (t instanceof FileNotFoundException) { + } else if (t instanceof FileNotFoundException || t instanceof NoSuchFileException) { report = !didClose; } else if (t instanceof IOException) { Throwable t2 = t.getCause(); Index: lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java =================================================================== --- lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java (revision 1491970) +++ lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java (working copy) @@ -20,6 +20,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.nio.file.NoSuchFileException; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; @@ -428,8 +429,8 @@ } try { DirectoryReader.open(fileDirName); - fail("opening DirectoryReader on empty directory failed to produce FileNotFoundException"); - } catch (FileNotFoundException e) { + fail("opening DirectoryReader on empty directory failed to produce FileNotFoundException/NoSuchFileException"); + } catch (FileNotFoundException | NoSuchFileException e) { // GOOD } rmDir(fileDirName); @@ -470,8 +471,8 @@ Directory dir = newFSDirectory(dirFile); try { DirectoryReader.open(dir); - fail("expected FileNotFoundException"); - } catch (FileNotFoundException e) { + fail("expected FileNotFoundException/NoSuchFileException"); + } catch (FileNotFoundException | NoSuchFileException e) { // expected } @@ -480,8 +481,8 @@ // Make sure we still get a CorruptIndexException (not NPE): try { DirectoryReader.open(dir); - fail("expected FileNotFoundException"); - } catch (FileNotFoundException e) { + fail("expected FileNotFoundException/NoSuchFileException"); + } catch (FileNotFoundException | NoSuchFileException e) { // expected } Index: lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java =================================================================== --- lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java (revision 1491970) +++ lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java (working copy) @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.Reader; import java.io.StringReader; +import java.nio.file.NoSuchFileException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -1671,7 +1672,7 @@ } catch (CorruptIndexException ex) { // Exceptions are fine - we are running out of file handlers here continue; - } catch (FileNotFoundException ex) { + } catch (FileNotFoundException | NoSuchFileException ex) { continue; } failure.clearDoFail(); Index: lucene/core/src/test/org/apache/lucene/index/TestIndexWriterLockRelease.java =================================================================== --- lucene/core/src/test/org/apache/lucene/index/TestIndexWriterLockRelease.java (revision 1491970) +++ lucene/core/src/test/org/apache/lucene/index/TestIndexWriterLockRelease.java (working copy) @@ -19,6 +19,7 @@ import java.io.FileNotFoundException; import java.io.IOException; +import java.nio.file.NoSuchFileException; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.index.IndexWriterConfig.OpenMode; @@ -37,10 +38,10 @@ Directory dir = newFSDirectory(_TestUtil.getTempDir("testLockRelease")); try { new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())).setOpenMode(OpenMode.APPEND)); - } catch (FileNotFoundException e) { + } catch (FileNotFoundException | NoSuchFileException e) { try { new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())).setOpenMode(OpenMode.APPEND)); - } catch (FileNotFoundException e1) { + } catch (FileNotFoundException | NoSuchFileException e1) { } } finally { dir.close(); Index: lucene/core/src/test/org/apache/lucene/store/TestDirectory.java =================================================================== --- lucene/core/src/test/org/apache/lucene/store/TestDirectory.java (revision 1491970) +++ lucene/core/src/test/org/apache/lucene/store/TestDirectory.java (working copy) @@ -20,6 +20,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.nio.file.NoSuchFileException; import java.util.Arrays; import org.apache.lucene.store.MockDirectoryWrapper.Throttling; @@ -98,7 +99,7 @@ try { IndexInput input = dir.openInput(file, newIOContext(random())); input.close(); - } catch (FileNotFoundException e) { + } catch (FileNotFoundException | NoSuchFileException e) { // ignore } catch (IOException e) { if (e.getMessage().contains("still open for writing")) { Index: lucene/replicator/src/test/org/apache/lucene/replicator/LocalReplicatorTest.java =================================================================== --- lucene/replicator/src/test/org/apache/lucene/replicator/LocalReplicatorTest.java (revision 1491970) +++ lucene/replicator/src/test/org/apache/lucene/replicator/LocalReplicatorTest.java (working copy) @@ -155,10 +155,8 @@ try { replicator.obtainFile(res.id, res.sourceFiles.keySet().iterator().next(), "madeUpFile"); fail("should have failed obtaining an unrecognized file"); - } catch (FileNotFoundException e) { + } catch (FileNotFoundException | NoSuchFileException e) { // expected - } catch (NoSuchFileException e) { - // expected (only java 1.7) } } Index: lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java =================================================================== --- lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java (revision 1491970) +++ lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java (working copy) @@ -20,6 +20,7 @@ import java.io.Closeable; import java.io.FileNotFoundException; import java.io.IOException; +import java.nio.file.NoSuchFileException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -385,7 +386,7 @@ if (randomState.nextBoolean()) { throw new IOException("a random IOException (" + name + ")"); } else { - throw new FileNotFoundException("a random IOException (" + name + ")"); + throw randomState.nextBoolean() ? new FileNotFoundException("a random IOException (" + name + ")") : new NoSuchFileException("a random IOException (" + name + ")"); } } } @@ -544,7 +545,7 @@ maybeThrowDeterministicException(); } if (!delegate.fileExists(name)) { - throw new FileNotFoundException(name + " in dir=" + delegate); + throw randomState.nextBoolean() ? new FileNotFoundException(name + " in dir=" + delegate) : new NoSuchFileException(name + " in dir=" + delegate); } // cannot open a file for input if it's still open for @@ -920,7 +921,7 @@ throws IOException { maybeYield(); if (!delegate.fileExists(name)) { - throw new FileNotFoundException(name); + throw randomState.nextBoolean() ? new FileNotFoundException(name) : new NoSuchFileException(name); } // cannot open a file for input if it's still open for // output, except for segments.gen and segments_N