You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2012/01/07 21:56:26 UTC

svn commit: r1228727 - in /lucene/dev/trunk/lucene: contrib/misc/src/java/org/apache/lucene/store/ src/java/org/apache/lucene/store/ src/test/org/apache/lucene/util/

Author: rmuir
Date: Sat Jan  7 20:56:25 2012
New Revision: 1228727

URL: http://svn.apache.org/viewvc?rev=1228727&view=rev
Log:
LUCENE-3680: exception consistency in o.a.l.store

Modified:
    lucene/dev/trunk/lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java
    lucene/dev/trunk/lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/BufferedIndexInput.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/ByteArrayDataInput.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/DataInput.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/Directory.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/MMapDirectory.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/RAMInputStream.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/TestByteBlockPool.java

Modified: lucene/dev/trunk/lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java?rev=1228727&r1=1228726&r2=1228727&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java (original)
+++ lucene/dev/trunk/lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java Sat Jan  7 20:56:25 2012
@@ -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 exte
         throw new IOException(ioe.getMessage() + ": " + this, ioe);
       }
       if (n < 0) {
-        throw new IOException("eof: " + this);
+        throw new EOFException("read past EOF: " + this);
       }
       buffer.rewind();
     }

Modified: lucene/dev/trunk/lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java?rev=1228727&r1=1228726&r2=1228727&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java (original)
+++ lucene/dev/trunk/lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java Sat Jan  7 20:56:25 2012
@@ -97,7 +97,7 @@ public class WindowsDirectory extends FS
       }
 
       if (bytesRead != length) {
-        throw new EOFException("Read past EOF (resource: " + this + ")");
+        throw new EOFException("read past EOF: " + this);
       }
     }
 

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/BufferedIndexInput.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/BufferedIndexInput.java?rev=1228727&r1=1228726&r2=1228727&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/BufferedIndexInput.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/BufferedIndexInput.java Sat Jan  7 20:56:25 2012
@@ -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
         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
         // 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
       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 lazily

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/ByteArrayDataInput.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/ByteArrayDataInput.java?rev=1228727&r1=1228726&r2=1228727&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/ByteArrayDataInput.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/ByteArrayDataInput.java Sat Jan  7 20:56:25 2012
@@ -100,11 +100,11 @@ public final class ByteArrayDataInput ex
 
   @Override
   public 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 ex
  
   @Override
   public 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 ex
   // NOTE: AIOOBE not EOF if you read too much
   @Override
   public byte readByte() {
-    checkBounds();
+    assert checkBounds();
     return bytes[pos++];
   }
 
@@ -140,7 +140,6 @@ public final class ByteArrayDataInput ex
   }
 
   private boolean checkBounds() {
-    assert pos < limit;
-    return true;
+    return pos < limit;
   }
 }

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java?rev=1228727&r1=1228726&r2=1228727&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/CompoundFileDirectory.java Sat Jan  7 20:56:25 2012
@@ -216,7 +216,7 @@ public final class CompoundFileDirectory
     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
     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() {
       @Override

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/DataInput.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/DataInput.java?rev=1228727&r1=1228726&r2=1228727&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/DataInput.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/DataInput.java Sat Jan  7 20:56:25 2012
@@ -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 implemen
     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.

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/Directory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/Directory.java?rev=1228727&r1=1228726&r2=1228727&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/Directory.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/Directory.java Sat Jan  7 20:56:25 2012
@@ -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 implemen
     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 implemen
       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);

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/MMapDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/MMapDirectory.java?rev=1228727&r1=1228726&r2=1228727&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/MMapDirectory.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/MMapDirectory.java Sat Jan  7 20:56:25 2012
@@ -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 FSDir
         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 FSDir
           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 FSDir
         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);
       }

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java?rev=1228727&r1=1228726&r2=1228727&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java Sat Jan  7 20:56:25 2012
@@ -182,7 +182,7 @@ public class NIOFSDirectory extends FSDi
       long pos = getFilePointer() + off;
       
       if (pos + len > end) {
-        throw new EOFException("read past EOF (resource: " + this + ")");
+        throw new EOFException("read past EOF: " + this);
       }
 
       try {

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/RAMInputStream.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/RAMInputStream.java?rev=1228727&r1=1228726&r2=1228727&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/RAMInputStream.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/RAMInputStream.java Sat Jan  7 20:56:25 2012
@@ -91,7 +91,7 @@ public class RAMInputStream extends Inde
     if (currentBufferIndex >= file.numBuffers()) {
       // end of file reached, no more buffers left
       if (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 position
         currentBufferIndex--;

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java?rev=1228727&r1=1228726&r2=1228727&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java Sat Jan  7 20:56:25 2012
@@ -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 F
         int total = 0;
 
         if (position + len > end) {
-          throw new IOException("read past EOF: " + this);
+          throw new EOFException("read past EOF: " + this);
         }
 
         try {

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/TestByteBlockPool.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/TestByteBlockPool.java?rev=1228727&r1=1228726&r2=1228727&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/TestByteBlockPool.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/TestByteBlockPool.java Sat Jan  7 20:56:25 2012
@@ -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 L
     try {
       input.readByte();
       fail("must be EOF");
-    } catch (IOException e) {
+    } catch (EOFException e) {
       // expected - read past EOF
     }
     dir.close();