Apache Solr open-source search software
LUCENE-3680: exception consistency in o.a.l.store
Robert Muir19801a4d8714
diff --git a/lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java b/lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.javaindex bdd1f5d116a..fdaf3d7641e 100644--- a/lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java+++ b/lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java@@ -17,6 +17,7 @@ package org.apache.lucene.store;* the License.*/+import java.io.EOFException;import java.io.File;import java.io.IOException;import java.io.FileInputStream;@@ -340,7 +341,7 @@ public class DirectIOLinuxDirectory extends FSDirectory {throw new IOException(ioe.getMessage() + ": " + this, ioe);}if (n < 0) {- throw new IOException("eof: " + this);+ throw new EOFException("read past EOF: " + this);}buffer.rewind();}diff --git a/lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java b/lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.javaindex ebfc60b2d03..36a25f0df2d 100644--- a/lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java+++ b/lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java@@ -97,7 +97,7 @@ public class WindowsDirectory extends FSDirectory {}if (bytesRead != length) {- throw new EOFException("Read past EOF (resource: " + this + ")");+ throw new EOFException("read past EOF: " + this);}}diff --git a/lucene/src/java/org/apache/lucene/store/BufferedIndexInput.java b/lucene/src/java/org/apache/lucene/store/BufferedIndexInput.javaindex a5eb0515bb4..e205c1b41c9 100644--- a/lucene/src/java/org/apache/lucene/store/BufferedIndexInput.java+++ b/lucene/src/java/org/apache/lucene/store/BufferedIndexInput.java@@ -17,6 +17,7 @@ package org.apache.lucene.store;* limitations under the License.*/+import java.io.EOFException;import java.io.IOException;/** Base implementation class for buffered {@link IndexInput}. */@@ -138,7 +139,7 @@ public abstract class BufferedIndexInput extends IndexInput {if(bufferLength<len){// Throw an exception when refill() could not read len bytes:System.arraycopy(buffer, 0, b, offset, bufferLength);- throw new IOException("read past EOF");+ throw new EOFException("read past EOF: " + this);} else {System.arraycopy(buffer, 0, b, offset, len);bufferPosition=len;@@ -153,7 +154,7 @@ public abstract class BufferedIndexInput extends IndexInput {// had in the buffer.long after = bufferStart+bufferPosition+len;if(after > length())- throw new IOException("read past EOF");+ throw new EOFException("read past EOF: " + this);readInternal(b, offset, len);bufferStart = after;bufferPosition = 0;@@ -231,7 +232,7 @@ public abstract class BufferedIndexInput extends IndexInput {end = length();int newLength = (int)(end - start);if (newLength <= 0)- throw new IOException("read past EOF");+ throw new EOFException("read past EOF: " + this);if (buffer == null) {newBuffer(new byte[bufferSize]); // allocate buffer lazilydiff --git a/lucene/src/java/org/apache/lucene/store/ByteArrayDataInput.java b/lucene/src/java/org/apache/lucene/store/ByteArrayDataInput.javaindex b968f4eb298..d75dc078e49 100644--- a/lucene/src/java/org/apache/lucene/store/ByteArrayDataInput.java+++ b/lucene/src/java/org/apache/lucene/store/ByteArrayDataInput.java@@ -100,11 +100,11 @@ public final class ByteArrayDataInput extends DataInput {@Overridepublic int readVInt() {- checkBounds();+ assert checkBounds();byte b = bytes[pos++];int i = b & 0x7F;for (int shift = 7; (b & 0x80) != 0; shift += 7) {- checkBounds();+ assert checkBounds();b = bytes[pos++];i |= (b & 0x7F) << shift;}@@ -113,11 +113,11 @@ public final class ByteArrayDataInput extends DataInput {@Overridepublic long readVLong() {- checkBounds();+ assert checkBounds();byte b = bytes[pos++];long i = b & 0x7F;for (int shift = 7; (b & 0x80) != 0; shift += 7) {- checkBounds();+ assert checkBounds();b = bytes[pos++];i |= (b & 0x7FL) << shift;}@@ -127,7 +127,7 @@ public final class ByteArrayDataInput extends DataInput {// NOTE: AIOOBE not EOF if you read too much@Overridepublic byte readByte() {- checkBounds();+ assert checkBounds();return bytes[pos++];}@@ -140,7 +140,6 @@ public final class ByteArrayDataInput extends DataInput {}private boolean checkBounds() {- assert pos < limit;- return true;+ return pos < limit;}}diff --git a/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java b/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.javaindex b19dcbaa867..c0304b58bb6 100644--- a/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java+++ b/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java@@ -216,7 +216,7 @@ public final class CompoundFileDirectory extends Directory {final String id = IndexFileNames.stripSegmentName(name);final FileEntry entry = entries.get(id);if (entry == null) {- throw new IOException("No sub-file with id " + id + " found (fileName=" + name + " files: " + entries.keySet() + ")");+ throw new FileNotFoundException("No sub-file with id " + id + " found (fileName=" + name + " files: " + entries.keySet() + ")");}return handle.openSlice(name, entry.offset, entry.length);}@@ -310,7 +310,7 @@ public final class CompoundFileDirectory extends Directory {final String id = IndexFileNames.stripSegmentName(name);final FileEntry entry = entries.get(id);if (entry == null) {- throw new IOException("No sub-file with id " + id + " found (fileName=" + name + " files: " + entries.keySet() + ")");+ throw new FileNotFoundException("No sub-file with id " + id + " found (fileName=" + name + " files: " + entries.keySet() + ")");}return new IndexInputSlicer() {@Overridediff --git a/lucene/src/java/org/apache/lucene/store/DataInput.java b/lucene/src/java/org/apache/lucene/store/DataInput.javaindex 5af441fdc0f..c5edee93c08 100644--- a/lucene/src/java/org/apache/lucene/store/DataInput.java+++ b/lucene/src/java/org/apache/lucene/store/DataInput.java@@ -21,6 +21,8 @@ import java.io.IOException;import java.util.HashMap;import java.util.Map;+import org.apache.lucene.util.IOUtils;+/*** Abstract base class for performing read operations of Lucene's low-level* data types.@@ -166,7 +168,7 @@ public abstract class DataInput implements Cloneable {int length = readVInt();final byte[] bytes = new byte[length];readBytes(bytes, 0, length);- return new String(bytes, 0, length, "UTF-8");+ return new String(bytes, 0, length, IOUtils.CHARSET_UTF_8);}/** Returns a clone of this stream.diff --git a/lucene/src/java/org/apache/lucene/store/Directory.java b/lucene/src/java/org/apache/lucene/store/Directory.javaindex 82b2604f2a5..8dd98264709 100644--- a/lucene/src/java/org/apache/lucene/store/Directory.java+++ b/lucene/src/java/org/apache/lucene/store/Directory.java@@ -17,6 +17,7 @@ package org.apache.lucene.store;* limitations under the License.*/+import java.io.EOFException;import java.io.FileNotFoundException;import java.io.IOException;import java.io.Closeable;@@ -305,7 +306,7 @@ public abstract class Directory implements Closeable {protected void readInternal(byte[] b, int offset, int len) throws IOException {long start = getFilePointer();if(start + len > length)- throw new IOException("read past EOF");+ throw new EOFException("read past EOF: " + this);base.seek(fileOffset + start);base.readBytes(b, offset, len, false);}@@ -338,7 +339,7 @@ public abstract class Directory implements Closeable {if (numBytes > 0) {long start = getFilePointer();if (start + numBytes > length) {- throw new IOException("read past EOF");+ throw new EOFException("read past EOF: " + this);}base.seek(fileOffset + start);base.copyBytes(out, numBytes);diff --git a/lucene/src/java/org/apache/lucene/store/MMapDirectory.java b/lucene/src/java/org/apache/lucene/store/MMapDirectory.javaindex 805019b4609..c30a76b28e4 100644--- a/lucene/src/java/org/apache/lucene/store/MMapDirectory.java+++ b/lucene/src/java/org/apache/lucene/store/MMapDirectory.java@@ -17,6 +17,7 @@ package org.apache.lucene.store;* limitations under the License.*/+import java.io.EOFException;import java.io.IOException;import java.io.File;import java.io.RandomAccessFile;@@ -303,7 +304,7 @@ public class MMapDirectory extends FSDirectory {do {curBufIndex++;if (curBufIndex >= buffers.length) {- throw new IOException("read past EOF: " + this);+ throw new EOFException("read past EOF: " + this);}curBuf = buffers[curBufIndex];curBuf.position(0);@@ -326,7 +327,7 @@ public class MMapDirectory extends FSDirectory {offset += curAvail;curBufIndex++;if (curBufIndex >= buffers.length) {- throw new IOException("read past EOF: " + this);+ throw new EOFException("read past EOF: " + this);}curBuf = buffers[curBufIndex];curBuf.position(0);@@ -394,12 +395,12 @@ public class MMapDirectory extends FSDirectory {if (pos < 0L) {throw new IllegalArgumentException("Seeking to negative position: " + this);}- throw new IOException("seek past EOF");+ throw new EOFException("seek past EOF: " + this);} catch (IllegalArgumentException iae) {if (pos < 0L) {throw new IllegalArgumentException("Seeking to negative position: " + this);}- throw new IOException("seek past EOF: " + this);+ throw new EOFException("seek past EOF: " + this);} catch (NullPointerException npe) {throw new AlreadyClosedException("MMapIndexInput already closed: " + this);}diff --git a/lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java b/lucene/src/java/org/apache/lucene/store/NIOFSDirectory.javaindex 7ba01e9ae33..12a1a91d14b 100644--- a/lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java+++ b/lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java@@ -182,7 +182,7 @@ public class NIOFSDirectory extends FSDirectory {long pos = getFilePointer() + off;if (pos + len > end) {- throw new EOFException("read past EOF (resource: " + this + ")");+ throw new EOFException("read past EOF: " + this);}try {diff --git a/lucene/src/java/org/apache/lucene/store/RAMInputStream.java b/lucene/src/java/org/apache/lucene/store/RAMInputStream.javaindex 44725b17555..60c83f62928 100644--- a/lucene/src/java/org/apache/lucene/store/RAMInputStream.java+++ b/lucene/src/java/org/apache/lucene/store/RAMInputStream.java@@ -91,7 +91,7 @@ public class RAMInputStream extends IndexInput implements Cloneable {if (currentBufferIndex >= file.numBuffers()) {// end of file reached, no more buffers leftif (enforceEOF) {- throw new EOFException("Read past EOF (resource: " + this + ")");+ throw new EOFException("read past EOF: " + this);} else {// Force EOF if a read takes place at this positioncurrentBufferIndex--;diff --git a/lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java b/lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.javaindex fc307a5d19b..f256d29f365 100644--- a/lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java+++ b/lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java@@ -17,6 +17,7 @@ package org.apache.lucene.store;* limitations under the License.*/+import java.io.EOFException;import java.io.File;import java.io.IOException;import java.io.RandomAccessFile;@@ -145,7 +146,7 @@ public class SimpleFSDirectory extends FSDirectory {int total = 0;if (position + len > end) {- throw new IOException("read past EOF: " + this);+ throw new EOFException("read past EOF: " + this);}try {diff --git a/lucene/src/test/org/apache/lucene/util/TestByteBlockPool.java b/lucene/src/test/org/apache/lucene/util/TestByteBlockPool.javaindex d7620b358b3..26ea474d4e9 100644--- a/lucene/src/test/org/apache/lucene/util/TestByteBlockPool.java+++ b/lucene/src/test/org/apache/lucene/util/TestByteBlockPool.java@@ -1,5 +1,6 @@package org.apache.lucene.util;+import java.io.EOFException;import java.io.IOException;import java.util.ArrayList;import java.util.List;@@ -59,7 +60,7 @@ public class TestByteBlockPool extends LuceneTestCase {try {input.readByte();fail("must be EOF");- } catch (IOException e) {+ } catch (EOFException e) {// expected - read past EOF}dir.close();