Index: lucene/CHANGES.txt =================================================================== --- lucene/CHANGES.txt (revision 933613) +++ lucene/CHANGES.txt (working copy) @@ -111,6 +111,11 @@ behavior you can call writer.commit()/close() immediately after you create it. (Shai Erera, Mike McCandless) +* LUCENE-2316: Directory.fileLength contract was clarified - it returns the + actual file's length if the file exists, and throws FileNotFoundException + otherwise. Returning length=0 for a non-existent file is no longer allowed. If + you relied on that, make sure to catch the exception. (Shai Erera) + Changes in runtime behavior * LUCENE-1923: Made IndexReader.toString() produce something Index: lucene/contrib/db/bdb-je/src/java/org/apache/lucene/store/je/JEDirectory.java =================================================================== --- lucene/contrib/db/bdb-je/src/java/org/apache/lucene/store/je/JEDirectory.java (revision 933591) +++ lucene/contrib/db/bdb-je/src/java/org/apache/lucene/store/je/JEDirectory.java (working copy) @@ -19,6 +19,7 @@ import java.io.ByteArrayInputStream; import java.io.DataInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; @@ -133,7 +134,7 @@ if (file.exists(this)) return file.getLength(); - throw new IOException("File does not exist: " + name); + throw new FileNotFoundException(name); } @Override Index: lucene/contrib/db/bdb/src/java/org/apache/lucene/store/db/DbDirectory.java =================================================================== --- lucene/contrib/db/bdb/src/java/org/apache/lucene/store/db/DbDirectory.java (revision 933591) +++ lucene/contrib/db/bdb/src/java/org/apache/lucene/store/db/DbDirectory.java (working copy) @@ -17,6 +17,7 @@ * limitations under the License. */ +import java.io.FileNotFoundException; import java.io.IOException; import java.io.ByteArrayInputStream; import java.io.DataInputStream; @@ -140,15 +141,13 @@ } @Override - public long fileLength(String name) - throws IOException - { + public long fileLength(String name) throws IOException { File file = new File(name); if (file.exists(this)) return file.getLength(); - throw new IOException("File does not exist: " + name); + throw new FileNotFoundException(name); } @Override Index: lucene/src/java/org/apache/lucene/index/CompoundFileReader.java =================================================================== --- lucene/src/java/org/apache/lucene/index/CompoundFileReader.java (revision 933591) +++ lucene/src/java/org/apache/lucene/index/CompoundFileReader.java (working copy) @@ -24,6 +24,7 @@ import org.apache.lucene.store.Lock; import java.util.HashMap; +import java.io.FileNotFoundException; import java.io.IOException; @@ -183,12 +184,10 @@ /** Returns the length of a file in the directory. * @throws IOException if the file does not exist */ @Override - public long fileLength(String name) - throws IOException - { + public long fileLength(String name) throws IOException { FileEntry e = entries.get(name); if (e == null) - throw new IOException("File " + name + " does not exist"); + throw new FileNotFoundException(name); return e.length; } Index: lucene/src/java/org/apache/lucene/store/Directory.java =================================================================== --- lucene/src/java/org/apache/lucene/store/Directory.java (revision 933613) +++ lucene/src/java/org/apache/lucene/store/Directory.java (working copy) @@ -17,6 +17,7 @@ * limitations under the License. */ +import java.io.FileNotFoundException; import java.io.IOException; import java.io.Closeable; import java.util.Collection; // for javadocs @@ -73,9 +74,20 @@ public abstract void deleteFile(String name) throws IOException; - /** Returns the length of a file in the directory. */ - public abstract long fileLength(String name) - throws IOException; + /** + * Returns the length of a file in the directory. This method follows the + * following contract: + *