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 22:08:23 UTC
svn commit: r1228729 - in /lucene/dev/branches/branch_3x: ./ lucene/
lucene/contrib/misc/src/java/org/apache/lucene/store/
lucene/src/java/org/apache/lucene/index/
lucene/src/java/org/apache/lucene/store/
lucene/src/test/org/apache/lucene/util/
Author: rmuir
Date: Sat Jan 7 21:08:22 2012
New Revision: 1228729
URL: http://svn.apache.org/viewvc?rev=1228729&view=rev
Log:
LUCENE-3680: exception consistency in o.a.l.store
Modified:
lucene/dev/branches/branch_3x/ (props changed)
lucene/dev/branches/branch_3x/lucene/ (props changed)
lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java
lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java
lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/CompoundFileReader.java
lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/BufferedIndexInput.java
lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/ByteArrayDataInput.java
lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/DataInput.java
lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/MMapDirectory.java
lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java
lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/RAMInputStream.java
lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java
lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/TestByteBlockPool.java
Modified: lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java?rev=1228729&r1=1228728&r2=1228729&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java Sat Jan 7 21:08:22 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;
@@ -335,7 +336,7 @@ public class DirectIOLinuxDirectory exte
throw newIOE;
}
if (n < 0) {
- throw new IOException("eof: " + this);
+ throw new EOFException("read past EOF: " + this);
}
buffer.rewind();
}
Modified: lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java?rev=1228729&r1=1228728&r2=1228729&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/misc/src/java/org/apache/lucene/store/WindowsDirectory.java Sat Jan 7 21:08:22 2012
@@ -99,7 +99,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/branches/branch_3x/lucene/src/java/org/apache/lucene/index/CompoundFileReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/CompoundFileReader.java?rev=1228729&r1=1228728&r2=1228729&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/CompoundFileReader.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/index/CompoundFileReader.java Sat Jan 7 21:08:22 2012
@@ -153,7 +153,7 @@ class CompoundFileReader extends Directo
id = IndexFileNames.stripSegmentName(id);
FileEntry entry = entries.get(id);
if (entry == null) {
- throw new IOException("No sub-file with id " + id + " found (fileName=" + fileName + " files: " + entries.keySet() + ")");
+ throw new FileNotFoundException("No sub-file with id " + id + " found (fileName=" + fileName + " files: " + entries.keySet() + ")");
}
return new CSIndexInput(stream, entry.offset, entry.length, readBufferSize);
@@ -269,7 +269,7 @@ class CompoundFileReader extends Directo
protected void readInternal(byte[] b, int offset, int len) throws IOException {
long start = getFilePointer();
if(start + len > length)
- throw new EOFException("read past EOF (resource: " + base + ")");
+ throw new EOFException("read past EOF: " + base);
base.seek(fileOffset + start);
base.readBytes(b, offset, len, false);
}
@@ -302,7 +302,7 @@ class CompoundFileReader extends Directo
if (numBytes > 0) {
long start = getFilePointer();
if (start + numBytes > length) {
- throw new EOFException("read past EOF (resource: " + base + ")");
+ throw new EOFException("read past EOF: " + base);
}
base.seek(fileOffset + start);
base.copyBytes(out, numBytes);
Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/BufferedIndexInput.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/BufferedIndexInput.java?rev=1228729&r1=1228728&r2=1228729&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/BufferedIndexInput.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/BufferedIndexInput.java Sat Jan 7 21:08:22 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}. */
@@ -136,7 +137,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;
@@ -151,7 +152,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;
@@ -220,7 +221,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/branches/branch_3x/lucene/src/java/org/apache/lucene/store/ByteArrayDataInput.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/ByteArrayDataInput.java?rev=1228729&r1=1228728&r2=1228729&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/ByteArrayDataInput.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/ByteArrayDataInput.java Sat Jan 7 21:08:22 2012
@@ -86,11 +86,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;
}
@@ -99,11 +99,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;
}
@@ -113,7 +113,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++];
}
@@ -126,7 +126,6 @@ public final class ByteArrayDataInput ex
}
private boolean checkBounds() {
- assert pos < limit;
- return true;
+ return pos < limit;
}
}
Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/DataInput.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/DataInput.java?rev=1228729&r1=1228728&r2=1228729&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/DataInput.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/DataInput.java Sat Jan 7 21:08:22 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.
@@ -179,7 +181,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);
}
private String readModifiedUTF8String() throws IOException {
Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/MMapDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/MMapDirectory.java?rev=1228729&r1=1228728&r2=1228729&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/MMapDirectory.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/MMapDirectory.java Sat Jan 7 21:08:22 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;
@@ -281,7 +282,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);
@@ -304,7 +305,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);
@@ -372,12 +373,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/branches/branch_3x/lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java?rev=1228729&r1=1228728&r2=1228729&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/NIOFSDirectory.java Sat Jan 7 21:08:22 2012
@@ -161,7 +161,7 @@ public class NIOFSDirectory extends FSDi
bb.limit(limit);
int i = channel.read(bb, pos);
if (i == -1) {
- throw new EOFException("read past EOF (resource: " + this + ")");
+ throw new EOFException("read past EOF: " + this);
}
pos += i;
readOffset += i;
Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/RAMInputStream.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/RAMInputStream.java?rev=1228729&r1=1228728&r2=1228729&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/RAMInputStream.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/RAMInputStream.java Sat Jan 7 21:08:22 2012
@@ -97,7 +97,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/branches/branch_3x/lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java?rev=1228729&r1=1228728&r2=1228729&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/store/SimpleFSDirectory.java Sat Jan 7 21:08:22 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;
@@ -121,7 +122,7 @@ public class SimpleFSDirectory extends F
}
final int i = file.read(b, offset + total, readLength);
if (i == -1) {
- throw new IOException("read past EOF");
+ throw new EOFException("read past EOF: " + this);
}
file.position += i;
total += i;
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/TestByteBlockPool.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/TestByteBlockPool.java?rev=1228729&r1=1228728&r2=1228729&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/TestByteBlockPool.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/TestByteBlockPool.java Sat Jan 7 21:08:22 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();